splash_view_model.dart 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import 'package:flutter/material.dart';
  2. import 'package:plugin_basic/constants/app_constant.dart';
  3. import 'package:plugin_basic/provider/user_config/user_config_service.dart';
  4. import 'package:plugin_platform/engine/sp/sp_util.dart';
  5. import 'package:riverpod_annotation/riverpod_annotation.dart';
  6. import 'package:flutter_riverpod/flutter_riverpod.dart';
  7. import 'package:router/componentRouter/component_service_manager.dart';
  8. import 'package:shared/utils/log_utils.dart';
  9. part 'splash_view_model.g.dart';
  10. @riverpod
  11. class SplashViewModel extends _$SplashViewModel {
  12. @override
  13. void build() {
  14. // 初始构建逻辑
  15. Log.d("初始构建逻辑");
  16. _gotoNextPage();
  17. }
  18. BuildContext? _context;
  19. void setContext(BuildContext context) {
  20. Log.d("赋值Context");
  21. _context = context;
  22. }
  23. void _gotoNextPage() async {
  24. await Future.delayed(const Duration(seconds: 1));
  25. // await AppInitializer.delayInitialize(futureTasks: [
  26. // () async {
  27. // await FlutterBugly.init(
  28. // androidAppId: "12345678",
  29. // iOSAppId: "12345678",
  30. // );
  31. // },
  32. // ], normalTasks: [
  33. // () {
  34. // if (DeviceUtils.isIOS || DeviceUtils.isAndroid) {
  35. // jpush.init();
  36. // }
  37. // },
  38. // ]);
  39. // 先查询原生平台有没有保存需要跳转的子路由
  40. // String routerName = await AppChannel.getNativeRouterName();
  41. // Log.d('SplashController - 查询原生平台有没有保存需要跳转的子路由:$routerName');
  42. String? token = SPUtil.getString(AppConstant.storageToken);
  43. final userConfigService = UserConfigService.getInstance();
  44. Log.d("userConfigService对象:$userConfigService");
  45. userConfigService.setToken(token);
  46. final userConfigServiceByRef = UserConfigService.getInstance(ref: ref);
  47. Log.d("userConfigServiceByRef对象:$userConfigServiceByRef");
  48. Log.d("两个UserConfigService是一个对象吗:${userConfigService == userConfigServiceByRef}");
  49. final appService = ComponentServiceManager().appService;
  50. final mainService = ComponentServiceManager().mainService;
  51. Log.d("appService:$appService mainService:$mainService");
  52. if (UserConfigService.getState().haslogin == true) {
  53. //去Attendance页面签到
  54. Log.d("已经登录,去首页页面");
  55. ComponentServiceManager().mainService.startMainPage();
  56. } else {
  57. //去登录页面
  58. Log.d("没有登录,去登录页面");
  59. ComponentServiceManager().mainService.startMainPage();
  60. }
  61. }
  62. }