Files
wushu/lib/main.dart
2026-04-02 22:30:49 +08:00

66 lines
2.0 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'utils/app_theme.dart';
import 'utils/app_initializer.dart';
import 'utils/force_guide_checker.dart';
import 'routes/app_routes.dart';
import 'constants/app_constants.dart';
import 'config/app_config.dart';
import 'controllers/shared_preferences_storage_controller.dart';
import 'services/get/theme_controller.dart';
import 'views/profile/guide/sp-guide.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await SharedPreferencesStorageController.init();
// 初始化 ThemeController在 AppInitializer 之前,确保主题最先加载)
Get.put(ThemeController(), permanent: true);
// 检查是否需要显示引导页
String initialRoute = await _getInitialRoute();
runApp(MyApp(initialRoute: initialRoute));
}
Future<String> _getInitialRoute() async {
final prefs = await SharedPreferences.getInstance();
bool agreementAccepted =
prefs.getBool(AppConfig.keyAgreementAccepted) ?? false;
// 如果协议未被接受,显示引导页
if (!agreementAccepted) {
return '/sp-guide';
}
// 否则使用 AppInitializer 返回的初始路由
final result = await AppInitializer.initialize();
return result.initialRoute;
}
class MyApp extends StatelessWidget {
final String initialRoute;
const MyApp({super.key, required this.initialRoute});
@override
Widget build(BuildContext context) {
// 使用 Obx 监听主题变化
return Obx(() {
final themeController = Get.find<ThemeController>();
return GetMaterialApp(
title: AppConstants.appName,
debugShowCheckedModeBanner: false,
theme: AppTheme.lightTheme,
darkTheme: AppTheme.darkTheme,
themeMode: themeController.currentThemeMode,
initialRoute: initialRoute,
onGenerateRoute: AppRoutes.generateRoute,
routes: {'/sp-guide': (context) => const SpGuidePage()},
);
});
}
}