Browse Source

修复新手和多语言逻辑

weicu
liwei1dao 1 year ago
parent
commit
3f84933c9d
  1. 85
      lib/main.dart

85
lib/main.dart

@ -1,5 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_intro/flutter_intro.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart'; import 'package:get_storage/get_storage.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart';
@ -108,27 +111,69 @@ class MainApp extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
// 在应用构建时立即初始化深链接处理 // 在应用构建时立即初始化深链接处理
_initDeepLinkHandler(); _initDeepLinkHandler();
// 获取保存的主题设置
final themeMode = ThemeService().getThemeMode();
// 使用 ScreenUtilInit 包装整个应用
return ScreenUtilInit( return ScreenUtilInit(
designSize: const Size(375, 812), // 设计稿尺寸,根据你的设计稿调整 designSize: const Size(375, 812),
minTextAdapt: true, minTextAdapt: true,
splitScreenMode: true, splitScreenMode: true,
builder: (context, child) { builder: (_, child) {
return GetMaterialApp( return GetMaterialApp(
title: 'VoiTrans', title: 'Voitrans',
theme: AppTheme.lightTheme, theme: AppTheme.lightTheme,
darkTheme: AppTheme.darkTheme, darkTheme: AppTheme.darkTheme,
themeMode: ThemeService().getThemeMode(), themeMode: themeMode, // 使用提前获取的主题模式
initialRoute: Routes.splash, initialBinding: InitialBinding(),
getPages: AppPages.pages, initialRoute: Routes.splash,
initialBinding: InitialBinding(), getPages: AppPages.pages,
translations: AppTranslations(), debugShowCheckedModeBanner: false,
locale: Get.deviceLocale, translations: AppTranslations(),
fallbackLocale: const Locale('en', 'US'), localizationsDelegates: const [
debugShowCheckedModeBanner: false, GlobalMaterialLocalizations.delegate,
); GlobalWidgetsLocalizations.delegate,
}, GlobalCupertinoLocalizations.delegate,
); ],
locale: AppTranslations.deviceLocale(),
fallbackLocale: AppTranslations.getSmartFallbackLocale(),
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: Intro(
padding: EdgeInsets.zero,
child: widget!,
),
);
},
),
);
});
// // 使用 ScreenUtilInit 包装整个应用
// return ScreenUtilInit(
// designSize: const Size(375, 812), // 设计稿尺寸,根据你的设计稿调整
// minTextAdapt: true,
// splitScreenMode: true,
// builder: (context, child) {
// return GetMaterialApp(
// title: 'VoiTrans',
// theme: AppTheme.lightTheme,
// darkTheme: AppTheme.darkTheme,
// themeMode: ThemeService().getThemeMode(),
// initialRoute: Routes.splash,
// getPages: AppPages.pages,
// initialBinding: InitialBinding(),
// translations: AppTranslations(),
// locale: Get.deviceLocale,
// fallbackLocale: const Locale('en', 'US'),
// debugShowCheckedModeBanner: false,
// );
// },
// );
} }
} }

Loading…
Cancel
Save