1.url_launcher安装
2.引用(就是Url不一样)
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
class OpenThree extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("第三方应用"),
),
body: Column(
children: <Widget>[
DecoratedBox(
decoration: BoxDecoration(color: Colors.blueAccent),
child: ListTile(
title: Text("打开浏览器"),
onTap: _lanchUrl,
leading: Icon(Icons.open_in_browser),
),
),
DecoratedBox(
decoration: BoxDecoration(color: Colors.deepPurple),
child: ListTile(
title: Text("打开App"),
onTap: _lanchApp,
leading: Icon(Icons.apps),
),
),
DecoratedBox(
decoration: BoxDecoration(color: Colors.lightGreen),
child: ListTile(
title: Text("打电话"),
onTap: _lanchTel,
leading: Icon(Icons.apps),
),
),
DecoratedBox(
decoration: BoxDecoration(color: Colors.redAccent),
child: ListTile(
title: Text("sms发消息"),
onTap: _lanchSms,
leading: Icon(Icons.apps),
),
),
DecoratedBox(
decoration: BoxDecoration(color: Colors.blueGrey),
child: ListTile(
title: Text("发邮件"),
onTap: _lanchEmail,
leading: Icon(Icons.apps),
),
)
],
),
);
}
//打开浏览器查看页面
_lanchUrl() async {
final url = "https://www.baidu.com";
if (await canLaunch(url)) {
await launch(url);
} else {
throw "不可以加载浏览器地址:$url";
}
}
//打开app
_lanchApp() async {
const url = "geo:31.2651321247,120.7324430486";
const iosUrl = "http://maps.apple.com/?ll=31.2651321247,120.7324430486";
if (await canLaunch(url)) {
await launch(url);
} else if (await canLaunch(iosUrl)) {
await launch(iosUrl);
}else{
throw "不可以打开App";
}
}
//打电话
_lanchTel() async {
final url = "tel:+1 555 010 999";
if (await canLaunch(url)) {
await launch(url);
} else {
throw "不可以打电话";
}
}
//发sms
_lanchSms() async {
final url = "sms:5550101234";
if (await canLaunch(url)) {
await launch(url);
} else {
throw "不可sms";
}
}
//发邮件
_lanchEmail() async {
final url = "mailto:smith@example.org?subject=News&body=New%20plugin";
if (await canLaunch(url)) {
await launch(url);
} else {
throw "不可发邮件";
}
}
}
浏览器:
APP:
打电话:
Sms消息:
发邮件: