瀏覽器哪個好,Flutter進階第13篇: 打開外部瀏覽器、打開外部應用、撥打電話、發送短信

 2023-12-25 阅读 29 评论 0

摘要:效果圖: 打開外部瀏覽器 發送短信 撥打電話 打開外部應用 導入第三方庫:url_launcher import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart';class UrlLauncher extends StatefulWidget {UrlLauncher({Ke

效果圖:

在這里插入圖片描述

打開外部瀏覽器
在這里插入圖片描述
發送短信
在這里插入圖片描述
撥打電話
在這里插入圖片描述
打開外部應用
在這里插入圖片描述

導入第三方庫: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

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/194776.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息