Inscription
- his sword End of the World, Start with your accumulated bit by bit, clinics of the Department, will be better, that is, tossing every day.
Important Message
- Point of view this may proficient said fine
- Flutter from entry to develop a practice of APP UI Basics video
- flutter series of articles from entry to the master
This article will describe:
the flutter cross-platform development, the use of plug-ins install_plugin_custom achieve invoking the Android platform is installed automatically updated in the appstore ios platform jump
The actual cross-platform application development flutter, the upgrading effect app follows
ios platform:
Android platform:
1 Introduction
In APP development program in general, we will get a version of APP by visiting our information service platform, such as the version number, the version name, whether to force updates, etc.
Here is a description of the Android platform download apk and then invoking the application is installed, click to update the ios platform jump appstore platform.
Here download apk using Dio, install apk using install_plugin_custom plug, flutter project dependencies
# 权限申请
permission_handler: 4.0.0
# 网络请求
dio: ^2.1.2
# APP升级安装组件 Android中调用自动安装 apk的程序 ios 调用打开APPStore
install_plugin_custom:
git:
url: https://github.com/zhaolongs/install_plugin_custom.git
ref: master
Update 2 flutter in the Android platform
2.1 SD card storage permission application
Future<bool> _checkPermission(BuildContext context) async {
if (Theme.of(context).platform == TargetPlatform.android) {
PermissionStatus permission = await PermissionHandler()
.checkPermissionStatus(PermissionGroup.storage);
if (permission != PermissionStatus.granted) {
Map<PermissionGroup, PermissionStatus> permissions =
await PermissionHandler()
.requestPermissions([PermissionGroup.storage]);
if (permissions[PermissionGroup.storage] == PermissionStatus.granted) {
return true;
}
} else {
return true;
}
} else {
return true;
}
return false;
}
2.2 SD card memory storage path acquisition
Future<String> _findLocalPath(BuildContext context) async {
final directory = Theme.of(context).platform == TargetPlatform.android
? await getExternalStorageDirectory()
: await getApplicationDocumentsDirectory();
return directory.path;
}
2.3 Dio download apk
//apk 网络存储链接
String apkNetUrl ="";
//手机中sd卡上 apk 下载存储路径
String localPath ="";
Dio dio = Dio();
//设置连接超时时间
dio.options.connectTimeout = 1200000;
//设置数据接收超时时间
dio.options.receiveTimeout = 1200000;
try {
Response response = await dio
.download(apkNetUrl, localPath
onReceiveProgress: (int count, int total) {
// count 当前已下载文件大小
// total 需要下载文件的总大小
});
if (response.statusCode == 200) {
print('下载请求成功');
//"安装";
} else {
//"下载失败重试";
}
} catch (e) {
//"下载失败重试";
if (mounted) {
setState(() {});
}
}
2.4 install_plugin_custom mounted apk
//apk 的包名
String apkPackageName ="";
// 安装
InstallPluginCustom.installApk(
localPath,
apkPackageName)
.then((result) {
print('install apk $result');
}).catchError((error) {
// "重试";
installStatues = 2;
setState(() {});
});
Update 3 flutter in ios platform
If flutter project is running ios phone, so there is time to update the information directly jump page in the application appstore update
if (Theme.of(context).platform == TargetPlatform.iOS) {
InstallPluginCustom.gotoAppStore(
"https://apps.apple.com/cn/app/id1472328992");
}
Here is a direct replacement in the use of links to jump just fine.