代码拉取完成,页面将自动刷新
A new Flutter plugin.
flutter与原生交互,包含静态资源获取,版本获取。
###集成方式
aj_flutter_plugin:
git:
url: https://github.com/anji-plus/flutter_plugin.git
path: aj_flutter_plugin
注意:插件url 如果GitHub下载慢的话 可以换成gitee的url
aj_flutter_plugin:
git:
url: https://gitee.com/anji-plus/aj_flutter_plugins.git
path: aj_flutter_plugin
###使用方式
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
int firstBackPressTime = 0;
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
AjFlutterPlugin info;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
info = await AjFlutterPlugin.platformVersion();
platformVersion = "appName:${info.appName}\n" +
"packageName: ${info.packageName}\n" +
"version:${info.version}\n" +
"buildNumber:${info.buildNumber}";
print(platformVersion);
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: WillPopScope(
child: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: ListView(
children: <Widget>[
Text('$_platformVersion\n'),
FlatButton(
color: Colors.black12,
onPressed: () async {
if (Platform.isAndroid) {
if (await canLaunch("https://www.pgyer.com/Ti9R")) {
await launch("https://www.pgyer.com/Ti9R");
}
} else if (Platform.isIOS) {
await launch("http://itunes.apple.com/cn/app/id1441492772");
}
},
child: Text("跳转外部链接"),
),
FlatButton(
color: Colors.black12,
onPressed: () async {
await launchCallPhone('10086');
},
child: Text("打电话 100000"),
),
FlatButton(
color: Colors.black12,
onPressed: () async {
await launchEmail('100000');
},
child: Text("发邮件 100000"),
),
FlatButton(
color: Colors.black12,
onPressed: () async {
await launchMessage('188188888888');
},
child: Text("发信息 10086"),
),
FlatButton(
color: Colors.black12,
onPressed: () async {
_exitApp();
},
child: Text("退出app"),
),
FlatButton(
color: Colors.black12,
onPressed: () async {
print(await isiOSSimuLator());
},
child: Text("是否是模拟器"),
),
FlatButton(
color: Colors.black12,
onPressed: () async {
int permissState = await AjFlutterPlugin.getLocationPermissions();
_platformVersion = "$permissState";
setState(() {
});
},
child: Text("获取权限"),
),
//getLocationPermissions
],
)),
),
onWillPop: () {
_exitApp();
},
),);
}
_exitApp() {
//Android 回到桌面
int secondTime = new DateTime.now().millisecondsSinceEpoch;
if (secondTime - firstBackPressTime > 2000) {
// 如果两次按键时间间隔大于2秒,则不退出
firstBackPressTime = secondTime; // 更新firstTime
print("再按一次退出程序");
} else {
//退出到桌面
exitApp();
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。