From 9676d13777c2db074e7f812554eeffaa98458907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=90=8C?= <494089941@qq.com> Date: Tue, 7 Jun 2022 15:09:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20r=5Fupgrade=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .flutter-plugins | 8 +- .flutter-plugins-dependencies | 2 +- .fvm/flutter_sdk | 1 + .fvm/fvm_config.json | 4 + lib/aku_app_upgrade.dart | 178 ++++++++++++++++++---------------- pubspec.yaml | 2 +- 6 files changed, 102 insertions(+), 93 deletions(-) create mode 120000 .fvm/flutter_sdk create mode 100644 .fvm/fvm_config.json diff --git a/.flutter-plugins b/.flutter-plugins index a698799..52f8b69 100644 --- a/.flutter-plugins +++ b/.flutter-plugins @@ -4,10 +4,4 @@ package_info_plus_linux=/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/pack package_info_plus_macos=/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus_macos-1.3.0/ package_info_plus_web=/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus_web-1.0.5/ package_info_plus_windows=/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus_windows-1.0.5/ -url_launcher=/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.1.2/ -url_launcher_android=/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/url_launcher_android-6.0.17/ -url_launcher_ios=/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/url_launcher_ios-6.0.17/ -url_launcher_linux=/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-3.0.1/ -url_launcher_macos=/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-3.0.1/ -url_launcher_web=/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-2.0.11/ -url_launcher_windows=/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/url_launcher_windows-3.0.1/ +r_upgrade=/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/r_upgrade-0.3.8+2/ diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 55576a3..de10931 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"package_info_plus","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.4.2/","native_build":true,"dependencies":[]},{"name":"url_launcher_ios","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/url_launcher_ios-6.0.17/","native_build":true,"dependencies":[]}],"android":[{"name":"package_info_plus","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.4.2/","native_build":true,"dependencies":[]},{"name":"url_launcher_android","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/url_launcher_android-6.0.17/","native_build":true,"dependencies":[]}],"macos":[{"name":"package_info_plus_macos","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus_macos-1.3.0/","native_build":true,"dependencies":[]},{"name":"url_launcher_macos","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-3.0.1/","native_build":true,"dependencies":[]}],"linux":[{"name":"package_info_plus_linux","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus_linux-1.0.5/","native_build":false,"dependencies":[]},{"name":"url_launcher_linux","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-3.0.1/","native_build":true,"dependencies":[]}],"windows":[{"name":"package_info_plus_windows","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus_windows-1.0.5/","native_build":false,"dependencies":[]},{"name":"url_launcher_windows","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/url_launcher_windows-3.0.1/","native_build":true,"dependencies":[]}],"web":[{"name":"package_info_plus_web","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus_web-1.0.5/","dependencies":[]},{"name":"url_launcher_web","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-2.0.11/","dependencies":[]}]},"dependencyGraph":[{"name":"package_info_plus","dependencies":["package_info_plus_linux","package_info_plus_macos","package_info_plus_windows","package_info_plus_web"]},{"name":"package_info_plus_linux","dependencies":[]},{"name":"package_info_plus_macos","dependencies":[]},{"name":"package_info_plus_web","dependencies":[]},{"name":"package_info_plus_windows","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_android","url_launcher_ios","url_launcher_linux","url_launcher_macos","url_launcher_web","url_launcher_windows"]},{"name":"url_launcher_android","dependencies":[]},{"name":"url_launcher_ios","dependencies":[]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2022-06-02 10:29:21.647080","version":"3.0.0"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"package_info_plus","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.4.2/","native_build":true,"dependencies":[]},{"name":"r_upgrade","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/r_upgrade-0.3.8+2/","native_build":true,"dependencies":[]}],"android":[{"name":"package_info_plus","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus-1.4.2/","native_build":true,"dependencies":[]},{"name":"r_upgrade","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/r_upgrade-0.3.8+2/","native_build":true,"dependencies":[]}],"macos":[{"name":"package_info_plus_macos","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus_macos-1.3.0/","native_build":true,"dependencies":[]}],"linux":[{"name":"package_info_plus_linux","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus_linux-1.0.5/","native_build":false,"dependencies":[]}],"windows":[{"name":"package_info_plus_windows","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus_windows-1.0.5/","native_build":false,"dependencies":[]}],"web":[{"name":"package_info_plus_web","path":"/Users/zhangmeng/.pub-cache/hosted/pub.dartlang.org/package_info_plus_web-1.0.5/","dependencies":[]}]},"dependencyGraph":[{"name":"package_info_plus","dependencies":["package_info_plus_linux","package_info_plus_macos","package_info_plus_windows","package_info_plus_web"]},{"name":"package_info_plus_linux","dependencies":[]},{"name":"package_info_plus_macos","dependencies":[]},{"name":"package_info_plus_web","dependencies":[]},{"name":"package_info_plus_windows","dependencies":[]},{"name":"r_upgrade","dependencies":[]}],"date_created":"2022-06-07 14:38:49.619690","version":"3.0.0"} \ No newline at end of file diff --git a/.fvm/flutter_sdk b/.fvm/flutter_sdk new file mode 120000 index 0000000..e323414 --- /dev/null +++ b/.fvm/flutter_sdk @@ -0,0 +1 @@ +/Users/zhangmeng/fvm/versions/3.0.0 \ No newline at end of file diff --git a/.fvm/fvm_config.json b/.fvm/fvm_config.json new file mode 100644 index 0000000..d4e14b2 --- /dev/null +++ b/.fvm/fvm_config.json @@ -0,0 +1,4 @@ +{ + "flutterSdkVersion": "3.0.0", + "flavors": {} +} \ No newline at end of file diff --git a/lib/aku_app_upgrade.dart b/lib/aku_app_upgrade.dart index 47ed7cb..2ade719 100644 --- a/lib/aku_app_upgrade.dart +++ b/lib/aku_app_upgrade.dart @@ -6,8 +6,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:dio/dio.dart'; -import 'package:url_launcher/url_launcher.dart'; -import 'package:url_launcher/url_launcher_string.dart'; +import 'package:r_upgrade/r_upgrade.dart'; enum ForceUpgrade { force(1), @@ -77,100 +76,111 @@ class AppUpgrade { upgradeDialog(BuildContext context, PackageInfo packageInfo, Function()? onLaunchFail, AkuAppVersion akuAppVersion) { return Center( - child: Material( - borderRadius: BorderRadius.circular(16), - child: Container( - width: 300, - height: 200, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(16), - // gradient: LinearGradient(colors: [ - // Colors.yellow.withOpacity(0.05), - // Colors.white, - // ], begin: Alignment.topCenter, end: Alignment.bottomCenter), - color: Colors.white, - boxShadow: const [ - BoxShadow( - color: Colors.blue, - blurRadius: 5, - spreadRadius: 0, - ) - ]), - child: Column( - children: [ - const Padding( - padding: EdgeInsets.all(32), - child: Text( - '当前不是最新版本\n请升级最新版', - textAlign: TextAlign.center, - style: TextStyle( - color: Colors.black, - fontSize: 24, - fontWeight: FontWeight.bold), + child: Container( + width: 300, + height: 200, + clipBehavior: Clip.antiAliasWithSaveLayer, + decoration: BoxDecoration( + color: Colors.white, + boxShadow: const [ + BoxShadow( + color: Colors.blue, + blurRadius: 5, + spreadRadius: 0, + ) + ], + borderRadius: BorderRadius.circular(24), + ), + child: Material( + child: Container( + decoration: const BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + stops: [0,0.7], + colors: [ + Color(0x33FBE541), + Colors.white, + ])), + child: Column( + children: [ + const Padding( + padding: EdgeInsets.all(32), + child: Text( + '当前不是最新版本\n请升级最新版', + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.black, + fontSize: 22, + fontWeight: FontWeight.bold), + ), + ), + const Spacer(), + Container( + height: 1, + width: double.infinity, + color: Colors.black.withOpacity(0.45), ), - ), - const Spacer(), - Container( - height: 1, - width: double.infinity, - color: Colors.black.withOpacity(0.45), - ), - SizedBox( - height: 50, - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - if (akuAppVersion.forceEM != ForceUpgrade.force) + SizedBox( + height: 50, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + if (akuAppVersion.forceEM != ForceUpgrade.force) + Expanded( + child: MaterialButton( + onPressed: () { + Navigator.pop(context); + }, + child: const Text( + '取消', + style: TextStyle( + color: Colors.black, + fontSize: 20, + fontWeight: FontWeight.normal), + ), + ), + ), + Offstage( + offstage: akuAppVersion.forceEM == ForceUpgrade.force, + child: Container( + height: double.infinity, + width: 1, + color: Colors.black.withOpacity(0.45), + ), + ), Expanded( - child: TextButton( - onPressed: () { + child: MaterialButton( + onPressed: () async { Navigator.pop(context); + if (Platform.isAndroid) { + var stores = await RUpgrade.androidStores; + if (stores == null || stores.isEmpty) { + onLaunchFail?.call(); + return; + } + await RUpgrade.upgradeFromAndroidStore( + stores.first); + } else if (Platform.isIOS) { + await RUpgrade.upgradeFromAppStore( + packageInfo.packageName); + } else {} }, child: const Text( - '取消', + '去升级', style: TextStyle( color: Colors.black, fontSize: 20, fontWeight: FontWeight.normal), ), ), - ), - Offstage( - offstage: akuAppVersion.forceEM == ForceUpgrade.force, - child: Container( - height: double.infinity, - width: 1, - color: Colors.black.withOpacity(0.45), - ), - ), - Expanded( - child: TextButton( - onPressed: () async { - if (Platform.isAndroid) { - var re = await launchUrlString( - 'mimarket://detail?id=${packageInfo.packageName}'); - if (!re && onLaunchFail != null) { - onLaunchFail.call(); - } - } else if (Platform.isIOS) { - launchUrlString( - 'itms-apps://itunes.apple.com/app/${packageInfo.packageName}'); - } else {} - }, - child: const Text( - '去升级', - style: TextStyle( - color: Colors.black, - fontSize: 20, - fontWeight: FontWeight.normal), - ), - ), - ) - ], + ) + ], + ), ), - ), - ], + ], + ), ), ), ), diff --git a/pubspec.yaml b/pubspec.yaml index 26445f9..80fe588 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,8 +11,8 @@ dependencies: flutter: sdk: flutter package_info_plus: ^1.4.2 - url_launcher: ^6.1.2 dio: ^4.0.6 + r_upgrade: ^0.3.8+2 dev_dependencies: flutter_test: