url_launcher是用于在移动平台中启动URL的Flutter插件,适用于IOS和Android平台。他可以打开网页,发送邮件,还可以拨打电话。
github地址:https://github.com/flutter/plugins/tree/master/packages/url_launcher
引入依赖
在pubspec.yaml文件里注册依赖,并保存下载包。请注意使用最新版。
url_launcher: ^5.1.3在需要使用的页面在使用import引入具体的url_launcher包。
import 'package:url_launcher/url_launcher.dart';mailto:<email address>?subject=<subject>&body=<body>,
例如
mailto:smith@example.org?subject=News&body=New plugin
在默认电子邮件应用中创建电子邮件tel:<phone number>, 例如 tel:+1 555 010 999拨打电话以使用默认电话应用程序sms:<phone number>, 例如 sms:5550101234使用默认消息传递应用程序发送SMS消息代码示例:
String url = 'tel:12306' ; if(await canLaunch(url)){ await launch(url); }else{ throw 'url不能进行访问,异常。'; } //或者 String url = 'https://www.baidu.com'; if(await canLaunch(url)){ await launch(url); }else{ throw 'url不能进行访问,异常。'; }
转载于:https://www.cnblogs.com/joe235/p/11540321.html
相关资源:Flutter 插件url_launcher简介