flutter打开第三方应用
生活随笔
收集整理的這篇文章主要介紹了
flutter打开第三方应用
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
添加依賴(lài)
url_launcher: ^5.4.1
?
————————main.dart
import 'package:url_launcher/url_launcher.dart';void main() => runApp(MyApp());const String TITLE='whqtest';class MyApp extends StatelessWidget {@overrideWidget build(BuildContext context) {return MaterialApp(title: TITLE,theme: ThemeData(primarySwatch: Colors.blue,),home: MyHomePage(title: TITLE),);} }class MyHomePage extends StatefulWidget {MyHomePage({Key key, this.title}) : super(key: key);final String title;@override_MyHomePageState createState() => _MyHomePageState(); }class _MyHomePageState extends State<MyHomePage> {String _title = TITLE;void _pressed() async{// Androidprint("open weixin");const url = 'vnd.weixin://';if (await canLaunch(url)) {await launch(url);} else {// Iosconst url = 'weixin://';if(await canLaunch(url)){await launch(url);}else{throw 'Could not launch $url';}}}@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: Text(widget.title),),body: Center(child: Column(mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[RaisedButton(child: Text('微信'),color: Colors.blue,textColor: Colors.white,onPressed: _pressed,)]),),);} }?
總結(jié)
以上是生活随笔為你收集整理的flutter打开第三方应用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 第四章:条件语句(if)和循环结构(wh
- 下一篇: java中方法的参数传递机制