connectivity_plus 检测网络
地址: https://pub.dev/packages/connectivity_plus
dependencies:
connectivity_plus: ^2.3.6+1
import 'package:flutter/material.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
class NetworkPage extends StatefulWidget {
const NetworkPage({super.key});
@override
State<NetworkPage> createState() => _NetworkPageState();
}
class _NetworkPageState extends State<NetworkPage> {
dynamic subscription;
String _stateText = "检测中...";
@override
void initState() {
super.initState();
subscription = Connectivity()
.onConnectivityChanged
.listen((ConnectivityResult result) {
if (result == ConnectivityResult.wifi) {
setState(() {
_stateText = "处于 wifi";
});
} else if (result == ConnectivityResult.mobile) {
setState(() {
_stateText = "处于手机网络";
});
} else {
setState(() {
_stateText = "没有网络";
});
}
});
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
subscription.cancel();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('检测网络'),
),
body: Center(
child: Text(_stateText),
),
);
}
}
url_launcher 配置打开URL、拨打电话 、发送短信 、打开外部应用、打开高德地图
地址:https://pub.dev/packages/url_launcher
Android配置
修改:android\app\src\main\AndroidManifest.xml
<!-- Provide required visibility configuration for API level 30 and above -->
<queries>
<!-- If your app checks for SMS support -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="sms" />
</intent>
<!-- If your app checks for call support -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="tel" />
</intent>
</queries>
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
Ios配置
配置拨打电话、发送邮件、打开外部应用、高德地图导航Info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>iosamap</string>
<string>baidumap</string>
<string>sms</string>
<string>tel</string>
<string>weixin</string>
<string>alipays</string>
</array>
高德官网导航地址:
https://lbs.amap.com/api/amap-mobile/guide/android/navigation
坐标吸取器
https://lbs.amap.com/tools/picker
完整代码
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
class UrlLauncherPage extends StatefulWidget {
const UrlLauncherPage({super.key});
@override
State<UrlLauncherPage> createState() => _UrlLauncherPageState();
}
class _UrlLauncherPageState extends State<UrlLauncherPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('UrlLauncherPage'),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(20),
child: ListView(children: [
ElevatedButton(
child: const Text('打开外部浏览器'),
onPressed: () async {
final Uri url = Uri.parse('https://www.itying.com');
if (await canLaunchUrl(url)) {
await launchUrl(url);
} else {
throw 'Could not launch $url';
}
},
),
const SizedBox(height: 10),
ElevatedButton(
child: const Text('拨打电话'),
onPressed: () async {
final Uri tel = Uri.parse('tel:10086');
if (await canLaunchUrl(tel)) {
await launchUrl(tel);
} else {
throw 'Could not launch $tel';
}
},
),
const SizedBox(height: 10),
ElevatedButton(
child: const Text('发送短信'),
onPressed: () async {
final Uri tel = Uri.parse('sms:10086');
// var tel = 'sms:10086';
if (await canLaunchUrl(tel)) {
await launchUrl(tel);
} else {
throw 'Could not launch $tel';
}
},
),
const SizedBox(height: 10),
ElevatedButton(
child: const Text('打开外部应用-支付宝'),
onPressed: () async {
/*
weixin://
alipays://
*/
final Uri alipays = Uri.parse('alipays://');
if (await canLaunchUrl(alipays)) {
await launchUrl(alipays);
} else {
throw 'Could not launch $alipays';
}
},
),
const SizedBox(height: 10),
ElevatedButton(
child: const Text('打开外部应用-微信'),
onPressed: () async {
/*
weixin://
alipays://
*/
final Uri weixin = Uri.parse('weixin://');
if (await canLaunchUrl(weixin)) {
await launchUrl(weixin);
} else {
throw 'Could not launch $weixin';
}
},
//
),
const SizedBox(height: 10),
ElevatedButton(
child: const Text('打开外部应用-高德地图'),
onPressed: () async {
String title = "北京大学";
String latitude = "39.992806";
String longitude = "116.310905";
Uri uri = Uri.parse(
'${Platform.isAndroid ? 'android' : 'ios'}amap://navi?
sourceApplication=amap&lat=$latitude&lon=$longitude&dev=0&style=2&poiname=${titl
e}');
// if (Platform.isIOS) url = Uri.encodeFull(url);
// if (Platform.isIOS) url = Uri.encodeFull(url);
// url=Uri.parse(url);
try {
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
print('无法调起高德地图');
}
} catch (e) {
print('无法调起高德地图');
}
}),
]),
)));
}
}
App Store中 常见App的scheme
电商
taobao : 淘宝
tmall : 天猫
jdlogin : 京东
pinduoduo : 拼多多
kaola : 网易考拉
yanxuan : 网易严选
vipshop : 唯品会
suning : 苏宁
mishopv1 : 小米商城
wireless1688 : 阿里巴巴
社交、社区-->
weibo : 微博
zhihu : 知乎
xhsdiscover : 小红书
momochat : 陌陌
blued : blued
mqzone : QQ空间
mqq : QQ
tantanapp : 探探
huputiyu : 虎扑
com.baidu.tieba : 贴吧
tianya : 天涯社区
douban : 豆瓣
jike : 即刻
短视频
snssdk1128 : 抖音
snssdk1112 : 火山
snssdk32 : 西瓜视频
gifshow : 快手
视频/直播
tenvideo : 腾讯视频
youku : 优酷
bilibili : B站
imgotv : 芒果TV
qiyi-iphone : 爱奇艺
hanju : 韩剧TV
douyutv : 斗鱼
yykiwi : 虎牙
图片处理
mtxx.open : 美图秀秀
faceu : faceu国内
ulike : 轻颜国内
资讯
snssdk141 : 今日头条
newsapp : 网易新闻
qqnews : 腾讯新闻
iting : 喜马拉雅
weread : 微信读书
jianshu : 简书
igetApp : 得到
kuaikan : 快看漫画
财经
sinanews : 新浪财经
amihexin : 同花顺炒股
音乐
orpheus : 网易云音乐
qqmusic : qq音乐
kugouURL : 酷狗
qmkege : 全民K歌
changba : 唱吧
工具
iosamap : 高德地图
baidumap : 百度地图
baiduyun : 百度网盘
rm434209233MojiWeather : 墨迹天气
办公
wxwork : 企业微信
dingtalk : 钉钉
生活
imeituan : 美团
dianping : 点评
cainiao : 菜鸟裹裹
wbmain : 58同城
mihome : 米家
美食佳饮
xcfapp : 下厨房
sbuxcn : 星巴克中国
meituanwaimai : 美团外卖
运动健康
fb370547106731052 : 小米运动
meetyou.linggan : 美柚
babytree : 宝宝树
keep : keep
旅行
CtripWireless : 携程
diditaxi : 滴滴
taobaotravel : 飞猪
travelguide : 马蜂窝
游戏
tencent1104466820 : 王者荣耀
tencent100689805 : 天天爱消除
tencent382 : QQ斗地主