|
|
|
@ -16,15 +16,12 @@ void main() async { |
|
|
|
// 确保Flutter绑定初始化 |
|
|
|
WidgetsFlutterBinding.ensureInitialized(); |
|
|
|
|
|
|
|
// 先运行应用,显示启动页面 |
|
|
|
runApp(const MainApp()); |
|
|
|
// 初始化存储 - 在创建应用之前初始化 |
|
|
|
await GetStorage.init(); |
|
|
|
|
|
|
|
// 初始化环境变量 |
|
|
|
await dotenv.load(); |
|
|
|
|
|
|
|
// 然后异步执行其他初始化操作 |
|
|
|
_initializeApp(); |
|
|
|
} |
|
|
|
|
|
|
|
// 异步初始化应用 |
|
|
|
Future<void> _initializeApp() async { |
|
|
|
// 设置窗口大小(仅在 macOS 下生效) |
|
|
|
if (Platform.isMacOS) { |
|
|
|
const double width = 375.0; |
|
|
|
@ -35,32 +32,20 @@ Future<void> _initializeApp() async { |
|
|
|
setWindowMaxSize(const Size(width, height)); |
|
|
|
|
|
|
|
// 居中显示窗口 |
|
|
|
getCurrentScreen().then((screen) { |
|
|
|
if (screen != null) { |
|
|
|
final screenFrame = screen.frame; |
|
|
|
final windowFrame = Rect.fromCenter( |
|
|
|
center: screenFrame.center, |
|
|
|
width: width, |
|
|
|
height: height, |
|
|
|
); |
|
|
|
setWindowFrame(windowFrame); |
|
|
|
} |
|
|
|
}); |
|
|
|
final screen = await getCurrentScreen(); |
|
|
|
if (screen != null) { |
|
|
|
final screenFrame = screen.frame; |
|
|
|
final windowFrame = Rect.fromCenter( |
|
|
|
center: screenFrame.center, |
|
|
|
width: width, |
|
|
|
height: height, |
|
|
|
); |
|
|
|
setWindowFrame(windowFrame); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 初始化环境变量 |
|
|
|
await dotenv.load(); |
|
|
|
|
|
|
|
// 初始化存储 |
|
|
|
await GetStorage.init(); |
|
|
|
|
|
|
|
// 注意:应用启动时会在 SplashController 中检查上次保存的皮肤模式 |
|
|
|
// 并自动应用保存的主题(暗黑/浅色) |
|
|
|
|
|
|
|
// AudioService 将在 AudioServiceManager 中初始化 |
|
|
|
// 不再需要在这里调用 AudioService.init |
|
|
|
|
|
|
|
// 其他可能的初始化操作... |
|
|
|
// 运行应用 |
|
|
|
runApp(const MainApp()); |
|
|
|
} |
|
|
|
|
|
|
|
class MainApp extends StatelessWidget { |
|
|
|
@ -68,6 +53,9 @@ class MainApp extends StatelessWidget { |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
// 获取保存的主题设置 |
|
|
|
final themeMode = ThemeService().getThemeMode(); |
|
|
|
|
|
|
|
return ScreenUtilInit( |
|
|
|
designSize: const Size(375, 812), |
|
|
|
minTextAdapt: true, |
|
|
|
@ -77,7 +65,7 @@ class MainApp extends StatelessWidget { |
|
|
|
title: 'Deep Voice', |
|
|
|
theme: AppTheme.lightTheme, |
|
|
|
darkTheme: AppTheme.darkTheme, |
|
|
|
themeMode: ThemeService().getThemeMode(), // 初始主题模式,将在 SplashController 中再次检查 |
|
|
|
themeMode: themeMode, // 使用提前获取的主题模式 |
|
|
|
initialBinding: InitialBinding(), |
|
|
|
initialRoute: Routes.splash, |
|
|
|
getPages: AppPages.pages, |
|
|
|
|