diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 3020b6f..5ea6c35 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -53,8 +53,8 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" ndk { //选择要添加的对应cpu类型的.so库。 - abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a' - //abiFilters 'armeabi-v7a','x86_64' + abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a' + // abiFilters 'armeabi-v7a','x86_64' } } @@ -113,9 +113,9 @@ android { // // 智夜生活 // zhiying { // applicationId "cn.zhios.zhiying" -// versionCode 53 +// versionCode 55 // dimension "app" -// versionName '1.3.13' +// versionName '1.3.15' // // 签名信息 // signingConfig signingConfigs.zhiying // } diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 185f6b5..cb59de2 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -429,7 +429,7 @@ SPEC CHECKSUMS: flutter_webview_plugin: ed9e8a6a96baf0c867e90e1bce2673913eeac694 flutter_xupdate: bdb588f0fe4f6c5e45436b8b0de08d505a50c04e fluttertoast: b644586ef3b16f67fae9a1f8754cef6b2d6b634b - fluwx: 07a55ed66bf3a4961e836a2a411b02dcada32902 + fluwx: 8d47bee15c7fed07b94c2a12fb2381677232431a FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a image_cropper: 3c16d7651730ffe85897f5a1c4e2547e6b54989a image_picker: 9c3312491f862b28d21ecd8fdf0ee14e601b3f09 diff --git a/example/lib/main.dart b/example/lib/main.dart index 388367a..9b6d622 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -22,6 +22,7 @@ import 'package:zhiying_moments/register.dart'; import 'package:zhiying_member_upgrade/register.dart'; import 'package:zhiying_equity_card/zhiying_equity_card.dart'; import 'package:zhiying_official/register.dart'; +import 'package:zhiying_base_widget/zhiying_base_widget.dart'; void main() { FlutterError.onError = (FlutterErrorDetails details) { @@ -38,21 +39,16 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State { - Widget getErrorWidget(BuildContext context, FlutterErrorDetails error) { - var erroStr=''; + var erroStr = ''; const bool inProduction = const bool.fromEnvironment("dart.vm.product"); - if ( !inProduction) { - erroStr=error.exceptionAsString(); + if (!inProduction) { + erroStr = error.exceptionAsString(); } return Center( child: Text( - ""+erroStr, - style: Theme - .of(context) - .textTheme - .title - .copyWith(color: Colors.grey[200]), + "" + erroStr, + style: Theme.of(context).textTheme.title.copyWith(color: Colors.grey[200]), ), ); } @@ -75,12 +71,12 @@ class _MyAppState extends State { }); MobPushUtil.setCanPush(); + EventUtil.instance.on().listen((event) {}); // app更新插件 AppUpdateUtil.initXUpdate(); } - @override Widget build(BuildContext context) { ErrorWidget.builder = (FlutterErrorDetails errorDetails) { @@ -91,15 +87,15 @@ class _MyAppState extends State { ChangeNotifierProvider.value(value: UserInfoNotifier()), ], child: GestureDetector( - onTap: (){ + onTap: () { FocusScopeNode currentFocus = FocusScope.of(context); if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) { FocusManager.instance.primaryFocus.unfocus(); } }, child: MaterialApp( - builder: (context,child){ - return MediaQuery( + builder: (context, child) { + return MediaQuery( //设置文字大小不随系统设置改变 data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), child: child, @@ -111,7 +107,7 @@ class _MyAppState extends State { accentColor: HexColor.fromHex('#FF4242'), ), routes: { - '/homePage': (BuildContext context) => HomePage(), + '/homePage': (BuildContext context) => HomeCenterPage(), }, navigatorKey: navigatorKey, localizationsDelegates: [ @@ -129,8 +125,8 @@ class _MyAppState extends State { return locale; }, home: LaunchPage( - // builder: (context) => HomePage(), - ), + // builder: (context) => HomePage(), + ), ), ), ); @@ -140,4 +136,4 @@ class _MyAppState extends State { // FocusScopeNode currentFocus = FocusScope.of(context); // if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) { // FocusManager.instance.primaryFocus.unfocus(); -// } \ No newline at end of file +// } diff --git a/lib/pages/custom_page/bloc/custom_item_page_repository.dart b/lib/pages/custom_page/bloc/custom_item_page_repository.dart index 43d241d..1dc43d5 100644 --- a/lib/pages/custom_page/bloc/custom_item_page_repository.dart +++ b/lib/pages/custom_page/bloc/custom_item_page_repository.dart @@ -1,3 +1,6 @@ +import 'dart:async'; + +import 'package:zhiying_base_widget/pages/custom_page/event/reload_event.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; class CustomItemPageRepository { @@ -15,10 +18,16 @@ class CustomItemPageRepository { if (!EmptyUtil.isEmpty(reqUrl)) { var result = await NetUtil.post(reqUrl, method: NetMethod.GET, cache: true); if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { - List mobList = !EmptyUtil.isEmpty(data) ? List.from(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA][tabIndex.toString()]) : List.from(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); + List mobList = + !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)) { + ReloadEvent.com = 0; return mobList.map((e) => Map.from(e)).toList(); } + } else { + Timer(Duration(milliseconds: 1000), () { + EventUtil.instance.fire(ReloadEvent()); + }); } } } catch (e, s) { diff --git a/lib/pages/custom_page/bloc/custom_page_repository.dart b/lib/pages/custom_page/bloc/custom_page_repository.dart index 83cd9a4..8eff7a1 100644 --- a/lib/pages/custom_page/bloc/custom_page_repository.dart +++ b/lib/pages/custom_page/bloc/custom_page_repository.dart @@ -1,5 +1,8 @@ +import 'dart:async'; 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_comm/zhiying_comm.dart'; @@ -37,6 +40,12 @@ class CustomPageRepository { } return customPageData; } + }else{ + + Timer(Duration(milliseconds: 1000), (){ + EventUtil.instance.fire(ReloadEvent()); + }); + } } } catch (e, s) { diff --git a/lib/pages/custom_page/custom_item_page.dart b/lib/pages/custom_page/custom_item_page.dart index df6db39..fe12c86 100644 --- a/lib/pages/custom_page/custom_item_page.dart +++ b/lib/pages/custom_page/custom_item_page.dart @@ -92,7 +92,6 @@ class __CustomItemPageContainerState extends State<_CustomItemPageContainer> wit _eventBus = EventBus(); _refreshController = RefreshController(initialRefresh: false); _initEvent();_controller.addListener(() { - print(_controller.offset.toString()); if(widget.scroller!=null){ widget?.scroller(_controller.offset); } diff --git a/lib/pages/custom_page/custom_page.dart b/lib/pages/custom_page/custom_page.dart index 454a00e..8e8c075 100644 --- a/lib/pages/custom_page/custom_page.dart +++ b/lib/pages/custom_page/custom_page.dart @@ -60,7 +60,7 @@ class _CommonPageContainer extends StatefulWidget { __CommonPageContainerState createState() => __CommonPageContainerState(); } -class __CommonPageContainerState extends State<_CommonPageContainer> with SingleTickerProviderStateMixin ,AutomaticKeepAliveClientMixin{ +class __CommonPageContainerState extends State<_CommonPageContainer> with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin { TabController _tabController; // 是否有AppBar @@ -80,7 +80,7 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single @override void initState() { - backgroundBloc=BackgroundBloc(); + backgroundBloc = BackgroundBloc(); super.initState(); } @@ -94,40 +94,38 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single @override Widget build(BuildContext context) { SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark); - return MediaQuery.removePadding( - context: context, - child: BlocConsumer( - listener: (context, state) {}, - buildWhen: (prev, current) { - if (current is CustomPageErrorState) { - return false; - } - if (current is CustomPageRefreshSuccessState) { - // _refreshController.refreshCompleted(resetFooterState: true); - return false; - } - if (current is CustomPageRefreshErrorState) { - // _refreshController.refreshFailed(); - return false; - } - return true; - }, - builder: (context, state) { - /// 有数据 - if (state is CustomPageLoadedState) { - if (EmptyUtil.isEmpty(state.model)) return _buildEmptyWidget(); - return _buildMainWidget(state.model, state.backgroundModel); - } - - /// 初始化失败 - if (state is CustomPageInitErrorState) { - return _buildEmptyWidget(); - } - - /// 骨架图 - return _buildSkeletonWidget(); - }, - ), + return BlocConsumer( + listener: (context, state) {}, + buildWhen: (prev, current) { + if (current is CustomPageErrorState) { + return false; + } + if (current is CustomPageRefreshSuccessState) { + // _refreshController.refreshCompleted(resetFooterState: true); + return false; + } + if (current is CustomPageRefreshErrorState) { + // _refreshController.refreshFailed(); + return false; + } + return true; + }, + builder: (context, state) { + /// 有数据 + if (state is CustomPageLoadedState) { + if (EmptyUtil.isEmpty(state.model)) return _buildEmptyWidget(); + Logger.log("通用模板数据", state.model); + return _buildMainWidget(state.model, state.backgroundModel); + } + + /// 初始化失败 + if (state is CustomPageInitErrorState) { + return _buildEmptyWidget(); + } + + /// 骨架图 + return _buildSkeletonWidget(); + }, ); } @@ -271,7 +269,11 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single onPressed: () => Navigator.maybePop(context), ), title: Text( - null != data && data.containsKey('app_bar_name') ? data['app_bar_name'] != '自定义页面' ? data['app_bar_name'] : parentTitle : parentTitle, + null != data && data.containsKey('app_bar_name') + ? data['app_bar_name'] != '自定义页面' + ? data['app_bar_name'] + : parentTitle + : parentTitle, style: TextStyle( color: HexColor.fromHex(null != data ? data['app_bar_name_color'] ?? '#333333' : '#333333'), fontSize: 16, @@ -370,16 +372,15 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single return result; } - _buildBackground(BackgroundModel backgroundModel) { if (backgroundModel != null) { var headerBg = backgroundModel.headerBg; return StreamBuilder( stream: backgroundBloc.outData, - builder: (context,asncy){ - return Container( + builder: (context, asncy) { + return Container( constraints: BoxConstraints(minHeight: 0), - height: (double.tryParse(headerBg?.height)??0)+backgroundTopMargin ?? 0, + height: (double.tryParse(headerBg?.height) ?? 0) + backgroundTopMargin ?? 0, width: double.infinity, decoration: BoxDecoration( gradient: LinearGradient( @@ -389,7 +390,6 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single ); }, ); - } else { return Container(); } @@ -423,7 +423,7 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single @override // TODO: implement wantKeepAlive - bool get wantKeepAlive =>true; + bool get wantKeepAlive => true; } /// 回到顶部的icon diff --git a/lib/pages/custom_page/event/reload_event.dart b/lib/pages/custom_page/event/reload_event.dart new file mode 100644 index 0000000..344c4dd --- /dev/null +++ b/lib/pages/custom_page/event/reload_event.dart @@ -0,0 +1,12 @@ +// +import 'dart:async'; + +class ReloadEvent { + static int com = 0; + final String id; + + ReloadEvent({this.id}) { + com++; + } + +} diff --git a/lib/pages/home_page/home_page.dart b/lib/pages/home_page/home_page.dart index 859cfac..a463313 100644 --- a/lib/pages/home_page/home_page.dart +++ b/lib/pages/home_page/home_page.dart @@ -22,8 +22,10 @@ import 'package:zhiying_base_widget/dialog/global_dialog/notification_setting_di import 'package:zhiying_base_widget/dialog/global_dialog/policy_dialog/policy_dialog.dart'; import 'package:zhiying_base_widget/dialog/tip_dialog/tip_dialog.dart'; import 'package:zhiying_base_widget/models/app_config_model.dart'; +import 'package:zhiying_base_widget/pages/custom_page/event/reload_event.dart'; import 'package:zhiying_base_widget/utils/contants.dart'; import 'package:zhiying_base_widget/utils/mob_push_util.dart'; +import 'package:zhiying_base_widget/widgets/restart_widget/restart_widget.dart'; import 'package:zhiying_comm/models/base/base_tab_model.dart'; import 'package:zhiying_comm/util/image_util.dart'; import 'package:zhiying_comm/util/mob_util/mob_util.dart'; @@ -39,6 +41,18 @@ import 'package:zhiying_comm/util/event_util/event_util.dart'; import 'package:zhiying_comm/util/event_util/log_out.dart'; import 'package:package_info/package_info.dart'; +class HomeCenterPage extends StatefulWidget { + @override + _HomeCenterPageState createState() => _HomeCenterPageState(); +} + +class _HomeCenterPageState extends State { + @override + Widget build(BuildContext context) { + return RestartWidget(child: HomePage()); + } +} + class HomePage extends StatefulWidget { HomePage({Key key}) : super(key: key); @@ -52,21 +66,33 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker static const EventChannel _eventChannel = const EventChannel('JAVA_TO_FLUTTER'); StreamSubscription streamSubscription; + StreamSubscription reloadSubscription; + StreamSubscription aliasSubscription; + StreamSubscription logOutSubscription; + StreamSubscription loginSubscription; + + StreamSubscription eventChannelSubscription; + @override void initState() { ///初始化一些数据 initAsync(); //如果登出则重新打开首页 - streamSubscription = EventUtil.instance.on().listen((event) async{ - UserInfoModel user = - await Provider.of(context, listen: false) - .getUserInfoModel(); - user.token=''; + streamSubscription = EventUtil.instance.on().listen((event) async { + UserInfoModel user = await Provider.of(context, listen: false).getUserInfoModel(); + user.token = ''; Navigator.maybePop(context); + print("重启1"); Navigator.pushReplacementNamed(context, "/homePage"); }); + reloadSubscription = EventUtil.instance.on().listen((event) async { + print("重启2"); + await BaseSettingModel.init(isGetCache: false); + RestartWidget.restartApp(context); + }); + super.initState(); } @@ -82,16 +108,9 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker NativeUtil.notifyInitSuccess(); }); }); - String data = BaseSettingModel.setting.tab['data']; - try { - List list = convert.jsonDecode(data); - _data = list.map((item) { - return Map.from(item); - }).toList(); - Logger.debug(_data); - } catch (error) { - Logger.error(error); - } + + initBaseSet(); + Constants.isShowIntellectDialog = false; TaobaoAuth.initAuth(context); @@ -108,10 +127,10 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker //app后台杀死时候的还原 Moblink.restoreScene(_restore); // 监听开始(传递监听到原生端,用户监听场景还原的数据回传回来) - _eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); + eventChannelSubscription= _eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); MobPushUtil.addPushReceiver(); - EventUtil.instance.on().listen((event) async { + aliasSubscription = EventUtil.instance.on().listen((event) async { UserInfoModel userInfo = UserInfoNotifier?.staitcUserInfo; var setting = await NativeUtil.getSetting(); String masterId = setting['master_id']; @@ -121,12 +140,12 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker } }); - EventUtil.instance.on().listen((event) { + logOutSubscription = EventUtil.instance.on().listen((event) { MobPushUtil.deleteAlias(); }); - super.initState(); + MobPushUtil.addPushReceiver(); - EventUtil.instance.on().listen((event) async { + loginSubscription = EventUtil.instance.on().listen((event) async { UserInfoModel userInfo = UserInfoNotifier?.staitcUserInfo; var setting = await NativeUtil.getSetting(); String masterId = setting['master_id']; @@ -136,19 +155,36 @@ class _HomePageState extends State with WidgetsBindingObserver, Ticker } }); - EventUtil.instance.on().listen((event) { - MobPushUtil.deleteAlias(); - }); + } catch (e, s) { print(e); print(s); } + + } + + initBaseSet() { + String data = BaseSettingModel.setting.tab['data']; + try { + List list = convert.jsonDecode(data); + _data = list.map((item) { + return Map.from(item); + }).toList(); + Logger.debug(_data); + } catch (error) { + Logger.error(error); + } } @override void dispose() { WidgetsBinding.instance.removeObserver(this); streamSubscription.cancel(); + reloadSubscription?.cancel(); + aliasSubscription?.cancel(); + logOutSubscription?.cancel(); + loginSubscription?.cancel(); + eventChannelSubscription?.cancel(); super.dispose(); } diff --git a/lib/pages/launch_page/launch_page.dart b/lib/pages/launch_page/launch_page.dart index 21c38c6..eb58166 100644 --- a/lib/pages/launch_page/launch_page.dart +++ b/lib/pages/launch_page/launch_page.dart @@ -40,14 +40,12 @@ class LaunchPage extends StatefulWidget { class _LaunchPageState extends State with TickerProviderStateMixin { final GlobalKey navigatorKey = new GlobalKey(); - ///闪屏动画 - AnimationController animationController; int showTime = 0; @override void initState() { - animationController = AnimationController(vsync: this); + validateInit(); super.initState(); } diff --git a/lib/pages/security_page/security_password/security_password.dart b/lib/pages/security_page/security_password/security_password.dart index 0fee690..d02d79b 100644 --- a/lib/pages/security_page/security_password/security_password.dart +++ b/lib/pages/security_page/security_password/security_password.dart @@ -30,6 +30,8 @@ class _SecurityPasswordState extends State { bool _canConfirm = false; String _phone; + Timer timer; + @override void initState() { Logger.debug(widget.model.toString()); @@ -143,9 +145,7 @@ class _SecurityPasswordState extends State { } void _verifiy() { - bool canConfirm = _passwordController.text.length >= 6 && - _confirmController.text.length >= 6 && - _codeController.text.length == 6; + bool canConfirm = _passwordController.text.length >= 6 && _confirmController.text.length >= 6 && _codeController.text.length == 6; if (canConfirm != _canConfirm) { setState(() { _canConfirm = canConfirm; @@ -153,20 +153,26 @@ class _SecurityPasswordState extends State { } } + @override + void dispose() { + timer?.cancel(); + super.dispose(); + } + /// 获取验证码 void _sendCode() async { - bool result = await MobUtil.getTextCode(_phone, smsCodeType: SMSCodeType.NORMAL); - if(result){ + bool result = await MobUtil.getTextCode(_phone, smsCodeType: SMSCodeType.NORMAL); + if (result) { Fluttertoast.showToast(msg: '发送成功'); _second = 60; - Timer.periodic(Duration(seconds: 1), (timer) { + timer = Timer.periodic(Duration(seconds: 1), (timer) { _second--; if (_second <= 0) { timer.cancel(); } setState(() {}); }); - }else{ + } else { // Fluttertoast.showToast(msg: '获取验证码失败'); } @@ -187,13 +193,8 @@ class _SecurityPasswordState extends State { void _confirm() async { NetUtil.request('/api/v1/settings/account/security/password', - params: Map.from({ - 'new_password': _passwordController.text, - 'new_password_ack': _confirmController.text, - 'valid_code': _codeController.text, - 'phone': _phone, - 'zone': '86' - }), + params: Map.from( + {'new_password': _passwordController.text, 'new_password_ack': _confirmController.text, 'valid_code': _codeController.text, 'phone': _phone, 'zone': '86'}), method: NetMethod.POST, onSuccess: (result) { Logger.debug(result); Fluttertoast.showToast(msg: '设置成功'); diff --git a/lib/widgets/custom/multi_nav/custom_quick_entry.dart b/lib/widgets/custom/multi_nav/custom_quick_entry.dart index fb37600..7a2690b 100644 --- a/lib/widgets/custom/multi_nav/custom_quick_entry.dart +++ b/lib/widgets/custom/multi_nav/custom_quick_entry.dart @@ -605,7 +605,7 @@ class CustomQuickCateEntry extends StatefulWidget { class _CustomQuickCateEntryState extends State with TickerProviderStateMixin, AutomaticKeepAliveClientMixin { TabController tabController; - PrimaryPageController primaryPageController; + bool isOnTap = false; @@ -617,32 +617,22 @@ class _CustomQuickCateEntryState extends State with Ticker @override void initState() { - // primaryPageController = PrimaryPageController(keepPage: true); + if (widget?.model != null) { tabController = TabController(length: widget?.model?.typeList?.length ?? 0, vsync: this); tabController.addListener(() {}); } _controller = SwiperController(); - // primaryPageController.addListener(() { - // if (isOnTap) { - // return; - // } - // if ((primaryPageController.page - tabController.index).abs() > 0.9) { - // tabController.animateTo(primaryPageController.page.floor()); - // } - // }); + super.initState(); } @override void dispose() { tabController?.dispose(); - primaryPageController?.dispose(); - for (var item in widget.model?.typeList) { - item.primaryPageController?.dispose(); - item.primaryPageController = null; - } + + _controller?.dispose(); super.dispose(); } @@ -665,9 +655,7 @@ class _CustomQuickCateEntryState extends State with Ticker if (model.typeList != null) { for (var item in model?.typeList) { item.listStyle = List(); - if (item.primaryPageController == null) { - item.primaryPageController = PrimaryPageController(keepPage: true); - } + for (var listItem in model?.listStyle) { if (listItem?.typeListKey == item.key) { item.listStyle.add(listItem); @@ -975,7 +963,7 @@ class _CustomQuickCateEntryState extends State with Ticker // 当前元素的下表 = 当前的列数 + 当前的行数 * 列数 + 当前的页数 * 当前的行数 + 当前的列数 int currentIndex = currentColum + currentRow * columSize; - print("当前页" + currentPage.toString() + "当前点" + currentIndex.toString()); + //print("当前页" + currentPage.toString() + "当前点" + currentIndex.toString()); // print('current Index sss = $currentIndex'); diff --git a/lib/widgets/custom/notice/custom_notice_widget.dart b/lib/widgets/custom/notice/custom_notice_widget.dart index 2e2ddd8..140acc1 100644 --- a/lib/widgets/custom/notice/custom_notice_widget.dart +++ b/lib/widgets/custom/notice/custom_notice_widget.dart @@ -18,7 +18,9 @@ class CustomNoticeWidget extends StatelessWidget { @override Widget build(BuildContext context) { return BlocProvider( - create: (_) => CustomNoticeBloc(repository: CustomNoticeRepository())..add(CustomNoticeInitEvent(model: model)), + create: (_) => + CustomNoticeBloc(repository: CustomNoticeRepository()) + ..add(CustomNoticeInitEvent(model: model)), child: _CustomNoticeWidgetContainer(), ); } @@ -79,9 +81,9 @@ class _CustomNoticeWidgetContainerState extends State<_CustomNoticeWidgetContain top: ParseUtil.stringParseDouble(model?.topMargin), left: ParseUtil.stringParseDouble(model?.leftRightMargin), right: ParseUtil.stringParseDouble(model?.leftRightMargin)), - padding: EdgeInsets.symmetric(horizontal:7.5, vertical: 7.5), + padding: EdgeInsets.symmetric(horizontal: 7.5, vertical: 7.5), child: Container( - decoration: BoxDecoration(borderRadius: BorderRadius.circular(7.5), color: HexColor.fromHex(model?.outsideBgColor??'#F6F6F6')), + decoration: BoxDecoration(borderRadius: BorderRadius.circular(7.5), color: HexColor.fromHex(model?.outsideBgColor ?? '#F6F6F6')), padding: const EdgeInsets.only(top: 8, bottom: 8, left: 12, right: 8), width: double.infinity, child: _getChildWidget(model), @@ -97,6 +99,7 @@ class _CustomNoticeWidgetContainerState extends State<_CustomNoticeWidgetContain behavior: HitTestBehavior.opaque, child: Row( children: [ + /// 图片 // Container(width: 52, height: 13, color: Colors.red), CachedNetworkImage( @@ -114,7 +117,7 @@ class _CustomNoticeWidgetContainerState extends State<_CustomNoticeWidgetContain // color: Colors.yellowAccent, child: MarqueeWidget( model?.listStyle?.length ?? 0, - (BuildContext context, int index) { + (BuildContext context, int index) { NoticeListStyle item = model.listStyle[index]; return Align(alignment: Alignment.centerLeft, child: Text('${item?.contentText}', style: TextStyle(color: HexColor.fromHex(model?.textColor), fontSize: 12))); }, @@ -161,10 +164,14 @@ class _MarqueeWidgetState extends State { _controller = PageController(); _timer = Timer.periodic(Duration(seconds: 5), (timer) { // 如果当前位于最后一页,则直接跳转到第一页,两者内容相同,跳转时视觉上无感知 - if (_controller.page.round() >= widget.count) { - _controller.jumpToPage(0); + try { + if (_controller.page.round() >= widget.count) { + _controller.jumpToPage(0); + } + _controller.nextPage(duration: Duration(seconds: 1), curve: Curves.linear); + } catch (e){ + _timer?.cancel(); } - _controller.nextPage(duration: Duration(seconds: 1), curve: Curves.linear); }); } } diff --git a/lib/widgets/custom/slide_banner/custom_slide_banner.dart b/lib/widgets/custom/slide_banner/custom_slide_banner.dart index d66d587..edd097e 100644 --- a/lib/widgets/custom/slide_banner/custom_slide_banner.dart +++ b/lib/widgets/custom/slide_banner/custom_slide_banner.dart @@ -56,6 +56,7 @@ class _CustomSlideBannerContainerState extends State @override void dispose() { + _swiperController.stopAutoplay(); _swiperController?.dispose(); super.dispose(); } diff --git a/lib/widgets/restart_widget/restart_widget.dart b/lib/widgets/restart_widget/restart_widget.dart new file mode 100644 index 0000000..26a6a92 --- /dev/null +++ b/lib/widgets/restart_widget/restart_widget.dart @@ -0,0 +1,91 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; +import 'package:zhiying_base_widget/dialog/loading/loading.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +class RestartWidget extends StatefulWidget { + RestartWidget({this.child}); + + final Widget child; + + static void restartApp(BuildContext context) { + //查找顶层_RestartWidgetState并重启 + context.findAncestorStateOfType<_RestartWidgetState>().restartApp(); + } + + @override + _RestartWidgetState createState() => _RestartWidgetState(); +} + +class _RestartWidgetState extends State { + bool reStart = false; + + int com = 0; + Timer timer1; + Timer timer2; + + StreamController streamController=StreamController(); + + Stream outData; + + bool isFirst=true; + + void restartApp() async { + + if (reStart) { + return; + } + + com++; + + ///刷新3次后不再刷新 + if (com > 3) { + if (com < 7) { + Fluttertoast.showToast(msg: "网络服务不可用"); + } + return; + } + + Loading.show(context, msg: "更新数据中..."); + + streamController.add(null); + + timer1 = Timer(Duration(milliseconds: 1000), () async { + print("重启"); + streamController.add("restart"); + }); + timer2 = Timer(Duration(milliseconds: 1500), () { + Loading.dismiss(); + }); + } + + @override + void initState() { + outData=streamController.stream; + super.initState(); + } + + @override + Widget build(BuildContext context) { + + return StreamBuilder(stream: outData,builder: (context,asyn){ + if(asyn.data==null&&!isFirst){ + return Scaffold( + body: Container(), + ); + }else{ + isFirst=false; + return widget?.child; + } + }); + + } + + @override + void dispose() { + timer1?.cancel(); + timer2?.cancel(); + super.dispose(); + } +} diff --git a/lib/zhiying_base_widget.dart b/lib/zhiying_base_widget.dart index 914effa..8a6ebd8 100644 --- a/lib/zhiying_base_widget.dart +++ b/lib/zhiying_base_widget.dart @@ -5,4 +5,5 @@ export 'package:flutter_swiper/flutter_swiper.dart'; export 'package:zhiying_base_widget/pages/main_page/model/background_model.dart'; export 'package:zhiying_base_widget/pages/custom_page/bloc/background_bloc.dart'; export 'package:pull_to_refresh/pull_to_refresh.dart'; -export 'package:flutter_user_agent/flutter_user_agent.dart'; \ No newline at end of file +export 'package:flutter_user_agent/flutter_user_agent.dart'; +export 'package:zhiying_base_widget/widgets/restart_widget/restart_widget.dart'; \ No newline at end of file