Flutter 的url_launcher简介
2024-09-03 20:07:31
url_launcher是用于在移动平台中启动URL的Flutter插件,适用于IOS和Android平台。他可以打开网页,发送邮件,还可以拨打电话。
github地址:https://github.com/flutter/plugins/tree/master/packages/url_launcher
引入依赖
在pubspec.yaml
文件里注册依赖,并保存下载包。请注意使用最新版。
url_launcher: ^5.1.
在需要使用的页面在使用import引入具体的url_launcher
包。
import 'package:url_launcher/url_launcher.dart';
支持的URL方案
方案 | Action |
---|---|
http:<URL> ,https:<URL> 例如 http://flutter.dev |
在默认浏览器中打开URL |
例如
|
在默认电子邮件应用中创建电子邮件 |
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不能进行访问,异常。';
}
最新文章
- es6 ajax
- C++ 之引用
- XE6移动开发环境搭建之IOS篇(4):VMware9里安装Mac OSX 10.8(有图有真相)
- SWFUpload使用指南
- iOS开源 框架
- Traits技法
- 出错:Failed to convert property value of type &#39;org.apache.ibatis.session.defaults.DefaultSqlSessionFactory&#39; to required type &#39;java.lang.String&#39; for property &#39;sqlSessionFactoryBeanName&#39;;
- c#串口测试
- CentOS7 安装中文输入法
- hdu6133 Army Formations 线段树合并
- 【随笔】借鉴 &; KPI式设计
- 存储空间消耗磁盘比较 int varchar date
- 浙江省赛 ZOJ4029
- hdu6444 Neko&#39;s Loop
- linux\mac 日常入门命令行使用——搜索文件\文件夹
- WPF开发的彩票程序(练手好例子)
- 手动抠下的wordpress登录页面样式
- 关于Unity的坐标系
- Spring整合Mybatis SQL语句的输出
- 6、perl创建模块(Exporter)及路径 引用 嵌套 查询模块