import 'package:common_project/common_project.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:module_chat/chat_room_init.dart'; import 'package:module_home/home_init.dart'; import 'package:module_login/login_init.dart'; import 'package:module_me/me_init.dart'; import 'package:module_im/im_init.dart'; class MainInit{ // static Future init() async{ WidgetsFlutterBinding.ensureInitialized(); // Bloc.observer = SimpleBlocObserver(); //本地存储初始化 await SpUtil.getInstance(); //微信登录初始化 // ThirdUtil.configureWeixin(); StorageManager.manager(); } /*全局路由初始化*/ static void routerInit(){ MainRouterInit.initRouter(); LoginInit.init(); ChatInit.init(); HomeInit.init(); MeInit.init(); ImInit.init(); CommonProjectModule.init(); getDeviceInfo(); setChatRoomAnimationLock(); } //融云初始化 static void rongrunInit(){ CommonProjectModule.rongRunInit(); } //网络初始化 static Future requestInit() async { List interceptors = []; /// 统一添加身份验证请求头 // interceptors.add(AuthInterceptor()); /// 加加密验证 // interceptors.add(AdapterSecretEncryptInterceptor()); // interceptors.add(AdapterSecretDecryptInterceptor()); /// 刷新Token // interceptors.add(TokenInterceptor()); /// 缓存 // interceptors.add(DioCacheManager( // CacheConfig( // baseUrl: AppConfig.APP_BASE_URL, // databaseName: "app", // )).interceptor); /// 打印Log(生产模式去除) if (!CommonUtil.inProduction) { // interceptors.add(LoggingInterceptor()); } ApiUtil.InitBaseRequest( baseUrl: AppConfig.APP_BASE_URL, connectTimeout: AppConfig.CONNECT_TIMEOUT, receiveTimeout: AppConfig.RECEIVE_TIMEOUT, interceptors: interceptors, ); ApiUtil.instance; } //获取版本号 static getDeviceInfo() async { PackageInfo info = await PackageInfo.fromPlatform(); SpUtil.putString(SPKeys.version, info.version); } static setChatRoomAnimationLock() { bool? isLock = StorageManager.instance.read(key: SPKeys.lockChatRoomAnimation); if (isLock == null){ StorageManager.instance.write(key: SPKeys.lockChatRoomAnimation, value: false); } } /*全局bloc配置*/ static Widget getGlobalBloc(Widget child){ return MultiBlocProvider( providers: [ BlocProvider( create: (context) => TabIndexCubit() ), BlocProvider( create: (context) => LayoutCubit() ), BlocProvider( create: (context) => ConfigCubit() ), BlocProvider( create: (context) => AuthenticationCubit() ), BlocProvider(create: (context) => GloableChatRoomCubit() ), ], child:child); } }