splash_view_model.dart 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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("SplashViewModel - 初始构建逻辑");
  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. userConfigService.setToken(token);
  45. if (UserConfigService.getState().haslogin == true) {
  46. //去Attendance页面签到
  47. Log.d("已经登录,去首页页面");
  48. ComponentServiceManager().mainService.startMainPage();
  49. } else {
  50. //去登录页面
  51. Log.d("没有登录,去登录页面");
  52. ComponentServiceManager().mainService.startMainPage();
  53. }
  54. }
  55. }