How to Open Application From a Flutter Application ?

· 3 min read
How to Solve Pub Run build_runner build Failed In Flutter
How to Solve Pub Run build_runner build Failed In Flutter

While designing or developing a Mobile Application Sometimes users need to open another application from our Flutter Application. So in this article, we will go through How to Open Application From a Flutter Application?

How to Open Application From a Flutter Application ?

To open another application user can give try to url_launcher package. It is useful for all URL Schema open phones, SMS, or even maps, etc.

To open Google Maps either in Android and iOS

_openMap() async {
    const url = 'https://www.google.com/maps/search/?api=1&query=52.32,4.917';
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }

Users can also use url_launcher to send mail using the below code snippet.

_sendMail() async {
    // Android and iOS
    const uri = 'mailto:[email protected]?subject=Greetings&body=Hello%20World';
    if (await canLaunch(uri)) {
      await launch(uri);
    } else {
    throw 'Could not launch $uri';
    }
  }

  _callMe() async {
    // Android
    const uri = 'tel:+1 222 060 888';
    if (await canLaunch(uri)) {
      await launch(uri);
    } else {
      // iOS
      const uri = 'tel:001-22-060-888';
      if (await canLaunch(uri)) {
        await launch(uri);
      } else {
        throw 'Could not launch $uri';
      }
    }
  }

  _textMe() async {
    // Android
    const uri = 'sms:+39 349 060 888';
    if (await canLaunch(uri)) {
      await launch(uri);
    } else {
      // iOS
      const uri = 'sms:0039-222-060-888';
      if (await canLaunch(uri)) {
        await launch(uri);
      } else {
        throw 'Could not launch $uri';
      }
    }
  }

Even if URI schema should be standards (RFC) sometimes the authority and path parts of them could differ between frameworks (Android or iOS). Import package like a below:

import 'dart:io'

and then in code.

if (Platform.isAndroid) {

} else if (Platform.isIOS) {

}

For iOS users, no browser involved, directly to apps:

//waze 
canLaunch("waze://") 
launch("waze://?ll=${latitude},${longitude}&navigate=yes"); 
//gmaps 
canLaunch("comgooglemaps://") 
launch("comgooglemaps://?saddr=${latitude},${longitude}&directionsmode=driving")

User needs to add Info.plist like a below:

<key>LSApplicationQueriesSchemes</key>  
<array>         
  <string>comgooglemaps</string>        
  <string>waze</string>     
</array>

I think you are looking for a scenario where you want to open a device installed app from Flutter?

User can use apps like https://pub.dev/packages/device_apps

If so, you can use a package called device_apps.

Conclusion:

Thanks for Reading !!!

Hope you find this article useful. Drop us your suggestion/feedback for the same.

Still, need support for Flutter Development?

FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

FlutterAgency.com is one of the most popular online portal dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge on Flutter.

Leave a Reply