62 lines
1.8 KiB
Dart
62 lines
1.8 KiB
Dart
import 'dart:ui';
|
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'package:food_health/stores/app_store.dart';
|
|
import 'package:food_health/stores/setting_store.dart';
|
|
import 'package:food_health/stores/user_store.dart';
|
|
import 'package:food_health/router/routes.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'config/theme/theme.dart';
|
|
import 'config/theme/themes/light_theme.dart';
|
|
import 'l10n/app_localizations.dart';
|
|
import 'l10n/l10n.dart';
|
|
|
|
void main() {
|
|
runApp(
|
|
MultiProvider(
|
|
providers: [
|
|
ChangeNotifierProvider(create: (context) => AppStore()),
|
|
ChangeNotifierProvider(create: (context) => UserStore()),
|
|
ChangeNotifierProvider(create: (_) => SettingStore()),
|
|
],
|
|
child: MyApp(),
|
|
),
|
|
);
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
//语言化
|
|
L10n.init(context);
|
|
|
|
final settingStore = context.watch<SettingStore>();
|
|
return ScreenUtilInit(
|
|
designSize: const Size(375, 694),
|
|
useInheritedMediaQuery: true,
|
|
child: MaterialApp.router(
|
|
debugShowCheckedModeBanner: false,
|
|
routerConfig: goRouter,
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: [
|
|
Locale('en'),
|
|
Locale('zh', 'CN'),
|
|
],
|
|
theme: AppTheme.createTheme(LightTheme()),
|
|
locale: settingStore.locale,
|
|
builder: (context, child) {
|
|
// ⚡️ 在这里就能拿到 AppLocalizations
|
|
L10n.init(context);
|
|
return EasyLoading.init()(context, child);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|