182 lines
6.3 KiB
Dart
Executable File
182 lines
6.3 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:permission_handler/permission_handler.dart';
|
||
import 'package:star_lock/app_settings/app_settings.dart';
|
||
import 'package:star_lock/blue/blue_manage.dart';
|
||
import 'package:star_lock/flavors.dart';
|
||
import 'package:star_lock/login/login/app_get_version.dart';
|
||
import 'package:star_lock/main/lockMian/lockMain/lockMain_logic.dart';
|
||
import 'package:star_lock/network/api_repository.dart';
|
||
import 'package:star_lock/tools/appFirstEnterHandle.dart';
|
||
import 'package:star_lock/tools/app_manager.dart';
|
||
import 'package:star_lock/tools/bindings/app_binding.dart';
|
||
import 'package:star_lock/tools/customer_tool.dart';
|
||
import 'package:star_lock/tools/pay/wx_pay_tool.dart';
|
||
import 'package:star_lock/tools/storage.dart';
|
||
|
||
import 'package:star_lock/translations/app_dept.dart';
|
||
import 'package:star_lock/translations/trans_lib.dart';
|
||
|
||
import 'appRouters.dart';
|
||
import 'baseWidget.dart';
|
||
import 'tools/appRouteObserver.dart';
|
||
|
||
import 'tools/store_service.dart';
|
||
|
||
class MyApp extends StatefulWidget {
|
||
MyApp({required this.isLogin, GlobalKey? key}) : super(key: key);
|
||
bool isLogin;
|
||
|
||
@override
|
||
State<MyApp> createState() => _MyAppState();
|
||
}
|
||
|
||
class _MyAppState extends State<MyApp> with WidgetsBindingObserver, BaseWidget {
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return ScreenUtilInit(
|
||
designSize: const Size(585, 1265),
|
||
builder: (BuildContext w, Widget? a) => _initMaterialApp());
|
||
}
|
||
|
||
GetMaterialApp _initMaterialApp() {
|
||
//判断是不是登录
|
||
String initialRoute;
|
||
if (widget.isLogin) {
|
||
initialRoute = Routers.starLockMain;
|
||
} else {
|
||
initialRoute = Routers.login;
|
||
}
|
||
return GetMaterialApp(
|
||
// enableLog: false,
|
||
title: F.navTitle,
|
||
navigatorObservers: <NavigatorObserver>[
|
||
AppRouteObserver().routeObserver
|
||
],
|
||
translations: TranslationMessage(),
|
||
supportedLocales: appDept.deptSupportedLocales,
|
||
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
|
||
GlobalMaterialLocalizations.delegate,
|
||
GlobalCupertinoLocalizations.delegate,
|
||
GlobalWidgetsLocalizations.delegate,
|
||
],
|
||
localeResolutionCallback:
|
||
(Locale? locale, Iterable<Locale> supportedLocales) {
|
||
if (!supportedLocales.contains(locale)) {
|
||
final int idx = appSupportedLocales.indexWhere((Locale element) =>
|
||
element.languageCode == locale!.languageCode);
|
||
if (idx != -1) {
|
||
locale = appSupportedLocales[idx];
|
||
} else {
|
||
locale = const Locale('zh', 'CN');
|
||
}
|
||
}
|
||
AppManager().setLanCode(
|
||
code: '${locale!.languageCode}_${locale.countryCode}');
|
||
// AppLog.log('1111locale:$locale');
|
||
return locale;
|
||
},
|
||
locale: StoreService.to.getLanguageCode()!.isNotEmpty
|
||
? appDept.deptSupportedLocales
|
||
.where((Locale element) =>
|
||
element.languageCode == StoreService.to.getLanguageCode())
|
||
.first
|
||
: Get.deviceLocale,
|
||
// locale: Get.deviceLocale,
|
||
fallbackLocale: const Locale('zh', 'CN'),
|
||
theme: ThemeData(
|
||
scaffoldBackgroundColor: const Color(0xFFF6F6F6),
|
||
backgroundColor: const Color(0xFFF6F6F6),
|
||
primaryColor: const Color(0xFFFFFFFF),
|
||
textTheme: TextTheme(
|
||
//用在非Material组件上的文字显示,
|
||
bodyText1:
|
||
TextStyle(fontSize: 28.sp, color: const Color(0xff2E2B2B)),
|
||
//Material组件上的文字显示
|
||
bodyText2:
|
||
TextStyle(fontSize: 28.sp, color: const Color(0xff2E2B2B)),
|
||
button: TextStyle(fontSize: 28.sp)),
|
||
iconTheme: IconThemeData(size: 28.sp, color: const Color(0xff2E2B2B)),
|
||
appBarTheme: AppBarTheme(
|
||
backgroundColor: const Color(0xFFFFFFFF),
|
||
elevation: 0,
|
||
centerTitle: true,
|
||
iconTheme:
|
||
IconThemeData(color: const Color(0xff333333), size: 36.sp),
|
||
titleTextStyle: TextStyle(
|
||
color: const Color(0xff333333),
|
||
fontWeight: FontWeight.w400,
|
||
fontSize: 36.sp),
|
||
),
|
||
splashColor: Colors.transparent,
|
||
// 点击时的高亮效果设置为透明
|
||
highlightColor: Colors.transparent,
|
||
),
|
||
debugShowCheckedModeBanner: false,
|
||
getPages: AppRouters.routePages,
|
||
builder: EasyLoading.init(),
|
||
initialBinding: AppBindings(),
|
||
initialRoute: initialRoute);
|
||
}
|
||
|
||
@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);
|
||
// AppLog.log('App--->state:$state');
|
||
switch (state) {
|
||
case AppLifecycleState.inactive:
|
||
// AppLog.log('App--->进入非活动状态');
|
||
break;
|
||
case AppLifecycleState.paused:
|
||
// AppLog.log('App--->进入后台');
|
||
BlueManage().disconnect();
|
||
break;
|
||
case AppLifecycleState.resumed:
|
||
// AppLog.log('App--->进入前台');
|
||
if (Get.isRegistered<LockMainLogic>()) {
|
||
//进入前台刷新如果存在锁列表则刷新,顺便判断 token 是否过期
|
||
Get.find<LockMainLogic>().updateZoneOffsetsAndLanguages();
|
||
}
|
||
break;
|
||
case AppLifecycleState.detached:
|
||
// AppLog.log('App--->挂起');
|
||
break;
|
||
case AppLifecycleState.hidden:
|
||
// AppLog.log('App--->隐藏');
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
Future<bool> getLoginStatus() async {
|
||
final String? data = await Storage.getString(saveUserLoginData);
|
||
if (data != null && data.isNotEmpty) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
Future<void> getAgreePrivacyShowUpdate() async {
|
||
final String? data = await Storage.getString(isAgreePrivacy);
|
||
if (data == isAgreePrivacy) {
|
||
AppFirstEnterHandle().getAppFirstEnter(isShowUpdateVersion);
|
||
}
|
||
}
|
||
|
||
|