diff --git a/lib/main.dart b/lib/main.dart index 230e6391..17cb9941 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,14 +3,11 @@ import 'package:akuCommunity/provider/sign_up_provider.dart'; import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/utils/developer_util.dart'; import 'package:akuCommunity/utils/hive_store.dart'; -import 'package:amap_location_fluttify/amap_location_fluttify.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:fluwx/fluwx.dart'; import 'package:get/get.dart'; -import 'package:hive/hive.dart'; -import 'package:hive_flutter/hive_flutter.dart'; import 'package:provider/provider.dart'; import 'package:akuCommunity/provider/cart.dart'; import 'package:flutter_picker/flutter_picker.dart'; @@ -19,9 +16,6 @@ import 'package:flutter_localizations/flutter_localizations.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); - await Hive.initFlutter(); - await HiveStore.init(); - AmapLocation.instance.init(iosKey: 'ios key'); DeveloperUtil.setDev(true); runApp(MyApp()); } diff --git a/lib/pages/splash/splash_page.dart b/lib/pages/splash/splash_page.dart index 55ea2f10..3d0807a8 100644 --- a/lib/pages/splash/splash_page.dart +++ b/lib/pages/splash/splash_page.dart @@ -2,9 +2,12 @@ import 'package:akuCommunity/pages/tab_navigator.dart'; import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/utils/hive_store.dart'; import 'package:akuCommunity/utils/logger/logger_view.dart'; +import 'package:amap_location_fluttify/amap_location_fluttify.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:hive/hive.dart'; +import 'package:hive_flutter/hive_flutter.dart'; import 'package:provider/provider.dart'; import 'package:velocity_x/velocity_x.dart'; @@ -17,8 +20,21 @@ class SplashPage extends StatefulWidget { } class _SplashPageState extends State { + ///原生端耗时加载 + Future _originOp() async { + //初始化HiveStore + await Hive.initFlutter(); + await HiveStore.init(); + + //初始化AMap + AmapLocation.instance.init(iosKey: 'ios key'); + } + Future _initOp() async { + //ensure call _originOp first. + await _originOp(); final userProvider = Provider.of(context, listen: false); + //app init delay 2 second await Future.delayed(Duration(seconds: 2)); if (HiveStore.appBox.get('login') ?? false) { await userProvider.setLogin(HiveStore.appBox.get('token')); diff --git a/lib/utils/network/net_util.dart b/lib/utils/network/net_util.dart index f067f05d..fa8ce2f3 100644 --- a/lib/utils/network/net_util.dart +++ b/lib/utils/network/net_util.dart @@ -1,4 +1,5 @@ import 'package:akuCommunity/pages/sign/sign_in_page.dart'; +import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/utils/logger/logger_data.dart'; import 'package:akuCommunity/utils/network/base_list_model.dart'; import 'package:akuCommunity/utils/network/base_model.dart'; @@ -8,6 +9,7 @@ import 'package:dio/dio.dart'; import 'package:akuCommunity/constants/api.dart'; import 'package:get/get.dart' hide Response; import 'package:logger/logger.dart'; +import 'package:provider/provider.dart'; class NetUtil { Dio _dio; @@ -144,8 +146,10 @@ class NetUtil { } _parseRequestError(BaseModel model, {bool showMessage = false}) { - if (!model.status&&model.message=='登录失效,请登录'){ + final userProvider = Provider.of(Get.context, listen: false); + if (!model.status && model.message == '登录失效,请登录') { Get.offAll(SignInPage()); + userProvider.logout(); } if (!model.status || showMessage) { BotToast.showText(text: model.message);