78 lines
2.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:starwork_flutter/common/constant/cache_keys.dart';
import 'package:starwork_flutter/common/utils/shared_preferences_utils.dart';
import 'package:starwork_flutter/flavors.dart';
import 'package:starwork_flutter/i18n/app_i18n.dart';
import 'package:starwork_flutter/routes/app_pages.dart';
import 'package:starwork_flutter/routes/app_routes.dart';
class App extends StatefulWidget {
App({super.key, required this.initialRoute});
String initialRoute;
@override
State<App> createState() => _AppState();
}
class _AppState extends State<App> {
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: const Size(360, 690),
minTextAdapt: true,
splitScreenMode: true,
builder: (_, child) {
return GetMaterialApp(
theme: ThemeData(
scaffoldBackgroundColor: Colors.white,
brightness: Brightness.light,
textSelectionTheme: TextSelectionThemeData(
cursorColor: Colors.blue.shade200,
selectionColor: Colors.blue.shade100,
selectionHandleColor: Colors.blue.shade300,
),
dialogBackgroundColor: Colors.white,
appBarTheme: AppBarTheme(
backgroundColor: Colors.white,
elevation: 0,
surfaceTintColor: Colors.transparent,
shadowColor: Colors.transparent,
scrolledUnderElevation: 0,
titleTextStyle: TextStyle(
color: Colors.black87,
fontSize: 18.sp,
fontWeight: FontWeight.w500,
),
),
),
// 必须配置以下三个本地化代理
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate, // 提供Material组件本地化字符串
GlobalWidgetsLocalizations.delegate, // 定义默认文本方向
GlobalCupertinoLocalizations.delegate, // 提供Cupertino组件本地化
],
supportedLocales: const [
Locale('zh', 'CN'), // ✅ 正确:简体中文
],
enableLog: true,
title: F.title,
translations: AppI18n(),
locale: const Locale('zh', 'CN'),
// 默认语言
fallbackLocale: const Locale('zh', 'CN'),
// 必须设置 fallback 没有该语言时使用
getPages: AppPages.pages,
initialRoute: widget.initialRoute,
debugShowCheckedModeBanner: false,
builder: EasyLoading.init(),
);
},
);
}
}