How to open default email app inbox in flutter?

后端 未结 1 1741
谎友^
谎友^ 2020-12-18 07:28

I want to open the default e-mail app Inbox screen using flutter. We can use url launcher to open the email compose screen with mailto: url. But that opens the compose scree

相关标签:
1条回答
  • 2020-12-18 08:03

    I found the answer using flutter_appavailability library. For those who are searching for the answer please see the steps below.

    1. Add dependency | flutter_appavailability: "^0.0.21" | in pubspec.yaml (Please check the latest version in GitHub)

    2. Add below lines in Xcode Podfile which is required for building the library in iOS

      target 'Runner' do use_frameworks! # required by simple_permission ... end

      post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '4.0' # required by simple_permission config.build_settings['ENABLE_BITCODE'] = 'NO' end end end

    3. Import below packages

      import 'dart:io'; import 'package:flutter_appavailability/flutter_appavailability.dart';

    4. Use below method

      void openEmailApp(BuildContext context){
          try{
              AppAvailability.launchApp(Platform.isIOS ? "message://" : "com.google.android.gm").then((_) {
                      print("App Email launched!");
                    }).catchError((err) {
                      Scaffold.of(context).showSnackBar(SnackBar(
                          content: Text("App Email not found!")
                      ));
                      print(err);
                    });
          } catch(e) {
            Scaffold.of(context).showSnackBar(SnackBar(content: Text("Email App not found!")));
          }
      }
      
    0 讨论(0)
提交回复
热议问题