From da91143fde361b86de8229b7a5a93fca12be4558 Mon Sep 17 00:00:00 2001 From: w-R <953969641@qq.com> Date: Thu, 12 May 2022 16:44:22 +0800 Subject: [PATCH] =?UTF-8?q?app=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community_view/community_dynamic.dart | 47 +++---- lib/main_page.dart | 49 ++++++- lib/retrofit/data/app_update.dart | 43 ++++++ lib/retrofit/min_api.dart | 2 +- lib/retrofit/retrofit_api.dart | 7 +- lib/retrofit/retrofit_api.g.dart | 21 +++ lib/setting/about_page.dart | 13 -- lib/store/store_view/product_sku.dart | 126 ++++++++++-------- lib/view_widget/update_dialog.dart | 37 ++--- 9 files changed, 232 insertions(+), 113 deletions(-) create mode 100644 lib/retrofit/data/app_update.dart diff --git a/lib/community/community_view/community_dynamic.dart b/lib/community/community_view/community_dynamic.dart index 83a235dc..262946a7 100644 --- a/lib/community/community_view/community_dynamic.dart +++ b/lib/community/community_view/community_dynamic.dart @@ -317,29 +317,30 @@ class _CommunityDynamic extends State { height:8.h, ), if (widget.article.location != "") - Row( - children: [ - Icon( - Icons.place, - size: 16, - color: Color(0xFFB3B2B2), - ), - SizedBox( - width: 2, - ), - Expanded( - child: Text( - widget?.article?.location ?? "", - overflow: TextOverflow.ellipsis, - maxLines: 1, - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.medium, - color: Color(0xFFB3B2B2), - ), - )), - ], - ), + Padding(padding:EdgeInsets.only(bottom:7), + child: Row( + children: [ + Icon( + Icons.place, + size: 16, + color: Color(0xFFB3B2B2), + ), + SizedBox( + width: 2, + ), + Expanded( + child: Text( + widget?.article?.location ?? "", + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: TextStyle( + fontSize: 12.sp, + fontWeight: MyFontWeight.medium, + color: Color(0xFFB3B2B2), + ), + )), + ], + ),), if (!widget.isDetails) SizedBox( height: 5.h, diff --git a/lib/main_page.dart b/lib/main_page.dart index c7b5fc0b..58acba26 100644 --- a/lib/main_page.dart +++ b/lib/main_page.dart @@ -5,12 +5,14 @@ import 'package:flutter/material.dart'; import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:huixiang/community/community_page.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/home/home_page.dart'; import 'package:huixiang/main.dart'; import 'package:huixiang/mine/mine_page.dart'; +import 'package:huixiang/retrofit/data/app_update.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/user_info.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; @@ -20,6 +22,7 @@ import 'package:huixiang/utils/bridge.dart'; import 'package:huixiang/utils/event_type.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/native_event_handler.dart'; +import 'package:huixiang/view_widget/update_dialog.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:sharesdk_plugin/sharesdk_interface.dart'; @@ -46,6 +49,10 @@ class _MainPage extends State with WidgetsBindingObserver { List icons; final GlobalKey homePageKey = GlobalKey(); // List iconn; + ApiService apiService; + String version = "1.0.1"; + AppUpdate appUpdate; + @override void dispose() { @@ -138,6 +145,8 @@ class _MainPage extends State with WidgetsBindingObserver { }); queryUserInfo(); + + appAutoUpdate(); } final XgFlutterPlugin xgFlutterPlugin = XgFlutterPlugin(); initSdk() async { @@ -316,6 +325,31 @@ class _MainPage extends State with WidgetsBindingObserver { } } + ///app自动更新 + appAutoUpdate() async { + if (apiService == null) { + SharedPreferences value = await SharedPreferences.getInstance(); + apiService = ApiService( + Dio(), + context: context, + token: value.getString("token"), + showLoading: true + ); + } + BaseData baseData = await apiService.appVersion().catchError((onError) {}); + if (baseData != null && baseData.isSuccess) { + if(version != appUpdate?.appLastVersion ?? ""){ + showAlertDialog(version); + }else{ + return; + } + }else{ + SmartDialog.showToast(baseData.msg, + alignment: Alignment.center); + Navigator.of(context).pop(); + } + } + final PageController pageController = PageController(initialPage: 0); @override @@ -358,8 +392,8 @@ class _MainPage extends State with WidgetsBindingObserver { // bottomNavigationBigItem(S.of(context).pinpai, 0), bottomNavigationItem(S.of(context).main_menu1, 0), bottomNavigationItem(S.of(context).main_menu2, 1), - // bottomNavigationItem(S.of(context).main_menu3 , 2) - bottomNavigationItem("订单", 2), + bottomNavigationItem(S.of(context).main_menu3 , 2), + // bottomNavigationItem("订单", 2), bottomNavigationItem(S.of(context).main_menu4, 3), ], ), @@ -441,6 +475,17 @@ class _MainPage extends State with WidgetsBindingObserver { ); } + ///app更新弹窗 + showAlertDialog(version) { + //显示对话框 + showDialog( + context: context, + builder: (BuildContext context) { + return UpdateDialog(version,appUpdate); + }, + ); + } + // Widget bottomNavigationBigItem(text, index) { // var isSelected = index == clickIndex; diff --git a/lib/retrofit/data/app_update.dart b/lib/retrofit/data/app_update.dart new file mode 100644 index 00000000..cac55b14 --- /dev/null +++ b/lib/retrofit/data/app_update.dart @@ -0,0 +1,43 @@ +/// appLastVersion : "1.0.0" +/// appLastVersionUrl : "" +/// appLastVersionUp : "1.0.0" +/// appLastVersionExplain : "优化更新" + +class AppUpdate { + AppUpdate({ + String appLastVersion, + String appLastVersionUrl, + String appLastVersionUp, + String appLastVersionExplain,}){ + _appLastVersion = appLastVersion; + _appLastVersionUrl = appLastVersionUrl; + _appLastVersionUp = appLastVersionUp; + _appLastVersionExplain = appLastVersionExplain; +} + + AppUpdate.fromJson(dynamic json) { + _appLastVersion = json['appLastVersion']; + _appLastVersionUrl = json['appLastVersionUrl']; + _appLastVersionUp = json['appLastVersionUp']; + _appLastVersionExplain = json['appLastVersionExplain']; + } + String _appLastVersion; + String _appLastVersionUrl; + String _appLastVersionUp; + String _appLastVersionExplain; + + String get appLastVersion => _appLastVersion; + String get appLastVersionUrl => _appLastVersionUrl; + String get appLastVersionUp => _appLastVersionUp; + String get appLastVersionExplain => _appLastVersionExplain; + + Map toJson() { + final map = {}; + map['appLastVersion'] = _appLastVersion; + map['appLastVersionUrl'] = _appLastVersionUrl; + map['appLastVersionUp'] = _appLastVersionUp; + map['appLastVersionExplain'] = _appLastVersionExplain; + return map; + } + +} \ No newline at end of file diff --git a/lib/retrofit/min_api.dart b/lib/retrofit/min_api.dart index f8e85a64..3154e15d 100644 --- a/lib/retrofit/min_api.dart +++ b/lib/retrofit/min_api.dart @@ -32,7 +32,7 @@ part 'min_api.g.dart'; // const base_url = "http://192.168.10.37:8766/app/"; -const localBaseUrl = "https://pos.api.lotus-wallet.com/app/";///本地 +const localBaseUrl = "http://192.168.10.236:8766/app/";///本地 const serviceBaseUrl = "https://pos.api.lotus-wallet.com/app/";///线上 diff --git a/lib/retrofit/retrofit_api.dart b/lib/retrofit/retrofit_api.dart index 1f7b8706..75508c21 100644 --- a/lib/retrofit/retrofit_api.dart +++ b/lib/retrofit/retrofit_api.dart @@ -21,6 +21,7 @@ import 'package:retrofit/retrofit.dart'; import 'data/achievement_detail_list.dart'; import 'data/activity_pos.dart'; import 'data/address.dart'; +import 'data/app_update.dart'; import 'data/banner.dart'; import 'data/brand_data.dart'; import 'data/category_select_list.dart'; @@ -68,7 +69,7 @@ part 'retrofit_api.g.dart'; // const base_url = "http://192.168.10.132:8766/app/";///詹云久 -const localBaseUrl = "https://pos.platform.lotus-wallet.com/app/";///本地 +const localBaseUrl = "http://192.168.10.236:8766/app/";///本地 const serviceBaseUrl = "https://pos.platform.lotus-wallet.com/app/";///线上 @RestApi(baseUrl: localBaseUrl) @@ -518,4 +519,8 @@ abstract class ApiService { @POST("/information/complaint") Future complaint(@Body() Map param); + ///app自动更新 + @GET("/home/version") + Future> appVersion(); + } diff --git a/lib/retrofit/retrofit_api.g.dart b/lib/retrofit/retrofit_api.g.dart index 8d41ae6c..ac8c7fa4 100644 --- a/lib/retrofit/retrofit_api.g.dart +++ b/lib/retrofit/retrofit_api.g.dart @@ -1958,4 +1958,25 @@ class _ApiService implements ApiService { return value; } + @override + Future> appVersion() async { + const _extra = {}; + final queryParameters = {}; + final _data = {}; + final _result = await _dio.request>( + '/home/version', + queryParameters: queryParameters, + options: RequestOptions( + method: 'GET', + headers: {}, + extra: _extra, + baseUrl: baseUrl), + data: _data); + final value = BaseData.fromJson( + _result.data, + (json) => AppUpdate.fromJson(json), + ); + return value; + } + } diff --git a/lib/setting/about_page.dart b/lib/setting/about_page.dart index 0d88b5f0..80d31310 100644 --- a/lib/setting/about_page.dart +++ b/lib/setting/about_page.dart @@ -89,7 +89,6 @@ class _AboutPage extends State { onTap: () { Navigator.of(context) .pushNamed('/router/help_feedback_page'); - // showAlertDialog(version); }, child: textItem(S.of(context).shiyongbangzhu), ), @@ -103,7 +102,6 @@ class _AboutPage extends State { alignment: Alignment.center); } }); - // showAlertDialog(version); }, ), GestureDetector( @@ -279,15 +277,4 @@ class _AboutPage extends State { ), ); } - - ///app更新弹窗 - showAlertDialog(version) { - //显示对话框 - showDialog( - context: context, - builder: (BuildContext context) { - return UpdateDialog(version); - }, - ); - } } diff --git a/lib/store/store_view/product_sku.dart b/lib/store/store_view/product_sku.dart index 0a6ed333..3312254f 100644 --- a/lib/store/store_view/product_sku.dart +++ b/lib/store/store_view/product_sku.dart @@ -198,10 +198,9 @@ class _ProductSku extends State { padding: EdgeInsets.zero, itemBuilder: (context, position) { return attrItem( - (index) { + (attrValue) { state(() { - selectSkus[position] = widget.miNiDetail - .attrList[position].attrValueList[index].attrValue; + selectSkus[position] = attrValue; buildCount(); }); }, @@ -301,7 +300,7 @@ class _ProductSku extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( - padding: EdgeInsets.only(top: 24, bottom: 16), + padding: EdgeInsets.only(top: 16, bottom: 16), child: Text( attrListBean.attrName, style: TextStyle( @@ -311,7 +310,8 @@ class _ProductSku extends State { ), ), ), - sweetnessStore(fc, attrListBean.attrValueList, position), + sweetnessStore(fc,attrListBean.attrValueList, position), + // sweetnessStore(fc, attrListBean.attrValueList, position), ], ); else { @@ -319,62 +319,74 @@ class _ProductSku extends State { } } - Widget sweetnessStore(Function fc, List arrays, position) { - return GridView.builder( - itemCount: arrays.length, - shrinkWrap: true, - padding: EdgeInsets.zero, - physics: NeverScrollableScrollPhysics(), - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - //一行的Widget数量 - crossAxisCount: 4, - //水平子Widget之间间距 - crossAxisSpacing: 6.w, - //垂直子Widget之间间距 - mainAxisSpacing: 12.w, - //垂直单个子Widget之间间距 - childAspectRatio: 3 / 1, - ), - itemBuilder: (context, index) { - return GestureDetector( - onTap: () { - fc(index); - }, - child: sweetnessItem( - arrays[index].attrValue, - (arrays[index].attrValue == selectSkus[position]) ?? false, - ), - ); - }, - ); + // Widget sweetnessStore(Function fc, List arrays, position) { + // return GridView.builder( + // itemCount: arrays.length, + // shrinkWrap: true, + // padding: EdgeInsets.zero, + // physics: NeverScrollableScrollPhysics(), + // gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + // //一行的Widget数量 + // crossAxisCount: 4, + // //水平子Widget之间间距 + // crossAxisSpacing: 6.w, + // //垂直子Widget之间间距 + // mainAxisSpacing: 12.w, + // //垂直单个子Widget之间间距 + // childAspectRatio: 3 / 1, + // ), + // itemBuilder: (context, index) { + // return GestureDetector( + // onTap: () { + // fc(index); + // }, + // child: sweetnessItem( + // arrays[index].attrValue, + // (arrays[index].attrValue == selectSkus[position]) ?? false, + // ), + // ); + // }, + // ); + // } + + Widget sweetnessStore(Function fc,List arrays, position){ + return Wrap( + runSpacing: 10.0, + spacing: 10.0, + children: arrays.take(arrays.length).map((AttrValueListBean tag) { + return GestureDetector( + onTap: () { + fc(tag.attrValue); + }, + child:sweetnessItem( + tag.attrValue, + (tag.attrValue == selectSkus[position]) ?? false, + )); + }).toList()); } Widget sweetnessItem(String name, bool isCheck) { return Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - width: 70.w, - height:30.h, - alignment: Alignment.center, - decoration: BoxDecoration( - color: !isCheck ? Color(0xFFE5E5E5) : Color(0xFF32A060), - borderRadius: BorderRadius.all(Radius.circular(4)), - ), - child:Text( - name, - overflow: TextOverflow.ellipsis, - style: TextStyle( - color:!isCheck ? Color(0xFF727272) : Colors.white, - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - ), - ), + padding: const EdgeInsets.symmetric(vertical:5.0,horizontal: 12.0), + decoration: BoxDecoration( + color: !isCheck ? Color(0xFFF2F2F2) : Color(0xFFF0FAF4), + border: Border.all( + width: !isCheck ? 0:1, + color: !isCheck ? Color(0xFFF2F2F2):Color(0xFF32A060), + style: BorderStyle.solid, ), - ], - ), - ); + borderRadius: const BorderRadius.all( + Radius.circular(4.0), + ), + ), + child: Text( + name, + overflow: TextOverflow.ellipsis, + style: TextStyle( + color:!isCheck ? Color(0xFF4D4D4D) : Color(0xFF32A060), + fontSize: 14.sp, + fontWeight: MyFontWeight.regular, + ), + )); } } diff --git a/lib/view_widget/update_dialog.dart b/lib/view_widget/update_dialog.dart index 95f58d36..2d590c1d 100644 --- a/lib/view_widget/update_dialog.dart +++ b/lib/view_widget/update_dialog.dart @@ -2,14 +2,17 @@ import 'dart:io'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter/material.dart'; +import 'package:huixiang/retrofit/data/app_update.dart'; import 'package:huixiang/utils/bridge.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:url_launcher/url_launcher.dart'; class UpdateDialog extends StatefulWidget { final String version; + final AppUpdate appUpdate; - UpdateDialog(this.version); + UpdateDialog(this.version,this.appUpdate); @override State createState() { @@ -42,17 +45,18 @@ class _UpdateDialog extends State { Text( "检测到新版本 v${widget.version}", style: TextStyle( - fontSize: 18.sp, + fontSize: 17.sp, fontWeight: MyFontWeight.semi_bold, - color: Color(0xFF353535), + color: Color(0xFF000000), ), ), + SizedBox(height: 12,), Text( "是否需要更新到最新版本?", style: TextStyle( - fontSize: 14.sp, + fontSize: 17.sp, fontWeight: MyFontWeight.regular, - color: Color(0xFF353535), + color: Color(0xFF333333), ), ), ], @@ -80,8 +84,8 @@ class _UpdateDialog extends State { "下次再说", style: TextStyle( fontSize: 17.sp, - fontWeight: MyFontWeight.medium, - color: Color(0xFF353535), + fontWeight: MyFontWeight.semi_bold, + color: Color(0xFF8C8C8C), ), ), ), @@ -95,7 +99,8 @@ class _UpdateDialog extends State { Expanded( child: InkWell( onTap: () { - Bridge.toAppStore().then((value) { + (Theme.of(context).platform == TargetPlatform.android) ? + androidUpdate():Bridge.toAppStore().then((value) { }); Navigator.of(context).pop(); }, @@ -107,7 +112,7 @@ class _UpdateDialog extends State { "立即更新", style: TextStyle( fontSize: 17.sp, - fontWeight: MyFontWeight.medium, + fontWeight: MyFontWeight.semi_bold, color: Color(0xFF32A060), ), ), @@ -125,13 +130,13 @@ class _UpdateDialog extends State { ); } - - Future _findLocalPath(BuildContext context) async { - final directory = Theme.of(context).platform == TargetPlatform.android - ? await getExternalStorageDirectory() - : await getApplicationDocumentsDirectory(); - return directory.path; + androidUpdate() async { + String url = "http://application.lotus-wallet.com/huixaing?release_id=627cadff23389f2fe6d57cb1"; + if (await canLaunch(url)) { + await launch(url); + } else { + throw 'Could not launch $url'; + } } - }