diff --git a/lib/constants/saas_api.dart b/lib/constants/saas_api.dart index 2c384e3e..da3b5699 100644 --- a/lib/constants/saas_api.dart +++ b/lib/constants/saas_api.dart @@ -44,6 +44,7 @@ class SAASAPI { static _Vote vote = _Vote(); static _Facilities facilities = _Facilities(); static _Bracelet bracelet = _Bracelet(); + static _Updater updater = _Updater(); ///二级分类 static _ProfileApi profile = _ProfileApi(); @@ -439,3 +440,10 @@ class _Facilities { ///取消预约 String get cancel => '/app/user/facilities/cancel'; } + +class _Updater{ + ///查询最新的app版本 + String get findNewVersion => '/app/version/findNewVersion'; + ///添加新的app版本 + String get insert => '/app/version/insert'; +} diff --git a/lib/main.dart b/lib/main.dart index d27b8aa1..837ec0bb 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,4 @@ 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/setting_page/settings_page.dart b/lib/pages/setting_page/settings_page.dart index 530dac71..b3294cf7 100644 --- a/lib/pages/setting_page/settings_page.dart +++ b/lib/pages/setting_page/settings_page.dart @@ -18,6 +18,7 @@ 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 'account_manager_page.dart'; import 'feedback_page/feedback_page.dart'; class SettingsPage extends StatefulWidget { diff --git a/lib/pages/tab_navigator.dart b/lib/pages/tab_navigator.dart index 778844c0..c201c31d 100644 --- a/lib/pages/tab_navigator.dart +++ b/lib/pages/tab_navigator.dart @@ -15,7 +15,6 @@ 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'; @@ -50,7 +49,7 @@ class _TabNavigatorState extends State flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin(); var android = new AndroidInitializationSettings('@mipmap/ic_launcher'); var iOS = new IOSInitializationSettings(); - var initSettings = new InitializationSettings(android: android, iOS: iOS); + var initSettings = new InitializationSettings(android: android,iOS: iOS); flutterLocalNotificationsPlugin.initialize(initSettings); //showNotification(); @@ -191,41 +190,42 @@ 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 + 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(), + ), + ), ), - ), - ), ); } @@ -235,24 +235,19 @@ class _TabNavigatorState extends State } //payload 可作为通知的一个标记,区分点击的通知。 debugPrint('payload:$payload'); - if (payload == "complete") { - await showDialog( - context: context, - builder: (_) => AlertDialog( - title: Text('Notification'), - content: Text('$payload'), - ), - ); + if(payload == "complete") { + await showDialog(context: context, builder: (_) => AlertDialog( + title: Text('Notification'), + content: Text('$payload'), + ),); } } showNotification() async { var android = new AndroidNotificationDetails( - 'channel id', - 'channel NAME', + 'channel id', 'channel NAME', priority: Priority.high, - importance: Importance.max, - ); + importance: Importance.max,); var iOS = new IOSNotificationDetails(); var platform = new NotificationDetails(android: android, iOS: iOS); await flutterLocalNotificationsPlugin.show( diff --git a/lib/utils/updater/updater_model.dart b/lib/utils/updater/updater_model.dart new file mode 100644 index 00000000..35b0069d --- /dev/null +++ b/lib/utils/updater/updater_model.dart @@ -0,0 +1,28 @@ +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; +part 'updater_model.g.dart'; + +@JsonSerializable() +class UpdaterModel extends Equatable{ + final int id; + final String versionNumber; + final String buildNo; + final int forceUpdate; + final String createDate; + + factory UpdaterModel.fromJson(Map json) =>_$UpdaterModelFromJson(json); + + const UpdaterModel({ + required this.id, + required this.versionNumber, + required this.buildNo, + required this.forceUpdate, + required this.createDate, + }); + + @override + List get props => [ + id,versionNumber,buildNo,forceUpdate,createDate, + ]; +} + diff --git a/lib/utils/updater/updater_model.g.dart b/lib/utils/updater/updater_model.g.dart new file mode 100644 index 00000000..35da6db2 --- /dev/null +++ b/lib/utils/updater/updater_model.g.dart @@ -0,0 +1,15 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'updater_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +UpdaterModel _$UpdaterModelFromJson(Map json) => UpdaterModel( + id: json['id'] as int, + versionNumber: json['versionNumber'] as String, + buildNo: json['buildNo'] as String, + forceUpdate: json['forceUpdate'] as int, + createDate: json['createDate'] as String, + ); diff --git a/lib/utils/updater_page.dart b/lib/utils/updater/updater_page.dart similarity index 90% rename from lib/utils/updater_page.dart rename to lib/utils/updater/updater_page.dart index 255167c9..d9c39a7a 100644 --- a/lib/utils/updater_page.dart +++ b/lib/utils/updater/updater_page.dart @@ -1,15 +1,17 @@ +import 'package:aku_new_community/utils/updater/updater_model.dart'; 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'; +import '../../constants/saas_api.dart'; +import '../constants.dart'; +import '../data_util.dart'; +import '../network/net_util.dart'; class UpdaterPage extends StatefulWidget { final Widget child; - const UpdaterPage(this.child); @override @@ -17,6 +19,7 @@ class UpdaterPage extends StatefulWidget { } class UpdatePagerState extends State { + UpdaterModel? _model; var _serviceVersionCode, _serviceVersionName, _serviceVersionPlatform, @@ -42,19 +45,13 @@ class UpdatePagerState extends State { //执行版本更新的网络请求 _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); + var base = + await NetUtil().get(SAASAPI.updater.findNewVersion, params: { + 'version': '1.8.12', + }); + if (base.success) { + _model = UpdaterModel.fromJson(base.data); + setState(() {}); } _checkVersionCode(); }