78 lines
2.1 KiB
Dart
78 lines
2.1 KiB
Dart
import 'package:app/widgets/version/version_ui.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:app/router/app_routes.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'core/event/event_bus.dart';
|
|
import 'core/event/global_event.dart';
|
|
import 'core/theme/theme.dart';
|
|
import 'data/repository/auto_repo.dart';
|
|
import 'l10n/app_localizations.dart';
|
|
import 'widgets/version/check_version_update.dart';
|
|
|
|
void main() {
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatefulWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
State<MyApp> createState() => _MyAppState();
|
|
}
|
|
|
|
class _MyAppState extends State<MyApp> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
EventBus().stream.listen((event) {
|
|
// 1. 监听 401
|
|
if (event is UnauthorizedEvent) {
|
|
final ctx = navigatorKey.currentState?.context;
|
|
if (ctx != null) {
|
|
AuthRepo.clearLogin();
|
|
// ctx.go(RoutePaths.auth);
|
|
}
|
|
}
|
|
|
|
//监听版本更新
|
|
if (event is VersionUpdateEvent) {
|
|
final ctx = navigatorKey.currentState?.context;
|
|
if (ctx == null) return;
|
|
showUpdateDialog(ctx, event.version);
|
|
}
|
|
});
|
|
|
|
checkUpdate();
|
|
}
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ScreenUtilInit(
|
|
designSize: const Size(375, 694),
|
|
useInheritedMediaQuery: true,
|
|
child: MaterialApp.router(
|
|
localizationsDelegates: [
|
|
// 本地化的代理类
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
AppLocalizations.delegate,
|
|
],
|
|
supportedLocales: [
|
|
Locale('en'),
|
|
Locale('zh', 'CN'),
|
|
],
|
|
routerConfig: goRouter,
|
|
theme: AppTheme.createTheme(LightTheme()),
|
|
builder: (context, child) {
|
|
final easyLoadingBuilder = EasyLoading.init();
|
|
return easyLoadingBuilder(context, child);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|