2024-01-27 16:05:17 +08:00
|
|
|
|
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';
|
2024-03-12 16:35:40 +08:00
|
|
|
|
import 'package:star_lock/flavors.dart';
|
2024-01-27 16:05:17 +08:00
|
|
|
|
import 'package:star_lock/tools/app_manager.dart';
|
|
|
|
|
|
import 'package:star_lock/tools/bindings/app_binding.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 'dart:io';
|
|
|
|
|
|
|
2024-03-13 11:38:37 +08:00
|
|
|
|
import 'versionUndate/versionUndateTool.dart';
|
|
|
|
|
|
|
2024-01-27 16:05:17 +08:00
|
|
|
|
class MyApp extends StatefulWidget {
|
|
|
|
|
|
const MyApp({GlobalKey? key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
State<MyApp> createState() => _MyAppState();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 注册 RouteObserver 作为 navigation observer.
|
|
|
|
|
|
// final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
|
|
|
|
|
|
|
|
|
|
|
|
class _MyAppState extends State<MyApp> with WidgetsBindingObserver, BaseWidget {
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
return ScreenUtilInit(
|
|
|
|
|
|
designSize: const Size(585, 1265),
|
|
|
|
|
|
builder: (w, a) => _initMaterialApp());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GetMaterialApp _initMaterialApp() => GetMaterialApp(
|
2024-03-12 16:35:40 +08:00
|
|
|
|
title: F.navTitle,
|
2024-01-27 16:05:17 +08:00
|
|
|
|
navigatorObservers: [AppRouteObserver().routeObserver],
|
|
|
|
|
|
translations: TranslationMessage(),
|
|
|
|
|
|
supportedLocales: appDept.deptSupportedLocales,
|
|
|
|
|
|
localizationsDelegates: const [
|
|
|
|
|
|
GlobalMaterialLocalizations.delegate,
|
|
|
|
|
|
GlobalCupertinoLocalizations.delegate,
|
|
|
|
|
|
GlobalWidgetsLocalizations.delegate,
|
|
|
|
|
|
],
|
|
|
|
|
|
localeResolutionCallback: (locale, supportedLocales) {
|
|
|
|
|
|
if (!supportedLocales.contains(locale)) {
|
|
|
|
|
|
int idx = appSupportedLocales.indexWhere(
|
2024-02-29 17:03:53 +08:00
|
|
|
|
(element) => element.languageCode == locale!.languageCode);
|
2024-01-27 16:05:17 +08:00
|
|
|
|
if (idx != -1) {
|
|
|
|
|
|
locale = appSupportedLocales[idx];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
locale = const Locale('zh', 'CN');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// print("localelocalelocalelocalelocale locale:${locale} locale.languageCode:${locale.languageCode} locale.countryCode:${locale.countryCode} supportedLocales:${supportedLocales}");
|
|
|
|
|
|
AppManager()
|
|
|
|
|
|
.setLanCode(code: '${locale!.languageCode}_${locale.countryCode}');
|
|
|
|
|
|
return locale;
|
|
|
|
|
|
},
|
|
|
|
|
|
// locale: StoreService.to.getLanguageCode().isNotEmpty ? appDept.deptSupportedLocales.where((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(
|
2024-02-29 17:03:53 +08:00
|
|
|
|
//用在非Material组件上的文字显示,
|
2024-01-27 16:05:17 +08:00
|
|
|
|
bodyText1:
|
2024-02-29 17:03:53 +08:00
|
|
|
|
TextStyle(fontSize: 28.sp, color: const Color(0xff2E2B2B)),
|
2024-01-27 16:05:17 +08:00
|
|
|
|
//Material组件上的文字显示
|
|
|
|
|
|
bodyText2:
|
2024-02-29 17:03:53 +08:00
|
|
|
|
TextStyle(fontSize: 28.sp, color: const Color(0xff2E2B2B)),
|
2024-01-27 16:05:17 +08:00
|
|
|
|
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: '/');
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
super.initState();
|
|
|
|
|
|
WidgetsBinding.instance.addObserver(this);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void dispose() {
|
|
|
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
|
|
super.dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void openBlueScan() {
|
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
|
print("有蓝牙权限开始扫描");
|
|
|
|
|
|
// startScanAction();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
getMicrophonePermission().then((value) {
|
|
|
|
|
|
if (value) {
|
|
|
|
|
|
// 有权限
|
|
|
|
|
|
print("有蓝牙权限开始扫描");
|
|
|
|
|
|
// startScanAction();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
//没有权限
|
|
|
|
|
|
openAppSettings(); //打开app系统设置
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///请求蓝牙权限
|
|
|
|
|
|
Future<bool> getMicrophonePermission() async {
|
|
|
|
|
|
// You can request multiple permissions at once.
|
|
|
|
|
|
Map<Permission, PermissionStatus> statuses = await [
|
|
|
|
|
|
Permission.bluetoothScan,
|
|
|
|
|
|
Permission.bluetoothConnect,
|
|
|
|
|
|
Permission.location,
|
|
|
|
|
|
].request();
|
|
|
|
|
|
|
|
|
|
|
|
//granted 通过,denied 被拒绝,permanentlyDenied 拒绝且不在提示
|
|
|
|
|
|
if (statuses[Permission.bluetoothScan]!.isGranted &&
|
|
|
|
|
|
statuses[Permission.bluetoothConnect]!.isGranted &&
|
|
|
|
|
|
statuses[Permission.location]!.isGranted) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|