171 lines
4.2 KiB
Dart
171 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:novyronst/common/help/help_token.dart';
|
|
import 'package:novyronst/root/lib_export.dart';
|
|
import 'package:novyronst/root/root_page.dart';
|
|
import 'package:novyronst/tools/util/ny_device_info.dart';
|
|
|
|
import 'common/help/help_pages.dart';
|
|
|
|
void main() async {
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await initManage();
|
|
runApp(const RootApp());
|
|
}
|
|
|
|
|
|
Future<void> initManage() async {
|
|
|
|
await NyDeviceInfo.init();
|
|
await HelpToken().init();
|
|
}
|
|
|
|
|
|
class RootApp extends StatefulWidget {
|
|
const RootApp({
|
|
super.key,
|
|
this.home,
|
|
this.locale
|
|
});
|
|
|
|
final Widget? home;
|
|
final Locale? locale;
|
|
|
|
@override
|
|
State<StatefulWidget> createState() {
|
|
return _RootAppState();
|
|
}
|
|
}
|
|
|
|
class _RootAppState extends State<RootApp> with WidgetsBindingObserver {
|
|
|
|
bool _appInForeground = true; //
|
|
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AnnotatedRegion<SystemUiOverlayStyle>(
|
|
value: const SystemUiOverlayStyle(
|
|
statusBarColor: Colors.white,
|
|
statusBarBrightness: Brightness.dark, // 🔥 iOS 关键:黑色文字
|
|
statusBarIconBrightness: Brightness.dark, // Android
|
|
),
|
|
child: ScreenUtilInit(
|
|
designSize: Size(375, 812),
|
|
child: GetMaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
locale: widget.locale ?? Get.deviceLocale,
|
|
fallbackLocale: const Locale('en'),
|
|
initialBinding: AppBindings(),
|
|
initialRoute: HelpRouters.launcher,
|
|
getPages: HelpPages.routes,
|
|
theme: ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: ConstColor.themeColor,
|
|
),
|
|
appBarTheme: AppBarTheme(elevation: 0, centerTitle: true),
|
|
splashColor: Colors.transparent,
|
|
useMaterial3: true,
|
|
scaffoldBackgroundColor: Colors.white,
|
|
),
|
|
builder: FlutterSmartDialog.init(
|
|
builder: (context, child) {
|
|
return MediaQuery(
|
|
data: MediaQuery.of(
|
|
context,
|
|
).copyWith(textScaler: TextScaler.linear(1.0)),
|
|
child: child!,
|
|
);
|
|
},
|
|
),
|
|
onInit: () {},
|
|
),
|
|
)
|
|
);
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addObserver(this);
|
|
// _startPeriodicOnlineReport();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
super.didChangeAppLifecycleState(state);
|
|
|
|
switch (state) {
|
|
case AppLifecycleState.inactive:
|
|
case AppLifecycleState.paused:
|
|
// 应用进入后台或不活跃状态
|
|
if (_appInForeground) {
|
|
print('💛应用不活跃');
|
|
_appInForeground = false;
|
|
_onAppPaused();
|
|
}
|
|
break;
|
|
case AppLifecycleState.resumed:
|
|
// 应用回到前台
|
|
if (!_appInForeground) {
|
|
print('💚应用活跃');
|
|
_appInForeground = true;
|
|
_onAppResumed();
|
|
}
|
|
break;
|
|
case AppLifecycleState.detached:
|
|
case AppLifecycleState.hidden:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 应用进入后台时的处理
|
|
void _onAppPaused() {
|
|
try {
|
|
// EventClient.eventOLeaveApp();
|
|
} catch (err) { print(err.toString()); }
|
|
}
|
|
|
|
/// 应用回到前台时的处理
|
|
void _onAppResumed() {
|
|
try {
|
|
// EventClient.eventEnterApp();
|
|
// EventClient.eventOnline();
|
|
} catch (err) { print(err.toString()); }
|
|
}
|
|
}
|
|
|
|
class AppBindings extends Bindings {
|
|
|
|
@override
|
|
void dependencies() {
|
|
// Get.lazyPut(() => UserController());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
// This widget is the root of your application.
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Flutter Demo',
|
|
theme: ThemeData(
|
|
colorScheme: .fromSeed(seedColor: Colors.deepPurple),
|
|
),
|
|
);
|
|
}
|
|
} |