调用 url_launcher 模块打开外部浏 览器 打开外部应用 拨打电话 发送短信
2021-04-14 16:28
标签:app widget bsp end ons title http list listview 调用 url_launcher 模块打开外部浏 览器 打开外部应用 拨打电话 发送短信 标签:app widget bsp end ons title http list listview 原文地址:https://www.cnblogs.com/zhaofeis/p/12375130.htmlimport ‘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
@override
Widget 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://‘;
if (await canLaunch(url)) {
await launch(url);
} else {
throw ‘Could not launch $url‘;
}
},
)
]),
)));
}
}
下一篇:前端之gojs插件的基本使用
文章标题:调用 url_launcher 模块打开外部浏 览器 打开外部应用 拨打电话 发送短信
文章链接:http://soscw.com/essay/75734.html