Code Monkey home page Code Monkey logo

open-mail-app-flutter's Introduction

Open Mail App Flutter Flutter 2.10.0

pub package

A boring but accurate name.

This library provides the ability to query the device for installed email apps and open those apps.

If you just want to compose an email or open any app with a mailto: link, you are looking for url_launcher.

Why

While url_launcher can help you compose an email or open the default email app, it doesn't give you control over which is opened and it doesn't tell you what is available on the device. This is especially a problem on iOS where only the default Mail app will be opened, even if the user prefers a different app.

Setup

iOS requires you to list the URL schemes you would like to query in the Info.plist file.

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>googlegmail</string>
    <string>x-dispatch</string>
    <string>readdle-spark</string>
    <string>airmail</string>
    <string>ms-outlook</string>
    <string>ymail</string>
    <string>fastmail</string>
    <string>superhuman</string>
    <string>protonmail</string>
</array>

Please file issues to add popular email apps you would like to see on iOS. They need to be added to both your app's Info.plist and in the source of this library.

Usage

Open Mail App With Picker If Multiple

import 'package:open_mail_app/open_mail_app.dart';

void main() {
  runApp(MaterialApp(home: MyApp()));
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return RaisedButton(
      child: Text("Open Mail App"),
      onPressed: () async {
        // Android: Will open mail app or show native picker.
        // iOS: Will open mail app if single mail app found.
        var result = await OpenMailApp.openMailApp();

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

          // 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) {
          showDialog(
            context: context,
            builder: (_) {
              return MailAppPickerDialog(
                mailApps: result.options,
              );
            },
          );
        }
      },
    );
  }

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

open-mail-app-flutter's People

Contributors

emcao avatar kristijanmitrik avatar andrzejchm avatar losdanieloss avatar diskwriter avatar jmacpherson avatar marcinusx avatar nikhiln avatar princegoyal avatar nerder avatar victorien-a avatar almnorth avatar vbuberen avatar deathcoder avatar

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.