2023-11-01 14:18:52 +08:00
|
|
|
|
import 'package:aliyun_push/aliyun_push.dart';
|
2023-07-10 17:50:31 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
2023-07-29 09:25:21 +08:00
|
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
2023-07-10 17:50:31 +08:00
|
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
|
|
import 'package:get/get.dart';
|
2023-12-27 10:47:58 +08:00
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
2023-07-10 17:50:31 +08:00
|
|
|
|
import 'package:star_lock/tools/app_manager.dart';
|
2023-07-29 09:25:21 +08:00
|
|
|
|
import 'package:star_lock/tools/bindings/app_binding.dart';
|
2023-07-10 17:50:31 +08:00
|
|
|
|
import 'package:star_lock/tools/device_info_service.dart';
|
|
|
|
|
|
import 'package:star_lock/tools/platform_info_services.dart';
|
2023-11-01 14:18:52 +08:00
|
|
|
|
import 'package:star_lock/tools/storage.dart';
|
|
|
|
|
|
import 'package:star_lock/tools/xs_aliyunPush.dart';
|
2023-07-10 17:50:31 +08:00
|
|
|
|
import 'package:star_lock/translations/app_dept.dart';
|
|
|
|
|
|
import 'package:star_lock/translations/trans_lib.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import 'appRouters.dart';
|
|
|
|
|
|
import 'baseWidget.dart';
|
2023-12-27 10:47:58 +08:00
|
|
|
|
import 'blue/blue_manage.dart';
|
2023-09-09 18:33:37 +08:00
|
|
|
|
import 'tools/appRouteObserver.dart';
|
2023-08-02 09:22:39 +08:00
|
|
|
|
import 'tools/store_service.dart';
|
2023-10-12 11:24:41 +08:00
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
import 'package:flutter/services.dart';
|
2023-07-10 17:50:31 +08:00
|
|
|
|
|
|
|
|
|
|
void main() async {
|
2023-08-26 11:40:40 +08:00
|
|
|
|
await _setCommonServices();
|
2023-07-10 17:50:31 +08:00
|
|
|
|
|
|
|
|
|
|
// 设置国际化信息
|
|
|
|
|
|
await _initTranslation();
|
|
|
|
|
|
|
|
|
|
|
|
runApp(MyApp());
|
2023-10-12 11:24:41 +08:00
|
|
|
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
2023-11-16 10:04:38 +08:00
|
|
|
|
SystemUiOverlayStyle systemUiOverlayStyle =
|
|
|
|
|
|
const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
|
2023-10-12 11:24:41 +08:00
|
|
|
|
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
|
|
|
|
|
|
}
|
2023-07-10 17:50:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class MyApp extends StatefulWidget {
|
2023-07-25 15:48:40 +08:00
|
|
|
|
const MyApp({GlobalKey? key}) : super(key: key);
|
2023-07-10 17:50:31 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
State<MyApp> createState() => _MyAppState();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-24 14:25:55 +08:00
|
|
|
|
// 注册 RouteObserver 作为 navigation observer.
|
2024-01-04 18:27:50 +08:00
|
|
|
|
// final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
|
2023-08-24 14:25:55 +08:00
|
|
|
|
|
2023-07-10 17:50:31 +08:00
|
|
|
|
class _MyAppState extends State<MyApp> with WidgetsBindingObserver, BaseWidget {
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
return ScreenUtilInit(
|
2023-07-27 15:26:30 +08:00
|
|
|
|
designSize: const Size(585, 1265),
|
2023-07-25 15:48:40 +08:00
|
|
|
|
builder: (w, a) => _initMaterialApp());
|
2023-07-10 17:50:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GetMaterialApp _initMaterialApp() => GetMaterialApp(
|
|
|
|
|
|
title: 'Star Lock',
|
2024-01-04 18:27:50 +08:00
|
|
|
|
navigatorObservers: [AppRouteObserver().routeObserver],
|
2023-07-10 17:50:31 +08:00
|
|
|
|
translations: TranslationMessage(),
|
|
|
|
|
|
supportedLocales: appDept.deptSupportedLocales,
|
|
|
|
|
|
localizationsDelegates: const [
|
|
|
|
|
|
GlobalMaterialLocalizations.delegate,
|
|
|
|
|
|
GlobalCupertinoLocalizations.delegate,
|
|
|
|
|
|
GlobalWidgetsLocalizations.delegate,
|
|
|
|
|
|
],
|
2023-07-25 15:48:40 +08:00
|
|
|
|
localeResolutionCallback: (locale, supportedLocales) {
|
|
|
|
|
|
if (!supportedLocales.contains(locale)) {
|
|
|
|
|
|
int idx = appSupportedLocales.indexWhere(
|
|
|
|
|
|
(element) => element.languageCode == locale!.languageCode);
|
|
|
|
|
|
if (idx != -1) {
|
2023-07-10 17:50:31 +08:00
|
|
|
|
locale = appSupportedLocales[idx];
|
2023-07-25 15:48:40 +08:00
|
|
|
|
} else {
|
2023-07-10 17:50:31 +08:00
|
|
|
|
locale = const Locale('zh', 'CN');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// print("localelocalelocalelocalelocale locale:${locale} locale.languageCode:${locale.languageCode} locale.countryCode:${locale.countryCode} supportedLocales:${supportedLocales}");
|
2023-07-25 15:48:40 +08:00
|
|
|
|
AppManager()
|
|
|
|
|
|
.setLanCode(code: '${locale!.languageCode}_${locale.countryCode}');
|
2023-07-10 17:50:31 +08:00
|
|
|
|
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(
|
2023-07-25 15:48:40 +08:00
|
|
|
|
//用在非Material组件上的文字显示,
|
|
|
|
|
|
bodyText1:
|
|
|
|
|
|
TextStyle(fontSize: 28.sp, color: const Color(0xff2E2B2B)),
|
2023-07-10 17:50:31 +08:00
|
|
|
|
//Material组件上的文字显示
|
2023-07-25 15:48:40 +08:00
|
|
|
|
bodyText2:
|
|
|
|
|
|
TextStyle(fontSize: 28.sp, color: const Color(0xff2E2B2B)),
|
2023-07-10 17:50:31 +08:00
|
|
|
|
button: TextStyle(fontSize: 28.sp)),
|
2023-07-25 15:48:40 +08:00
|
|
|
|
iconTheme: IconThemeData(size: 28.sp, color: const Color(0xff2E2B2B)),
|
2023-07-10 17:50:31 +08:00
|
|
|
|
appBarTheme: AppBarTheme(
|
|
|
|
|
|
backgroundColor: const Color(0xFFFFFFFF),
|
|
|
|
|
|
elevation: 0,
|
|
|
|
|
|
centerTitle: true,
|
2023-07-25 15:48:40 +08:00
|
|
|
|
iconTheme: IconThemeData(color: const Color(0xff333333), size: 36.sp),
|
2023-07-10 17:50:31 +08:00
|
|
|
|
titleTextStyle: TextStyle(
|
|
|
|
|
|
color: const Color(0xff333333),
|
|
|
|
|
|
fontWeight: FontWeight.w400,
|
|
|
|
|
|
fontSize: 36.sp),
|
|
|
|
|
|
),
|
|
|
|
|
|
splashColor: Colors.transparent, // 点击时的高亮效果设置为透明
|
|
|
|
|
|
highlightColor: Colors.transparent,
|
|
|
|
|
|
),
|
|
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
|
|
getPages: AppRouters.routePages,
|
2023-07-29 09:25:21 +08:00
|
|
|
|
builder: EasyLoading.init(),
|
|
|
|
|
|
initialBinding: AppBindings(),
|
2023-07-25 15:48:40 +08:00
|
|
|
|
initialRoute: '/');
|
2023-07-10 17:50:31 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
super.initState();
|
2024-01-17 14:11:10 +08:00
|
|
|
|
WidgetsBinding.instance.addObserver(this);
|
2023-11-01 14:18:52 +08:00
|
|
|
|
|
2023-12-27 10:47:58 +08:00
|
|
|
|
openBlueScan();
|
|
|
|
|
|
|
2023-11-01 14:18:52 +08:00
|
|
|
|
initAliyunPush();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//初始化阿里云推送
|
|
|
|
|
|
void initAliyunPush() {
|
2024-01-17 13:52:45 +08:00
|
|
|
|
final aliyunPush = AliyunPush();
|
|
|
|
|
|
XSAliyunPushProvider().init(aliyunPush);
|
2023-11-01 14:18:52 +08:00
|
|
|
|
XSAliyunPushProvider().initAliyunPush();
|
|
|
|
|
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
|
XSAliyunPushProvider().initAliyunThirdPush();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-17 13:52:45 +08:00
|
|
|
|
//暂使用DeviceID推送
|
|
|
|
|
|
aliyunPush.getDeviceId().then((deviceId) async {
|
|
|
|
|
|
// print('得到的DeviceId$deviceId');
|
2024-01-16 15:13:43 +08:00
|
|
|
|
final data = await Storage.getString(saveUserLoginData);
|
2024-01-17 13:52:45 +08:00
|
|
|
|
if (data!.isNotEmpty && deviceId.isNotEmpty) {
|
2024-01-16 10:11:40 +08:00
|
|
|
|
XSAliyunPushProvider()
|
|
|
|
|
|
.pushBindDeviceID(deviceId, Platform.isAndroid ? 10 : 20);
|
2023-12-04 09:47:04 +08:00
|
|
|
|
}
|
2023-11-01 14:18:52 +08:00
|
|
|
|
});
|
2023-07-10 17:50:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void dispose() {
|
2024-01-17 13:52:45 +08:00
|
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
2023-07-10 17:50:31 +08:00
|
|
|
|
super.dispose();
|
|
|
|
|
|
}
|
2024-01-17 13:58:48 +08:00
|
|
|
|
}
|
2023-07-10 17:50:31 +08:00
|
|
|
|
|
|
|
|
|
|
// 设置国际化信息
|
|
|
|
|
|
Future _initTranslation() async => TranslationLoader.loadTranslation(
|
2023-07-25 15:48:40 +08:00
|
|
|
|
zhSource: "images/lan/lan_zh.json",
|
|
|
|
|
|
enSource: "images/lan/lan_en.json",
|
|
|
|
|
|
keySource: "images/lan/lan_keys.json",
|
|
|
|
|
|
);
|
2023-07-10 17:50:31 +08:00
|
|
|
|
|
|
|
|
|
|
// 设置包名服务设备信息
|
|
|
|
|
|
Future _setCommonServices() async {
|
|
|
|
|
|
await Get.putAsync(() => StoreService().init());
|
|
|
|
|
|
await Get.putAsync(() => PlatformInfoService().init());
|
|
|
|
|
|
await Get.putAsync(() => DeviceInfoService().init());
|
2023-08-26 11:40:40 +08:00
|
|
|
|
// Get.log(PlatformInfoService.to.info.version);
|
2023-11-16 10:04:38 +08:00
|
|
|
|
}
|
2023-12-04 09:47:04 +08:00
|
|
|
|
|
2024-01-02 15:42:41 +08:00
|
|
|
|
void openBlueScan() {
|
|
|
|
|
|
if (Platform.isIOS) {
|
2023-12-27 10:47:58 +08:00
|
|
|
|
print("有蓝牙权限开始扫描");
|
2024-01-06 16:26:13 +08:00
|
|
|
|
// startScanAction();
|
2024-01-02 15:42:41 +08:00
|
|
|
|
} else {
|
2023-12-27 10:47:58 +08:00
|
|
|
|
getMicrophonePermission().then((value) {
|
|
|
|
|
|
if (value) {
|
|
|
|
|
|
// 有权限
|
|
|
|
|
|
print("有蓝牙权限开始扫描");
|
2024-01-06 16:26:13 +08:00
|
|
|
|
// startScanAction();
|
2024-01-02 15:42:41 +08:00
|
|
|
|
} else {
|
2023-12-27 10:47:58 +08:00
|
|
|
|
//没有权限
|
2024-01-02 15:42:41 +08:00
|
|
|
|
openAppSettings(); //打开app系统设置
|
2023-12-27 10:47:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-19 11:09:46 +08:00
|
|
|
|
// void startScanAction() {
|
|
|
|
|
|
// BlueManage().startScan();
|
|
|
|
|
|
// }
|
2023-12-27 10:47:58 +08:00
|
|
|
|
|
|
|
|
|
|
///请求蓝牙权限
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|