129 lines
3.9 KiB
Dart
129 lines
3.9 KiB
Dart
import 'package:bot_toast/bot_toast.dart';
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:flustars/flustars.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:wakelock_plus/wakelock_plus.dart';
|
|
|
|
import 'kt_pages/kt_routes.dart';
|
|
import 'kt_utils/kt_device_info_utils.dart';
|
|
import 'kt_utils/kt_keys.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
SystemChrome.setSystemUIOverlayStyle(
|
|
const SystemUiOverlayStyle(
|
|
statusBarColor: Colors.transparent,
|
|
statusBarIconBrightness: Brightness.light,
|
|
systemNavigationBarColor: Colors.transparent,
|
|
),
|
|
);
|
|
await initSDK();
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
initSDK() async {
|
|
await KtDeviceInfoUtil().init();
|
|
await WakelockPlus.enable();
|
|
EasyLoading.init();
|
|
EasyLoading.instance.dismissOnTap = true;
|
|
await SpUtil.getInstance();
|
|
// KtUserUtil().startOnline();
|
|
// await AdjustService().init();
|
|
// await Firebase.initializeApp();
|
|
}
|
|
|
|
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
|
|
|
class MyApp extends StatefulWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
State<MyApp> createState() => _MyAppState();
|
|
}
|
|
|
|
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
|
|
|
|
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|
DateTime? _cycleLifeTime;
|
|
bool _appLifecycleStateHasPaused = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addObserver(this);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
super.dispose();
|
|
}
|
|
|
|
// 监听生命周期状态变化
|
|
// @override
|
|
// void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
// super.didChangeAppLifecycleState(state);
|
|
// if (state == AppLifecycleState.paused) {
|
|
// _cycleLifeTime = DateTime.now();
|
|
// _appLifecycleStateHasPaused = true;
|
|
// } else if (state == AppLifecycleState.inactive) {
|
|
// KtUserUtil().offLinePost();
|
|
// } else if (state == AppLifecycleState.resumed) {
|
|
// _appLifecycleStateHasPaused = false;
|
|
// if (!_appLifecycleStateHasPaused) {
|
|
// KtUserUtil().enterAppPost();
|
|
// KtUserUtil().reportNotify();
|
|
// }
|
|
// final now = DateTime.now();
|
|
// final duration = now.difference(_cycleLifeTime ?? now);
|
|
// if (duration.inMilliseconds > 3) {
|
|
// Future.delayed(const Duration(milliseconds: 1000)).then((_) {
|
|
// KtUserUtil().onLinePost();
|
|
// });
|
|
// }
|
|
// _cycleLifeTime = null;
|
|
// }
|
|
// }
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ScreenUtilInit(
|
|
designSize: Size(375, 812),
|
|
// minTextAdapt: true,
|
|
builder: (context, child) {
|
|
return GetMaterialApp(
|
|
title: 'Kinetra',
|
|
navigatorKey: navigatorKey,
|
|
navigatorObservers: [routeObserver, BotToastNavigatorObserver()],
|
|
getPages: KtRoutes.routes,
|
|
initialRoute: KtRoutes.splash,
|
|
// 注册路由监听器
|
|
debugShowCheckedModeBanner: false,
|
|
locale: Get.deviceLocale,
|
|
// 获取设备语言
|
|
fallbackLocale: const Locale('en', 'US'),
|
|
// 默认语言
|
|
theme: ThemeData(
|
|
fontFamily: 'Inter',
|
|
// 设置透明导航栏
|
|
appBarTheme: const AppBarTheme(
|
|
backgroundColor: Colors.transparent,
|
|
elevation: 0,
|
|
scrolledUnderElevation: 0,
|
|
systemOverlayStyle: SystemUiOverlayStyle(
|
|
statusBarColor: Colors.transparent,
|
|
),
|
|
),
|
|
),
|
|
// home: const SplashPage(),
|
|
builder: EasyLoading.init(builder: BotToastInit()),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|