init.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import 'package:common_project/common_project.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/scheduler.dart';
  4. import 'package:module_chat/chat_room_init.dart';
  5. import 'package:module_home/home_init.dart';
  6. import 'package:module_login/login_init.dart';
  7. import 'package:module_me/me_init.dart';
  8. import 'package:module_im/im_init.dart';
  9. class MainInit{
  10. //
  11. static Future<void> init() async{
  12. WidgetsFlutterBinding.ensureInitialized();
  13. // Bloc.observer = SimpleBlocObserver();
  14. //本地存储初始化
  15. await SpUtil.getInstance();
  16. //微信登录初始化
  17. // ThirdUtil.configureWeixin();
  18. StorageManager.manager();
  19. }
  20. /*全局路由初始化*/
  21. static void routerInit(){
  22. MainRouterInit.initRouter();
  23. LoginInit.init();
  24. ChatInit.init();
  25. HomeInit.init();
  26. MeInit.init();
  27. ImInit.init();
  28. CommonProjectModule.init();
  29. getDeviceInfo();
  30. setChatRoomAnimationLock();
  31. }
  32. //融云初始化
  33. static void rongrunInit(){
  34. CommonProjectModule.rongRunInit();
  35. }
  36. //网络初始化
  37. static Future<void> requestInit() async {
  38. List<Interceptor> interceptors = [];
  39. /// 统一添加身份验证请求头
  40. // interceptors.add(AuthInterceptor());
  41. /// 加加密验证
  42. // interceptors.add(AdapterSecretEncryptInterceptor());
  43. // interceptors.add(AdapterSecretDecryptInterceptor());
  44. /// 刷新Token
  45. // interceptors.add(TokenInterceptor());
  46. /// 缓存
  47. // interceptors.add(DioCacheManager(
  48. // CacheConfig(
  49. // baseUrl: AppConfig.APP_BASE_URL,
  50. // databaseName: "app",
  51. // )).interceptor);
  52. /// 打印Log(生产模式去除)
  53. if (!CommonUtil.inProduction) {
  54. // interceptors.add(LoggingInterceptor());
  55. }
  56. ApiUtil.InitBaseRequest(
  57. baseUrl: AppConfig.APP_BASE_URL,
  58. connectTimeout: AppConfig.CONNECT_TIMEOUT,
  59. receiveTimeout: AppConfig.RECEIVE_TIMEOUT,
  60. interceptors: interceptors,
  61. );
  62. ApiUtil.instance;
  63. }
  64. //获取版本号
  65. static getDeviceInfo() async {
  66. PackageInfo info = await PackageInfo.fromPlatform();
  67. SpUtil.putString(SPKeys.version, info.version);
  68. }
  69. static setChatRoomAnimationLock() {
  70. bool? isLock = StorageManager.instance.read(key: SPKeys.lockChatRoomAnimation);
  71. if (isLock == null){
  72. StorageManager.instance.write(key: SPKeys.lockChatRoomAnimation, value: false);
  73. }
  74. }
  75. /*全局bloc配置*/
  76. static Widget getGlobalBloc(Widget child){
  77. return MultiBlocProvider(
  78. providers: [
  79. BlocProvider(
  80. create: (context) => TabIndexCubit()
  81. ),
  82. BlocProvider(
  83. create: (context) => LayoutCubit()
  84. ),
  85. BlocProvider(
  86. create: (context) => ConfigCubit()
  87. ),
  88. BlocProvider(
  89. create: (context) => AuthenticationCubit()
  90. ),
  91. BlocProvider(create: (context) => GloableChatRoomCubit()
  92. ),
  93. ],
  94. child:child);
  95. }
  96. }