Browse Source

1、审核模版刷新的立即刷新

2、商品详情的商品商店问题
3、个人各种无网络崩溃问题
tags/0.0.9+9^2
PH2 3 years ago
parent
commit
ca6adcc980
10 changed files with 108 additions and 26 deletions
  1. +67
    -0
      lib/pages/custom_page/bloc/bottom_nav_repository.dart
  2. +14
    -0
      lib/pages/custom_page/bloc/custom_item_page_bloc.dart
  3. +1
    -6
      lib/pages/custom_page/bloc/custom_item_page_repository.dart
  4. +3
    -0
      lib/pages/custom_page/bloc/custom_item_page_state.dart
  5. +0
    -8
      lib/pages/custom_page/bloc/custom_page_repository.dart
  6. +10
    -0
      lib/pages/custom_page/custom_item_page.dart
  7. +1
    -1
      lib/widgets/goods_details/store/bloc/store_state.dart
  8. +2
    -1
      lib/widgets/mine/mine_data/mine_data_widget.dart
  9. +2
    -2
      lib/widgets/mine/mine_header/mine_header_container.dart
  10. +8
    -8
      lib/widgets/restart_widget/restart_widget.dart

+ 67
- 0
lib/pages/custom_page/bloc/bottom_nav_repository.dart View File

@@ -0,0 +1,67 @@
import 'dart:async';
import 'package:zhiying_comm/zhiying_comm.dart';

///
/// 底部导航栏数据Repository
///
class BottomNavRepository {

/// 获取网络数据
Future<dynamic> fetchNetData() async {
try {
var result = await NetUtil.post('/api/v1/new/config.json', method: NetMethod.GET, cache: true);
if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
return result[GlobalConfig.HTTP_RESPONSE_KEY_DATA];
}
} catch (e, s) {
Logger.error(e, s);
}
return null;
}

/// 获取缓存数据
Future<dynamic> fetchCacheData() async {
try {
var result = await NetUtil.getRequestCachedData('/api/v1/new/config.json');
if (!EmptyUtil.isEmpty(result)) {
return result;
}
} catch (e, s) {
Logger.error(e, s);
}
return null;
}

///
/// 校验底部导航栏是否更新
///
/// 校验的规则:使用 bottom_nav 的 mod_id + mod_pid + template_id + data 进行MD5
/// ⚠️ 由于Register初始化/api/v1/new/config.json没有进行缓存,可以利用这规则,如果Register的init进行了接口缓存则需要修改逻辑
///
/// false: 不更新 true 更新
///
Future<bool> validateBottomNavUpdate() async {
bool rlt = false;
try {
var cacheData = await fetchCacheData();
var netData = await fetchNetData();
if (!EmptyUtil.isEmpty(netData) && !EmptyUtil.isEmpty(cacheData)) {
var netBottomNav = netData['bottom_nav'];
var cacheBottomNav = cacheData['bottom_nav'];
if (!EmptyUtil.isEmpty(netBottomNav) && !EmptyUtil.isEmpty(cacheBottomNav)) {
var netEncodeStr = new StringBuffer();
var cacheEncodeStr = new StringBuffer();
netEncodeStr..write(netBottomNav['mod_id'])..write('-')..write(netBottomNav['mod_pid'])..write('-')..write(netBottomNav['template_id'])..write(netBottomNav['data']);
cacheEncodeStr..write(cacheBottomNav['mod_id'])..write('-')..write(cacheBottomNav['mod_pid'])..write('-')..write(cacheBottomNav['template_id'])..write(cacheBottomNav['data']);
String netMD5 = EncodeUtil.generateMd5(netEncodeStr.toString());
String cacheMD5 = EncodeUtil.generateMd5(cacheEncodeStr.toString());
Logger.log('网络数据的MD5 = ${netMD5}, 本地数据的MD5 = ${cacheMD5}');
rlt = (netMD5 != cacheMD5);
}
}
} catch (e, s) {
Logger.error(e, s);
}
return rlt;
}
}

+ 14
- 0
lib/pages/custom_page/bloc/custom_item_page_bloc.dart View File

@@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';


import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:zhiying_base_widget/pages/custom_page/bloc/bottom_nav_repository.dart';
import 'package:zhiying_base_widget/pages/custom_page/bloc/custom_item_page_repository.dart'; import 'package:zhiying_base_widget/pages/custom_page/bloc/custom_item_page_repository.dart';
import 'custom_item_page_state.dart'; import 'custom_item_page_state.dart';
import 'custom_item_page_event.dart'; import 'custom_item_page_event.dart';
@@ -12,6 +13,7 @@ class CustomItemPageBloc extends Bloc<CustomItemPageEvent, CustomItemPageState>
CustomItemPageRepository repository; CustomItemPageRepository repository;


