flutterflutter-layoutflutter-dependencies

Open app when button is clicked I want to open the Gmail app when I click the button. I am using the url launcher


I want to open the Gmail app when I click the button. I am using the url launcher.

         `InkWell(
          child: Row(mainAxisSize: MainAxisSize.min, children: const [
            SizedBox(
              width: 30.0,
              height: 60.0,
            ),
            Text(' "/Open Email/" ',
                style: TextStyle(
                  color: Colors.black,
                )),
          ]),
          onTap: () {
            const url = 'https://mail.google.com/mail/u/0/#inbox';
            launchURL(url);
          }),`

When I click this its open the web instead of the app


Solution

  • Using Andriod_intent_plus for Android and url_launcher for iOS you can achieve this.

    if (Platform.isAndroid) {
       final AndroidIntent intent = AndroidIntent(
               action: 'android.intent.action.MAIN',
               category: 'android.intent.category.APP_EMAIL',
      );
      
      intent.launch().catchError((e) {});
    } else if (Platform.isIOS) {
      launch('message://').catchError((e) {});
    }