Giter Club home page Giter Club logo

Comments (5)

MisterJimson avatar MisterJimson commented on August 19, 2024

Hello! Does the example app work for you? Your code looks different compared to the example app. I'm not able to reproduce the issue in the example app.

I'm not familiar with Navigator.of(context).restorablePush or DialogRoute. From the error message it seems the problem may be with the usage of those.

from open-mail-app-flutter.

fennelhans avatar fennelhans commented on August 19, 2024

I'll give it another pass, but I was basing this code off what is now present in the Flutter API docs.

from open-mail-app-flutter.

fennelhans avatar fennelhans commented on August 19, 2024

image

from open-mail-app-flutter.

fennelhans avatar fennelhans commented on August 19, 2024

Ok, I've got it working (at least on Android... I don't have a Mac to test it on iOS.) I've tested with no mail app, one mail app, and two mail apps - all three cases seem to work.

  Future<void> _openMailApp(BuildContext context) async {
    // Android: Will open mail app or show native picker.
    // iOS: Will open mail app if single mail app found.
    final result = await OpenMailApp.openMailApp();
    Route<Object?> _dialogBuilder(BuildContext context, Object? arguments) {
      return DialogRoute<void>(
        context: context,
        builder: (BuildContext context) => MailAppPickerDialog(
          mailApps: result.options,
        ),
      );
    }

    // If no mail apps found, show error
    if (!result.didOpen && !result.canOpen) {
      Navigator.of(context).restorablePush(_showNoMailAppsDialog);

      // iOS: if multiple mail apps found, show dialog to select.
      // There is no native intent/default app system in iOS so
      // you have to do it yourself.
    } else if (!result.didOpen && result.canOpen) {
      Navigator.of(context).restorablePush(_dialogBuilder);
    }
  }

  static Route<Object?> _showNoMailAppsDialog(
      BuildContext context, Object? arguments) {
    return DialogRoute<void>(
      context: context,
      builder: (context) {
        return AlertDialog(
          title: Text("Open Mail App"),
          content: Text("No mail apps installed"),
          actions: <Widget>[
            PrimaryButton(
              title: "OK",
              onPressed: () {
                Navigator.pop(context);
              },
            )
          ],
        );
      },
    );
  }

Invoking it looks like this:

Button(
  onPressed: () => {_openMailApp(context)},
),

from open-mail-app-flutter.

fennelhans avatar fennelhans commented on August 19, 2024

I also managed to figure out how do to fix the example provided, without using my example. Notice the type next to the function, as well as the updated button.

  void showNoMailAppsDialog(BuildContext context) {
    showDialog<Dialog>(
      context: context,
      builder: (context) {
        return AlertDialog(
          title: Text("Open Mail App"),
          content: Text("No mail apps installed"),
          actions: <Widget>[
            TextButton(
              child: Text("OK"),
              onPressed: () {
                Navigator.pop(context);
              },
            )
          ],
        );
      },
    );
  }

from open-mail-app-flutter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.