135 lines
4.7 KiB
Dart
135 lines
4.7 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter_common/provider/theme_provider.dart';
|
||
import 'package:flutter_common/utils/log_utils.dart';
|
||
import 'package:flutter_common/utils/sp_utils.dart';
|
||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||
import 'package:food_hub_app/provider/app_provider.dart';
|
||
import 'package:food_hub_app/provider/food_provider.dart';
|
||
import 'package:food_hub_app/provider/user_provider.dart';
|
||
import 'package:food_hub_app/views/home.dart';
|
||
import 'package:food_hub_app/views/login.dart';
|
||
import 'package:food_hub_app/views/moment.dart';
|
||
import 'package:food_hub_app/views/moment_form.dart';
|
||
import 'package:food_hub_app/views/moment_user.dart';
|
||
import 'package:food_hub_app/views/profile_form.dart';
|
||
import 'package:food_hub_app/views/profile_user.dart';
|
||
import 'package:food_hub_app/views/recipe_form.dart';
|
||
import 'package:food_hub_app/views/record_form.dart';
|
||
import 'package:food_hub_app/views/recipe_detail.dart';
|
||
import 'package:form_builder_validators/form_builder_validators.dart';
|
||
import 'package:liquid_glass_widgets/liquid_glass_setup.dart';
|
||
import 'package:provider/provider.dart';
|
||
|
||
void main() async {
|
||
WidgetsFlutterBinding.ensureInitialized();
|
||
|
||
FormBuilderLocalizations.delegate.load(const Locale('zh', 'CN'));
|
||
await SPUtil.init();
|
||
await initLogger();
|
||
|
||
// 预编译 shader,防止首帧白闪
|
||
await LiquidGlassWidgets.initialize();
|
||
// wrap() 安装无障碍桥接、全局主题、自适应质量
|
||
runApp(
|
||
LiquidGlassWidgets.wrap(
|
||
child: MultiProvider(
|
||
providers: [
|
||
ChangeNotifierProvider(create: (context) => FoodProvider()),
|
||
ChangeNotifierProvider(create: (context) => ThemeProvider()),
|
||
ChangeNotifierProvider(create: (context) => UserProvider()),
|
||
ChangeNotifierProvider(create: (context) => AppProvider()),
|
||
],
|
||
child: const MyApp(),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
class MyApp extends StatelessWidget {
|
||
const MyApp({super.key});
|
||
|
||
// This widget is the root of your application.
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final themeProvider = context.watch<ThemeProvider>();
|
||
final brightness = MediaQuery.of(context).platformBrightness;
|
||
themeProvider.isDarkMode = brightness == Brightness.dark;
|
||
|
||
return MaterialApp(
|
||
debugShowCheckedModeBanner: false,
|
||
theme: ThemeData(
|
||
scaffoldBackgroundColor: const Color(0xFFFAF6F0),
|
||
colorScheme: ColorScheme(
|
||
brightness: Brightness.light,
|
||
primary: const Color(0xFFE89F71),
|
||
secondary: const Color(0xFFE89F71),
|
||
surface: const Color(0xFFFFFFFF),
|
||
error: const Color(0xFFE76F51),
|
||
|
||
onPrimary: Colors.white,
|
||
onSecondary: Colors.white,
|
||
onSurface: const Color(0xFF3A332C),
|
||
onError: Colors.white,
|
||
),
|
||
textTheme: TextTheme(
|
||
titleLarge: TextStyle(
|
||
fontSize: 20,
|
||
fontWeight: FontWeight.w600,
|
||
color: const Color(0xFF3A332C),
|
||
),
|
||
titleMedium: TextStyle(
|
||
fontSize: 16,
|
||
fontWeight: FontWeight.w500,
|
||
color: const Color(0xFF3A332C),
|
||
),
|
||
bodyLarge: TextStyle(
|
||
fontSize: 15,
|
||
color: const Color(0xFF3A332C),
|
||
),
|
||
bodyMedium: TextStyle(
|
||
fontSize: 14,
|
||
color: const Color(0xFF8C8379),
|
||
),
|
||
bodySmall: TextStyle(
|
||
fontSize: 12,
|
||
color: const Color(0xFF8C8379),
|
||
),
|
||
),
|
||
fontFamily: 'CustomFont',
|
||
useMaterial3: true,
|
||
),
|
||
supportedLocales: const [
|
||
Locale('en', 'US'), // 英语
|
||
Locale('zh', 'CN'), // 中文
|
||
],
|
||
// 本地化代理配置
|
||
localizationsDelegates: const [
|
||
GlobalMaterialLocalizations.delegate,
|
||
GlobalWidgetsLocalizations.delegate,
|
||
GlobalCupertinoLocalizations.delegate,
|
||
],
|
||
// 根据系统语言自动选择Locale
|
||
localeResolutionCallback: (locale, supportedLocales) {
|
||
for (var supportedLocale in supportedLocales) {
|
||
if (supportedLocale.languageCode == locale?.languageCode) {
|
||
return supportedLocale;
|
||
}
|
||
}
|
||
return supportedLocales.first;
|
||
},
|
||
home: LoginPage(),
|
||
routes: {
|
||
'/home': (context) => HomePage(),
|
||
'/recordForm': (context) => RecordForm(),
|
||
'/recipeForm': (context) => RecipeForm(),
|
||
'/recipeDetail': (context) => RecipeDetailPage(),
|
||
'/momentForm': (context) => MomentForm(),
|
||
'/moment': (context) => MomentPage(),
|
||
'/momentUser': (context) => MomentUserPage(),
|
||
'/profileUser': (context) => ProfileUserPage(),
|
||
'/profileForm': (context) => ProfileForm(),
|
||
},
|
||
);
|
||
}
|
||
}
|