Browse Source

app自动更新

remove_uniapp
w-R 3 years ago
parent
commit
da91143fde
  1. 5
      lib/community/community_view/community_dynamic.dart
  2. 49
      lib/main_page.dart
  3. 43
      lib/retrofit/data/app_update.dart
  4. 2
      lib/retrofit/min_api.dart
  5. 7
      lib/retrofit/retrofit_api.dart
  6. 21
      lib/retrofit/retrofit_api.g.dart
  7. 13
      lib/setting/about_page.dart
  8. 100
      lib/store/store_view/product_sku.dart
  9. 37
      lib/view_widget/update_dialog.dart

5
lib/community/community_view/community_dynamic.dart

@ -317,7 +317,8 @@ class _CommunityDynamic extends State<CommunityDynamic> {
height:8.h,
),
if (widget.article.location != "")
Row(
Padding(padding:EdgeInsets.only(bottom:7),
child: Row(
children: [
Icon(
Icons.place,
@ -339,7 +340,7 @@ class _CommunityDynamic extends State<CommunityDynamic> {
),
)),
],
),
),),
if (!widget.isDetails)
SizedBox(
height: 5.h,

49
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<MainPage> with WidgetsBindingObserver {
List<String> icons;
final GlobalKey homePageKey = GlobalKey();
// List<String> iconn;
ApiService apiService;
String version = "1.0.1";
AppUpdate appUpdate;
@override
void dispose() {
@ -138,6 +145,8 @@ class _MainPage extends State<MainPage> with WidgetsBindingObserver {
});
queryUserInfo();
appAutoUpdate();
}
final XgFlutterPlugin xgFlutterPlugin = XgFlutterPlugin();
initSdk() async {
@ -316,6 +325,31 @@ class _MainPage extends State<MainPage> 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<AppUpdate> 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<MainPage> 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<MainPage> with WidgetsBindingObserver {
);
}
///app更新弹窗
showAlertDialog(version) {
//
showDialog(
context: context,
builder: (BuildContext context) {
return UpdateDialog(version,appUpdate);
},
);
}
// Widget bottomNavigationBigItem(text, index) {
// var isSelected = index == clickIndex;

43
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<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['appLastVersion'] = _appLastVersion;
map['appLastVersionUrl'] = _appLastVersionUrl;
map['appLastVersionUp'] = _appLastVersionUp;
map['appLastVersionExplain'] = _appLastVersionExplain;
return map;
}
}

2
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/";///线

7
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<BaseData> complaint(@Body() Map<String, dynamic> param);
///app自动更新
@GET("/home/version")
Future<BaseData<AppUpdate>> appVersion();
}

21
lib/retrofit/retrofit_api.g.dart

@ -1958,4 +1958,25 @@ class _ApiService implements ApiService {
return value;
}
@override
Future<BaseData<AppUpdate>> appVersion() async {
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{};
final _result = await _dio.request<Map<String, dynamic>>(
'/home/version',
queryParameters: queryParameters,
options: RequestOptions(
method: 'GET',
headers: <String, dynamic>{},
extra: _extra,
baseUrl: baseUrl),
data: _data);
final value = BaseData<AppUpdate>.fromJson(
_result.data,
(json) => AppUpdate.fromJson(json),
);
return value;
}
}

13
lib/setting/about_page.dart

@ -89,7 +89,6 @@ class _AboutPage extends State<AboutPage> {
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<AboutPage> {
alignment: Alignment.center);
}
});
// showAlertDialog(version);
},
),
GestureDetector(
@ -279,15 +277,4 @@ class _AboutPage extends State<AboutPage> {
),
);
}
///app更新弹窗
showAlertDialog(version) {
//
showDialog(
context: context,
builder: (BuildContext context) {
return UpdateDialog(version);
},
);
}
}

100
lib/store/store_view/product_sku.dart

@ -198,10 +198,9 @@ class _ProductSku extends State<ProductSku> {
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<ProductSku> {
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(
@ -312,6 +311,7 @@ class _ProductSku extends State<ProductSku> {
),
),
sweetnessStore(fc,attrListBean.attrValueList, position),
// sweetnessStore(fc, attrListBean.attrValueList, position),
],
);
else {
@ -319,62 +319,74 @@ class _ProductSku extends State<ProductSku> {
}
}
// Widget sweetnessStore(Function fc, List<AttrValueListBean> 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<AttrValueListBean> 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 Wrap(
runSpacing: 10.0,
spacing: 10.0,
children: arrays.take(arrays.length).map<Widget>((AttrValueListBean tag) {
return GestureDetector(
onTap: () {
fc(index);
fc(tag.attrValue);
},
child:sweetnessItem(
arrays[index].attrValue,
(arrays[index].attrValue == selectSkus[position]) ?? false,
),
);
},
);
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,
padding: const EdgeInsets.symmetric(vertical:5.0,horizontal: 12.0),
decoration: BoxDecoration(
color: !isCheck ? Color(0xFFE5E5E5) : Color(0xFF32A060),
borderRadius: BorderRadius.all(Radius.circular(4)),
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(0xFF727272) : Colors.white,
fontSize: 12.sp,
color:!isCheck ? Color(0xFF4D4D4D) : Color(0xFF32A060),
fontSize: 14.sp,
fontWeight: MyFontWeight.regular,
),
),
),
],
),
);
));
}
}

37
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<StatefulWidget> createState() {
@ -42,17 +45,18 @@ class _UpdateDialog extends State<UpdateDialog> {
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<UpdateDialog> {
"下次再说",
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<UpdateDialog> {
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<UpdateDialog> {
"立即更新",
style: TextStyle(
fontSize: 17.sp,
fontWeight: MyFontWeight.medium,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF32A060),
),
),
@ -125,13 +130,13 @@ class _UpdateDialog extends State<UpdateDialog> {
);
}
Future<String> _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';
}
}
}

Loading…
Cancel
Save