1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| e.g.
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
class LaunchPage extends StatefulWidget { _LaunchPageState createState() => _LaunchPageState(); }
class _LaunchPageState extends State<LaunchPage> { @override Widget build(BuildContext context) { return MaterialApp( title: '如何打开第三方应用', theme: ThemeData(primarySwatch: Colors.blue), home: Scaffold( appBar: AppBar( title: Text('如何打开第三方应用'), leading: GestureDetector( onTap: () { Navigator.pop(context); }, child: Icon(Icons.arrow_back), ), ), body: Column( children: <Widget>[ RaisedButton( onPressed: () => _launchURL(), child: Text('点击打开浏览器'), ), RaisedButton( onPressed: () => _openMap(), child: Text('点击打开地图'), ) ], ), ), ); }
_launchURL() async { const url = 'https://flutter.dev'; if (await canLaunch(url)) { await launch(url); } else { throw 'Could not launch $url'; } }
|