添加依赖
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,)]),),);}
}