You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.2 KiB
103 lines
3.2 KiB
import 'package:flutter/material.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
import 'package:get_storage/get_storage.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'core/bindings/initial_binding.dart';
|
|
import 'routes/app_pages.dart';
|
|
import 'routes/app_routes.dart';
|
|
import 'dart:io';
|
|
import 'package:window_size/window_size.dart';
|
|
import 'core/translations/app_translations.dart';
|
|
import 'core/themes/app_theme.dart';
|
|
import 'core/themes/theme_service.dart';
|
|
import '../../data/services/login_service.dart';
|
|
|
|
void main() async {
|
|
// 确保Flutter绑定初始化
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
// 初始化存储 - 在创建应用之前初始化
|
|
await GetStorage.init();
|
|
|
|
// 初始化环境变量
|
|
await dotenv.load();
|
|
|
|
// 初始化登录服务(包含Firebase初始化)
|
|
LoginService();
|
|
|
|
// 设置窗口大小(仅在 macOS 下生效)
|
|
if (Platform.isMacOS) {
|
|
const double width = 375.0;
|
|
const double height = 812.0;
|
|
|
|
setWindowTitle('DeapSound');
|
|
setWindowMinSize(const Size(width, height));
|
|
setWindowMaxSize(const Size(width, height));
|
|
|
|
// 居中显示窗口
|
|
final screen = await getCurrentScreen();
|
|
if (screen != null) {
|
|
final screenFrame = screen.frame;
|
|
final windowFrame = Rect.fromCenter(
|
|
center: screenFrame.center,
|
|
width: width,
|
|
height: height,
|
|
);
|
|
setWindowFrame(windowFrame);
|
|
}
|
|
}
|
|
|
|
// 运行应用
|
|
runApp(const MainApp());
|
|
}
|
|
|
|
class MainApp extends StatelessWidget {
|
|
const MainApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// 获取保存的主题设置
|
|
final themeMode = ThemeService().getThemeMode();
|
|
|
|
return ScreenUtilInit(
|
|
designSize: const Size(375, 812),
|
|
minTextAdapt: true,
|
|
splitScreenMode: true,
|
|
builder: (_, child) {
|
|
return GetMaterialApp(
|
|
title: 'DeapSound',
|
|
theme: AppTheme.lightTheme,
|
|
darkTheme: AppTheme.darkTheme,
|
|
themeMode: themeMode, // 使用提前获取的主题模式
|
|
initialBinding: InitialBinding(),
|
|
initialRoute: Routes.splash,
|
|
getPages: AppPages.pages,
|
|
debugShowCheckedModeBanner: false,
|
|
translations: AppTranslations(),
|
|
localizationsDelegates: const [
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
locale: AppTranslations.deviceLocale(),
|
|
fallbackLocale: AppTranslations.fallbackLocale,
|
|
supportedLocales: AppTranslations.supportedLocales,
|
|
builder: EasyLoading.init(
|
|
builder: (BuildContext context, Widget? widget) {
|
|
EasyLoading.instance.userInteractions = false;
|
|
return MediaQuery(
|
|
data: MediaQuery.of(context).copyWith(
|
|
textScaler: TextScaler.noScaling,
|
|
),
|
|
child: widget!,
|
|
);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|