CustomItemPageBloc(this.repository) : super(CustomItemPageInitial()); CustomItemPageBloc(this.repository) : super(CustomItemPageInitial());
BottomNavRepository _bottomNavRepository = new BottomNavRepository();






@@ -47,6 +49,12 @@ class CustomItemPageBloc extends Bloc<CustomItemPageEvent, CustomItemPageState>
} else { } else {
yield CustomItemPageInitErrorState(); yield CustomItemPageInitErrorState();
} }
// 检查校验是否需要重启App(底部模版问题)
bool needRestart = await _bottomNavRepository.validateBottomNavUpdate();
Logger.log('init 是否重新启动App = ${needRestart}');
if (needRestart) {
yield CustomItemPageAppRestartState();
}
} }


/// 下拉刷新 /// 下拉刷新
@@ -59,6 +67,12 @@ class CustomItemPageBloc extends Bloc<CustomItemPageEvent, CustomItemPageState>
yield CustomItemPageRefreshErrorState(); yield CustomItemPageRefreshErrorState();
yield CustomItemPageErrorState(); yield CustomItemPageErrorState();
} }
// 检查校验是否需要重启App(底部模版问题)
bool needRestart = await _bottomNavRepository.validateBottomNavUpdate();
Logger.log('refresh 是否重新启动App = ${needRestart}');
if (needRestart) {
yield CustomItemPageAppRestartState();
}
} }


/// 上拉更多 /// 上拉更多


+ 1
- 6
lib/pages/custom_page/bloc/custom_item_page_repository.dart View File

@@ -1,6 +1,6 @@
import 'dart:async'; import 'dart:async';


import 'package:zhiying_base_widget/pages/custom_page/event/reload_event.dart';
import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:zhiying_comm/zhiying_comm.dart';


