How to open an application from a Flutter app?

后端 未结 5 2000
不思量自难忘°
不思量自难忘° 2020-11-30 03:29

I am developing a Flutter app, in which I need to show navigation to the user for a place. So, how can I open a map application from my Flutter app like we do using external

5条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 04:09

    You can just use the url_launcher plugin to open maps. It launches map if installed or falls back to open the map on a browser.

    Example:

    import 'package:flutter/material.dart';
    import 'package:url_launcher/url_launcher.dart';
    
    void main() {
      runApp(new Scaffold(
        body: new Center(
          child: new RaisedButton(
            onPressed: _launchURL,
            child: new Text('Launch Maps'),
          ),
        ),
      ));
    }
    
    _launchMaps() async {
      const url = "https://www.google.com/maps/search/?api=1&query=LATITUDE,LONGITUDE,17&query_place_id=PLACE_ID";
      if (await canLaunch(url)) {
        await launch(url);
      } else {
        throw 'Could not launch Maps';
      }
    }
    

    Hope that helps!

提交回复
热议问题