From a924d27e9c0dc462dcff672825ec4a0241a2dc9e Mon Sep 17 00:00:00 2001 From: laiiihz Date: Mon, 22 Feb 2021 11:16:40 +0800 Subject: [PATCH] =?UTF-8?q?add=20device=20info=20support,=E5=AE=89?= =?UTF-8?q?=E5=8D=93=E7=9A=84=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E7=94=B1=E8=B7=B3=E8=BD=AC=E5=BA=94=E7=94=A8=E5=AE=9D?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E7=9B=B4=E6=8E=A5=E4=B8=8B=E8=BD=BD=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/utils/versionInfo/version_tool.dart | 49 ++++++++++++++++--------- pubspec.lock | 14 +++++++ pubspec.yaml | 4 +- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/lib/utils/versionInfo/version_tool.dart b/lib/utils/versionInfo/version_tool.dart index ea9505a..a8f4ebb 100644 --- a/lib/utils/versionInfo/version_tool.dart +++ b/lib/utils/versionInfo/version_tool.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:device_info/device_info.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:package_info/package_info.dart'; @@ -22,37 +23,51 @@ class VersionTool { _showUpDateAlert(context, model); } - static _showUpDateAlert(context,VersionInfoModel model) async { + static _showUpDateAlert(context, VersionInfoModel model) async { VersionInfo versionInfo = model.data.versionInfo; // VersionInfo versionInfo = getStore().state.userBrief.versionInfo; PackageInfo packageInfo = await PackageInfo.fromPlatform(); - if (versionInfo==null) { + String _appStoreURL = ''; + + if (versionInfo == null) { return; } + if (Platform.isAndroid) _appStoreURL = await _getAndroidURL(); + if (Platform.isIOS) _appStoreURL = WebApi.iOSUrl; //当前版本小于服务器版本 if (int.parse(packageInfo.buildNumber) < versionInfo.build) { Alert.show( - context, - NormalTextDialog( - title: "发现新版本", - content: "${versionInfo.desc}", - items: ["确认","取消"], - listener: (int index) async { - Alert.dismiss(context); + context, + NormalTextDialog( + title: "发现新版本", + content: "${versionInfo.desc}", + items: ["确认", "取消"], + listener: (int index) async { + Alert.dismiss(context); if (index == 0) { - String _url = WebApi.androidUrl; - if (Platform.isIOS) _url = WebApi.iOSUrl; - if (await canLaunch(_url)){ - launch(_url); + if (await canLaunch(_appStoreURL)) { + launch(_appStoreURL); if (Theme.of(context).platform == TargetPlatform.iOS) { - Future.delayed(const Duration(seconds: 3), () => closeWebView()); + Future.delayed( + const Duration(seconds: 3), () => closeWebView()); } } } }, - ) - ); + )); } } -} \ No newline at end of file + static Future _getAndroidURL() async { + DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); + AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; + String brand = androidInfo.brand.toLowerCase(); + print(brand); + bool safeMarket = ['xiaomi', 'oneplus', 'oppo', 'vivo', 'huawei'] + .any((element) => brand.contains(element)); + if (safeMarket) + return 'market://details?id=com.akuhome.recook'; + else + return WebApi.androidUrl; + } +} diff --git a/pubspec.lock b/pubspec.lock index 1230146..66f9dd2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -246,6 +246,20 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.3.5" + device_info: + dependency: "direct main" + description: + name: device_info + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.0" + device_info_platform_interface: + dependency: transitive + description: + name: device_info_platform_interface + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" dio: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index dfc9a1e..4bcce29 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: recook description: Recook Market App. publish_to: "none" -version: 1.4.5-dev+245 +version: 1.4.5-dev+100 environment: sdk: ">=2.10.0 <3.0.0" @@ -220,6 +220,8 @@ dependencies: pin_input_text_field: ^3.3.0 + device_info: ^1.0.0 + dev_dependencies: flutter_test: sdk: flutter