class CustomItemPageRepository { class CustomItemPageRepository {
@@ -21,13 +21,8 @@ class CustomItemPageRepository {
List mobList = List mobList =
!EmptyUtil.isEmpty(data) ? List.from(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA][tabIndex.toString()]) : List.from(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); !EmptyUtil.isEmpty(data) ? List.from(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA][tabIndex.toString()]) : List.from(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]);
if (!EmptyUtil.isEmpty(mobList)) { if (!EmptyUtil.isEmpty(mobList)) {
ReloadEvent.com = 0;
return mobList.map((e) => Map<String, dynamic>.from(e)).toList(); return mobList.map((e) => Map<String, dynamic>.from(e)).toList();
} }
} else {
Timer(Duration(milliseconds: 1000), () {
EventUtil.instance.fire(ReloadEvent());
});
} }
} }
} catch (e, s) { } catch (e, s) {


+ 3
- 0
lib/pages/custom_page/bloc/custom_item_page_state.dart View File

@@ -30,3 +30,6 @@ class CustomItemPageLoadErrorState extends CustomItemPageState {}


/// 其他错误 /// 其他错误
class CustomItemPageErrorState extends CustomItemPageState {} class CustomItemPageErrorState extends CustomItemPageState {}

/// 需要重新渲染App,更新底部导航模版
class CustomItemPageAppRestartState extends CustomItemPageState {}

+ 0
- 8
lib/pages/custom_page/bloc/custom_page_repository.dart View File

@@ -1,8 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';


import 'package:zhiying_base_widget/dialog/loading/loading.dart';
import 'package:zhiying_base_widget/pages/custom_page/event/reload_event.dart';
import 'package:zhiying_base_widget/pages/main_page/model/background_model.dart'; import 'package:zhiying_base_widget/pages/main_page/model/background_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:zhiying_comm/zhiying_comm.dart';


@@ -40,12 +38,6 @@ class CustomPageRepository {
} }
return customPageData; return customPageData;
} }
}else{

Timer(Duration(milliseconds: 1000), (){
EventUtil.instance.fire(ReloadEvent());
});

} }
} }
} catch (e, s) { } catch (e, s) {


+ 10
- 0
lib/pages/custom_page/custom_item_page.dart View File

@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:event_bus/event_bus.dart'; import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart';
@@ -12,6 +14,7 @@ import 'bloc/custom_item_page_bloc.dart';
import 'bloc/custom_item_page_state.dart'; import 'bloc/custom_item_page_state.dart';
import 'bloc/custom_item_page_event.dart'; import 'bloc/custom_item_page_event.dart';
import 'bloc/custom_item_page_repository.dart'; import 'bloc/custom_item_page_repository.dart';
import 'package:zhiying_base_widget/pages/custom_page/event/reload_event.dart';


/// ///
/// 通用模块的分类导航下的子模块 /// 通用模块的分类导航下的子模块
@@ -131,9 +134,16 @@ class __CustomItemPageContainerState extends State<_CustomItemPageContainer> wit
if (current is CustomItemPageErrorState) { if (current is CustomItemPageErrorState) {
return false; return false;
} }
if (current is CustomItemPageAppRestartState) {
// 重启App
Logger.log('开始重新启动App CustomItemPageAppRestartState');
EventUtil.instance.fire(ReloadEvent());
return false;
}
return true; return true;
}, },
builder: (context, state) { builder: (context, state) {
Logger.log('Custom item page builder 刷新了');
if (state is CustomItemPageLoadedState) { if (state is CustomItemPageLoadedState) {
Logger.log('custom item page current state = ' + state?.toString()); Logger.log('custom item page current state = ' + state?.toString());
if (EmptyUtil.isEmpty(state.model)) if (EmptyUtil.isEmpty(state.model))


+ 1
- 1
lib/widgets/goods_details/store/bloc/store_state.dart View File

@@ -17,7 +17,7 @@ class StoreLoadedState extends StoreState {
const StoreLoadedState({this.model}); const StoreLoadedState({this.model});


@override @override
List<Object> get props => [];
List<Object> get props => [this.model];
} }


/// 数据加载出错 /// 数据加载出错


+ 2
- 1
lib/widgets/mine/mine_data/mine_data_widget.dart View File

@@ -7,6 +7,7 @@ import 'package:zhiying_base_widget/widgets/mine/mine_data/model/mine_data_model
import 'package:zhiying_base_widget/widgets/mine/mine_header/model/mine_profile_model.dart'; import 'package:zhiying_base_widget/widgets/mine/mine_header/model/mine_profile_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:zhiying_comm/util/shared_prefe_util.dart'; import 'package:zhiying_comm/util/shared_prefe_util.dart';
import 'package:zhiying_comm/zhiying_comm.dart';


class MineDataWidget extends StatefulWidget { class MineDataWidget extends StatefulWidget {
final Map<String, dynamic> data; final Map<String, dynamic> data;
@@ -118,7 +119,7 @@ class _MineDataWidgetState extends State<MineDataWidget> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Text( Text(
_isiOSReview ? '' : widget?.profile?.gridViews[0]?.name ?? "累计收益",
_isiOSReview ? '' : EmptyUtil.isEmpty(widget?.profile?.gridViews) ? "累计收益" : widget?.profile?.gridViews[0]?.name ?? '累计收益',
style: TextStyle( style: TextStyle(
fontSize: 11, fontSize: 11,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,


+ 2
- 2
lib/widgets/mine/mine_header/mine_header_container.dart View File

@@ -147,11 +147,11 @@ class _MineHeaderContainerState extends State<MineHeaderContainer> {
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
Text( Text(
'邀请码:${profile.inviteCode}',
'邀请码:${profile?.inviteCode ?? ''}',
maxLines: 1, maxLines: 1,
style: TextStyle( style: TextStyle(
fontSize: 13, fontSize: 13,
color: HexColor.fromHex(widget.staticModel.userNameColor),
color: HexColor.fromHex(widget?.staticModel?.userNameColor),
fontFamily: 'Din', fontFamily: 'Din',
package: 'zhiying_comm', package: 'zhiying_comm',
), ),


+ 8
- 8
lib/widgets/restart_widget/restart_widget.dart View File

@@ -21,7 +21,7 @@ class RestartWidget extends StatefulWidget {
class _RestartWidgetState extends State<RestartWidget> { class _RestartWidgetState extends State<RestartWidget> {
bool reStart = false; bool reStart = false;


int com = 0;
// int com = 0;
Timer timer1; Timer timer1;
Timer timer2; Timer timer2;


@@ -37,15 +37,15 @@ class _RestartWidgetState extends State<RestartWidget> {
return; return;
} }


com++;
// com++;


///刷新3次后不再刷新 ///刷新3次后不再刷新
if (com > 3) {
if (com < 7) {
Fluttertoast.showToast(msg: "网络服务不可用");
}
return;
}
// if (com > 3) {
// if (com < 7) {
// Fluttertoast.showToast(msg: "网络服务不可用");
// }
// return;
// }


Loading.show(context, msg: "更新数据中..."); Loading.show(context, msg: "更新数据中...");




Loading…
Cancel
Save