From a5d69f5a6e413dbd7b063544b4bfc294e38b816b Mon Sep 17 00:00:00 2001 From: datang Date: Mon, 30 May 2022 18:14:23 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=EF=BC=88?= =?UTF-8?q?=E9=83=A8=E5=88=86=EF=BC=89=EF=BC=8C=E7=A4=BE=E5=8C=BA=E6=A5=BC?= =?UTF-8?q?=E4=B8=BB=E5=8F=91=E5=B8=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/constants/application_objects.dart | 1 + lib/generated_plugin_registrant.dart | 2 + lib/main.dart | 1 + lib/pages/home/home_page.dart | 2 +- lib/pages/tab_navigator.dart | 73 ++++---- .../community_views/event_detail_page.dart | 4 +- .../community_views/widgets/chat_card.dart | 3 +- lib/utils/constants.dart | 3 + lib/utils/data_util.dart | 10 + lib/utils/updater_page.dart | 174 ++++++++++++++++++ macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 63 +++++++ pubspec.yaml | 1 + 13 files changed, 302 insertions(+), 37 deletions(-) create mode 100644 lib/utils/constants.dart create mode 100644 lib/utils/data_util.dart create mode 100644 lib/utils/updater_page.dart diff --git a/lib/constants/application_objects.dart b/lib/constants/application_objects.dart index b091f17d..6cb8ac2e 100644 --- a/lib/constants/application_objects.dart +++ b/lib/constants/application_objects.dart @@ -36,6 +36,7 @@ import 'package:aku_new_community/ui/profile/car/car_manage_page.dart'; import 'package:aku_new_community/ui/profile/car_parking/car_parking_page.dart'; import 'package:aku_new_community/ui/profile/house/house_owners_page.dart'; + ///应用对象 ///Application Object class AO { diff --git a/lib/generated_plugin_registrant.dart b/lib/generated_plugin_registrant.dart index 366ed6c3..e821df08 100644 --- a/lib/generated_plugin_registrant.dart +++ b/lib/generated_plugin_registrant.dart @@ -12,6 +12,7 @@ import 'package:flutter_sound_web/flutter_sound_web.dart'; import 'package:image_picker_for_web/image_picker_for_web.dart'; import 'package:just_audio_web/just_audio_web.dart'; import 'package:package_info_plus_web/package_info_plus_web.dart'; +import 'package:shared_preferences_web/shared_preferences_web.dart'; import 'package:url_launcher_web/url_launcher_web.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; @@ -24,6 +25,7 @@ void registerPlugins(Registrar registrar) { ImagePickerPlugin.registerWith(registrar); JustAudioPlugin.registerWith(registrar); PackageInfoPlugin.registerWith(registrar); + SharedPreferencesPlugin.registerWith(registrar); UrlLauncherPlugin.registerWith(registrar); registrar.registerMessageHandler(); } diff --git a/lib/main.dart b/lib/main.dart index 837ec0bb..d27b8aa1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'package:aku_new_community/provider/old_age_provider.dart'; +import 'package:aku_new_community/utils/updater_page.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index 4221a26a..8930da44 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -419,7 +419,7 @@ class _HomePageState extends State )), SliverToBoxAdapter( child: 48.hb, - ) + ), ], ), ), diff --git a/lib/pages/tab_navigator.dart b/lib/pages/tab_navigator.dart index eadecdd6..8ff67e5a 100644 --- a/lib/pages/tab_navigator.dart +++ b/lib/pages/tab_navigator.dart @@ -14,6 +14,7 @@ import 'package:aku_new_community/ui/market/market_page.dart'; import 'package:aku_new_community/utils/websocket/web_socket_util.dart'; import 'package:aku_new_community/widget/bee_scaffold.dart'; import 'package:aku_new_community/widget/others/user_tool.dart'; +import '../utils/updater_page.dart'; import 'home/home_page.dart'; import 'opening_code_page/opening_code_page.dart'; import 'personal/personal_page.dart'; @@ -181,41 +182,45 @@ class _TabNavigatorState extends State 4, ), ]; - return BeeScaffold( - body: WillPopScope( - onWillPop: () async { - if (_lastPressed == null || - DateTime.now().difference(_lastPressed!) > Duration(seconds: 1)) { - //两次点击间隔超过1秒重新计算 - _lastPressed = DateTime.now(); - BotToast.showText(text: '再点击一次返回退出'); - return false; - } - //否则关闭app - WebSocketUtil().closeWebSocket(); - return true; - }, - child: TabBarView( - children: _pages, - controller: _tabController, - physics: NeverScrollableScrollPhysics(), - ), - ), - bottomNavi: ConstrainedBox( - constraints: BoxConstraints(maxWidth: 750.w, maxHeight: 146.w), - child: Container( - margin: + return UpdaterPage( + BeeScaffold( + body: WillPopScope( + onWillPop: () async { + if (_lastPressed == null || + DateTime.now().difference(_lastPressed!) > Duration(seconds: 1)) { + //两次点击间隔超过1秒重新计算 + _lastPressed = DateTime.now(); + BotToast.showText(text: '再点击一次返回退出'); + return false; + } + //否则关闭app + WebSocketUtil().closeWebSocket(); + return true; + }, + child: TabBarView( + children: _pages, + controller: _tabController, + physics: NeverScrollableScrollPhysics(), + ), + ), + bottomNavi: ConstrainedBox( + constraints: BoxConstraints(maxWidth: 750.w, maxHeight: 146.w), + child: Container( + margin: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom), - decoration: BoxDecoration( - image: DecorationImage( - image: Assets.home.imgTabdi, fit: BoxFit.fitWidth), - color: Colors.transparent), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: _bottomNav.cast().toList(), + decoration: BoxDecoration( + image: DecorationImage( + image: Assets.home.imgTabdi, fit: BoxFit.fitWidth), + color: Colors.transparent), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: _bottomNav.cast().toList(), + ), + ), ), - ), - ), - ); + ) + ) + + ; } } diff --git a/lib/ui/community/community_views/event_detail_page.dart b/lib/ui/community/community_views/event_detail_page.dart index 10e1aca5..ee7a230c 100644 --- a/lib/ui/community/community_views/event_detail_page.dart +++ b/lib/ui/community/community_views/event_detail_page.dart @@ -28,11 +28,13 @@ import 'package:aku_new_community/widget/bee_scaffold.dart'; class EventDetailPage extends StatefulWidget { final int dynamicId; + final int? createId; final VoidCallback? refresh; EventDetailPage({ Key? key, required this.dynamicId, + this.createId, this.refresh, }) : super(key: key); @@ -533,7 +535,7 @@ class _EventDetailPageState extends State { fontSize: 28.sp, ), children: [ - if (createId == model.createId) + if (model.createId ==widget.createId) WidgetSpan( child: Container( width: 56.w, diff --git a/lib/ui/community/community_views/widgets/chat_card.dart b/lib/ui/community/community_views/widgets/chat_card.dart index 8f9370f0..abc60097 100644 --- a/lib/ui/community/community_views/widgets/chat_card.dart +++ b/lib/ui/community/community_views/widgets/chat_card.dart @@ -144,7 +144,7 @@ class _ChatCardState extends State { ), 20.wb, GestureDetector( - onTap: () => Get.to(EventDetailPage(dynamicId: widget.model.id)), + onTap: () => Get.to(EventDetailPage(dynamicId: widget.model.id,createId: widget.model.createId,)), child: Material( color: Colors.transparent, child: Row( @@ -194,6 +194,7 @@ class _ChatCardState extends State { ? () async { await Get.to(() => EventDetailPage( dynamicId: widget.model.id, + createId: widget.model.createId, refresh: widget.refresh, )); widget.refresh(); diff --git a/lib/utils/constants.dart b/lib/utils/constants.dart new file mode 100644 index 00000000..a00bc80b --- /dev/null +++ b/lib/utils/constants.dart @@ -0,0 +1,3 @@ +class Constants { + static final String timeStart = "timeStart"; +} diff --git a/lib/utils/data_util.dart b/lib/utils/data_util.dart new file mode 100644 index 00000000..74319fbb --- /dev/null +++ b/lib/utils/data_util.dart @@ -0,0 +1,10 @@ +import 'package:sp_util/sp_util.dart'; + +import 'constants.dart'; + +class DataUtil { + static saveCurrentTimeMillis(int timeStart) async { + await SpUtil.getInstance(); + SpUtil.putInt(Constants.timeStart, timeStart); + } +} diff --git a/lib/utils/updater_page.dart b/lib/utils/updater_page.dart new file mode 100644 index 00000000..255167c9 --- /dev/null +++ b/lib/utils/updater_page.dart @@ -0,0 +1,174 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:package_info/package_info.dart'; +import 'package:dio/dio.dart'; +import 'package:sp_util/sp_util.dart'; +import 'package:url_launcher/url_launcher.dart'; +import 'constants.dart'; +import 'data_util.dart'; + +class UpdaterPage extends StatefulWidget { + final Widget child; + + const UpdaterPage(this.child); + + @override + UpdatePagerState createState() => UpdatePagerState(); +} + +class UpdatePagerState extends State { + var _serviceVersionCode, + _serviceVersionName, + _serviceVersionPlatform, + _serviceVersionApp; + + @override + void initState() { + super.initState(); + //每次打开APP获取当前时间戳 + var timeEnd = DateTime.now().millisecondsSinceEpoch; + _getNewVersionAPP(); + //获取"Later"保存的时间戳 + var timeStart = SpUtil.getInt(Constants.timeStart); + if (timeStart == 0) { + //第一次打开APP时执行"版本更新"的网络请求 + _getNewVersionAPP(); + } else if (timeStart != 0 && timeEnd - timeStart! >= 24 * 60 * 60 * 1000) { + //如果新旧时间戳的差大于或等于一天,执行网络请求 + _getNewVersionAPP(); + } + + } + + //执行版本更新的网络请求 + _getNewVersionAPP() async { + String url = "/appversions/latest"; //接口的URL,替换你的URL + try { + Response response = await Dio().get(url); + setState(() { + var data = response.data; + _serviceVersionCode = data["versionCode"].toString(); //版本号 + _serviceVersionName = data["versionName"].toString(); //版本名称 + _serviceVersionPlatform = data["versionPlatform"].toString(); //版本平台 + _serviceVersionApp = data["versionApp"].toString(); //下载的URL + _checkVersionCode(); + }); + } catch (e) { + print(e); + } + _checkVersionCode(); + } + + //检查版本更新的版本号 + _checkVersionCode() async { + PackageInfo packageInfo = await PackageInfo.fromPlatform(); + String _currentVersionCode = packageInfo.version; + print('版本——————————————————————'+ '${_currentVersionCode}'); + int serviceVersionCode = int.parse(_serviceVersionCode); + print(serviceVersionCode); + int currentVersionCode = int.parse(_currentVersionCode); + print(currentVersionCode); + if (serviceVersionCode > currentVersionCode) { + _showNewVersionAppDialog(); //弹出对话框 + } + } + + //弹出"版本更新"对话框 + Future _showNewVersionAppDialog() async { + print('弹出框'); + if (_serviceVersionPlatform == "android") { + return showDialog( + context: context, + barrierDismissible: false, + builder: (BuildContext context) { + return AlertDialog( + title: Row( + children: [ + Image.asset("images/ic_launcher_icon.png", + height: 35.0, width: 35.0), + Padding( + padding: EdgeInsets.fromLTRB(30.0, 0.0, 10.0, 0.0), + child: Text('项目名称', + style: TextStyle( + color: Color(0xFF384F6F), fontSize: 20.0),),) + ], + ), + content: Text('提示的内容', + style: TextStyle( + color: Color(0xFF384F6F), fontSize: 18.0),), + actions: [ + OutlinedButton( + child: new Text('稍后再说', + style: TextStyle( + color: Color(0xFF384F6F), fontSize: 20.0),), + onPressed: () { + Navigator.of(context).pop(); + var timeStart = DateTime.now().millisecondsSinceEpoch; + DataUtil.saveCurrentTimeMillis(timeStart); //保存当前的时间戳 + }, + ), + OutlinedButton( + child: new Text('下载', + style: TextStyle( + color: Color(0xFF384F6F), fontSize: 20.0)), + onPressed: () { + //https://play.google.com/store/apps/details?id=项目包名 + launch(_serviceVersionApp); //到Google Play 官网下载 + Navigator.of(context).pop(); + }, + ) + ], + ); + }); + } else { + //iOS + return showDialog( + context: context, + barrierDismissible: false, + builder: (BuildContext context) { + return CupertinoAlertDialog( + title:Row( + children: [ + Image.asset("images/ic_launcher_icon.png", + height: 35.0, width: 35.0), + Padding( + padding: EdgeInsets.fromLTRB(30.0, 0.0, 10.0, 0.0), + child: Text('项目名称', + style: TextStyle( + color: Color(0xFF384F6F), fontSize: 20.0),),) + ], + ), + content: Text('提示的内容', + style: TextStyle( + color: Color(0xFF384F6F), fontSize: 18.0),), + + actions: [ + OutlinedButton( + child: new Text('稍后再说', + style: TextStyle( + color: Color(0xFF384F6F), fontSize: 20.0),), + onPressed: () { + Navigator.of(context).pop(); + var timeStart = DateTime.now().millisecondsSinceEpoch; + DataUtil.saveCurrentTimeMillis(timeStart); //保存当前的时间戳 + }, + ), + OutlinedButton( + child: new Text('下载', + style: TextStyle( + color: Color(0xFF384F6F), fontSize: 20.0)), + onPressed: () { + //https://play.google.com/store/apps/details?id=项目包名 + launch(_serviceVersionApp); //到Google Play 官网下载 + Navigator.of(context).pop(); + }, + ), + ], + ); + }); + } + } + + @override + Widget build(BuildContext context) => widget.child; +} diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index d850309c..6d75cc5e 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -11,6 +11,7 @@ import just_audio import package_info import package_info_plus_macos import path_provider_macos +import shared_preferences_macos import sqflite import url_launcher_macos @@ -21,6 +22,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLTPackageInfoPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlugin")) FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) + SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index d20c2ce7..1dbc6db8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1128,6 +1128,62 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.4" + shared_preferences: + dependency: transitive + description: + name: shared_preferences + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.15" + shared_preferences_android: + dependency: transitive + description: + name: shared_preferences_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.12" + shared_preferences_ios: + dependency: transitive + description: + name: shared_preferences_ios + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + shared_preferences_macos: + dependency: transitive + description: + name: shared_preferences_macos + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.4" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.4" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" shelf: dependency: transitive description: @@ -1189,6 +1245,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.2" + sp_util: + dependency: "direct main" + description: + name: sp_util + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.3" sqflite: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index b55896d6..e9ffef59 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -127,6 +127,7 @@ dependencies: like_button: ^2.0.4 #图片扩展 extended_image: ^6.1.0 + sp_util: ^2.0.0 dev_dependencies: flutter_test: