效果圖:
打開外部瀏覽器
發送短信
撥打電話
打開外部應用
導入第三方庫:url_launcher
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';class UrlLauncher extends StatefulWidget {UrlLauncher({Key key}) : super(key: key);_UrlLauncherState createState() => _UrlLauncherState();
}class _UrlLauncherState extends State<UrlLauncher> {@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: Text('UrlLauncher'),),body: Center(child: Padding(padding: EdgeInsets.all(20),child: ListView(children: [RaisedButton(child: Text('打開外部瀏覽器'),onPressed: () async{ const url = 'https://cflutter.com';if (await canLaunch(url)) {await launch(url);} else {throw 'Could not launch $url';}},),SizedBox(height: 10),RaisedButton(child: Text('撥打電話'),onPressed: () async{var tel = 'tel:10086';if (await canLaunch(tel)) {await launch(tel);} else {throw 'Could not launch $tel';}},),SizedBox(height: 10),RaisedButton(child: Text('發送短信'),onPressed: () async{var tel = 'sms:10086';if (await canLaunch(tel)) {await launch(tel);} else {throw 'Could not launch $tel';}},),SizedBox(height: 10),RaisedButton(child: Text('打開外部應用'),onPressed: () async{/*weixin://alipays://*/var url = 'alipays://'; //支付寶的 scheme碼if (await canLaunch(url)) {await launch(url);} else {throw 'Could not launch $url';}},) ]),)));}
}
打開其他APP的scheme碼:
https://www.cflutter.com/topic/5d0853733b57e317a4d0af01
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态