Merge branch 'release_hyx' into release
This commit is contained in:
commit
1b4cefbcc1
@ -608,7 +608,7 @@
|
|||||||
"卡详情": "Card details",
|
"卡详情": "Card details",
|
||||||
"请输入": "Please enter",
|
"请输入": "Please enter",
|
||||||
"关闭后,智能锁将设置为全天常开模式,直到手动关闭": "After closing, the smart lock will be set to all-day open mode until manually closed",
|
"关闭后,智能锁将设置为全天常开模式,直到手动关闭": "After closing, the smart lock will be set to all-day open mode until manually closed",
|
||||||
"请输入小于1000的数字": "Please enter a number less than 1000",
|
"请输入小于或等于60的数字": "Please enter a number less than 60",
|
||||||
"操作成功": "Operation success",
|
"操作成功": "Operation success",
|
||||||
"管理员密码相同,无需修改": "The administrator password is the same and does not need to be modified",
|
"管理员密码相同,无需修改": "The administrator password is the same and does not need to be modified",
|
||||||
"修改密码": "Modify password",
|
"修改密码": "Modify password",
|
||||||
|
|||||||
@ -633,7 +633,7 @@
|
|||||||
"卡详情": "卡详情",
|
"卡详情": "卡详情",
|
||||||
"请输入": "请输入",
|
"请输入": "请输入",
|
||||||
"关闭后,智能锁将设置为全天常开模式,直到手动关闭": "关闭后,智能锁将设置为全天常开模式,直到手动关闭",
|
"关闭后,智能锁将设置为全天常开模式,直到手动关闭": "关闭后,智能锁将设置为全天常开模式,直到手动关闭",
|
||||||
"请输入小于1000的数字": "请输入小于1000的数字",
|
"请输入小于或等于60的数字": "请输入小于或等于60的数字",
|
||||||
"操作成功": "操作成功",
|
"操作成功": "操作成功",
|
||||||
"管理员密码相同,无需修改": "管理员密码相同,无需修改",
|
"管理员密码相同,无需修改": "管理员密码相同,无需修改",
|
||||||
"修改密码": "修改密码",
|
"修改密码": "修改密码",
|
||||||
|
|||||||
@ -608,7 +608,7 @@
|
|||||||
"卡详情": "卡详情",
|
"卡详情": "卡详情",
|
||||||
"请输入": "请输入",
|
"请输入": "请输入",
|
||||||
"关闭后,智能锁将设置为全天常开模式,直到手动关闭": "关闭后,智能锁将设置为全天常开模式,直到手动关闭",
|
"关闭后,智能锁将设置为全天常开模式,直到手动关闭": "关闭后,智能锁将设置为全天常开模式,直到手动关闭",
|
||||||
"请输入小于1000的数字": "请输入小于1000的数字",
|
"请输入小于或等于60的数字": "请输入小于或等于60的数字",
|
||||||
"操作成功": "操作成功",
|
"操作成功": "操作成功",
|
||||||
"管理员密码相同,无需修改": "管理员密码相同,无需修改",
|
"管理员密码相同,无需修改": "管理员密码相同,无需修改",
|
||||||
"修改密码": "修改密码",
|
"修改密码": "修改密码",
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||||
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsWithParameters.dart';
|
import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsWithParameters.dart';
|
||||||
|
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
||||||
import 'package:star_lock/tools/baseGetXController.dart';
|
import 'package:star_lock/tools/baseGetXController.dart';
|
||||||
import '../../../../blue/blue_manage.dart';
|
import '../../../../blue/blue_manage.dart';
|
||||||
import '../../../../blue/io_reply.dart';
|
import '../../../../blue/io_reply.dart';
|
||||||
@ -15,47 +16,50 @@ import '../../../../tools/eventBusEventManage.dart';
|
|||||||
import '../../../../tools/storage.dart';
|
import '../../../../tools/storage.dart';
|
||||||
import 'automaticBlocking_state.dart';
|
import 'automaticBlocking_state.dart';
|
||||||
|
|
||||||
class AutomaticBlockingLogic extends BaseGetXController{
|
class AutomaticBlockingLogic extends BaseGetXController {
|
||||||
final AutomaticBlockingState state = AutomaticBlockingState();
|
final AutomaticBlockingState state = AutomaticBlockingState();
|
||||||
|
|
||||||
void setAutoUnLock() async{
|
Future<void> setAutoUnLock() async {
|
||||||
String autoTime;
|
String autoTime;
|
||||||
if(state.isOpen.value == false){
|
if (state.isOpen.value == false) {
|
||||||
autoTime = "0";
|
autoTime = '0';
|
||||||
}else{
|
} else {
|
||||||
if(state.isCustomLockTime.value == true){
|
if (state.isCustomLockTime.value == true) {
|
||||||
autoTime = state.timeController.text;
|
autoTime = state.timeController.text;
|
||||||
if(int.parse(autoTime) >= 1000){
|
if (int.parse(autoTime) > 60) {
|
||||||
showToast("请输入小于1000的数字".tr);
|
showToast('请输入小于或等于60的数字'.tr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
autoTime = state.autoLockTime.value;
|
autoTime = state.autoLockTime.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var entity = await ApiRepository.to.setAutoUnlock(
|
final LoginEntity entity = await ApiRepository.to.setAutoUnlock(
|
||||||
lockId: state.lockSetInfoData.value.lockId!,
|
lockId: state.lockSetInfoData.value.lockId!,
|
||||||
autoLock:state.isOpen.value == true ? 1 : 0,
|
autoLock: state.isOpen.value == true ? 1 : 0,
|
||||||
autoLockSecond: int.parse(autoTime),
|
autoLockSecond: int.parse(autoTime),
|
||||||
);
|
);
|
||||||
if(entity.errorCode!.codeIsSuccessful){
|
if (entity.errorCode!.codeIsSuccessful) {
|
||||||
|
|
||||||
state.autoLockTime.value = autoTime;
|
state.autoLockTime.value = autoTime;
|
||||||
state.lockSetInfoData.value.lockSettingInfo!.autoLockSecond = int.parse(state.autoLockTime.value);
|
state.lockSetInfoData.value.lockSettingInfo!.autoLockSecond =
|
||||||
showToast("操作成功".tr, something: (){
|
int.parse(state.autoLockTime.value);
|
||||||
|
showToast('操作成功'.tr, something: () {
|
||||||
eventBus.fire(RefreshLockListInfoDataEvent());
|
eventBus.fire(RefreshLockListInfoDataEvent());
|
||||||
eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
eventBus
|
||||||
|
.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
||||||
Get.back();
|
Get.back();
|
||||||
});
|
}, maskType: EasyLoadingMaskType.clear);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取解析后的数据
|
// 获取解析后的数据
|
||||||
late StreamSubscription<Reply> _replySubscription;
|
late StreamSubscription<Reply> _replySubscription;
|
||||||
|
|
||||||
void _initReplySubscription() {
|
void _initReplySubscription() {
|
||||||
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) {
|
_replySubscription =
|
||||||
if(reply is SetSupportFunctionsWithParametersReply) {
|
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
||||||
|
if (reply is SetSupportFunctionsWithParametersReply) {
|
||||||
_replySetSupportFunctionsWithParameters(reply);
|
_replySetSupportFunctionsWithParameters(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,10 +90,10 @@ class AutomaticBlockingLogic extends BaseGetXController{
|
|||||||
|
|
||||||
// 设置自动落锁数据解析
|
// 设置自动落锁数据解析
|
||||||
Future<void> _replySetSupportFunctionsWithParameters(Reply reply) async {
|
Future<void> _replySetSupportFunctionsWithParameters(Reply reply) async {
|
||||||
int status = reply.data[2];
|
final int status = reply.data[2];
|
||||||
switch(status){
|
switch (status) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
//成功
|
//成功
|
||||||
state.sureBtnState.value = 0;
|
state.sureBtnState.value = 0;
|
||||||
cancelBlueConnetctToastTimer();
|
cancelBlueConnetctToastTimer();
|
||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
@ -106,34 +110,39 @@ class AutomaticBlockingLogic extends BaseGetXController{
|
|||||||
|
|
||||||
// 设置支持功能(带参数)
|
// 设置支持功能(带参数)
|
||||||
Future<void> sendAutoLock() async {
|
Future<void> sendAutoLock() async {
|
||||||
if(state.sureBtnState.value == 1){
|
if (state.sureBtnState.value == 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state.sureBtnState.value = 1;
|
state.sureBtnState.value = 1;
|
||||||
|
|
||||||
showEasyLoading();
|
showEasyLoading();
|
||||||
showBlueConnetctToastTimer(action: (){
|
showBlueConnetctToastTimer(action: () {
|
||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
state.sureBtnState.value = 0;
|
state.sureBtnState.value = 0;
|
||||||
});
|
});
|
||||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||||
|
(BluetoothConnectionState connectionState) async {
|
||||||
if (connectionState == BluetoothConnectionState.connected) {
|
if (connectionState == BluetoothConnectionState.connected) {
|
||||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
final List<String>? privateKey =
|
||||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
await Storage.getStringList(saveBluePrivateKey);
|
||||||
|
final List<int> getPrivateKeyList =
|
||||||
|
changeStringListToIntList(privateKey!);
|
||||||
|
|
||||||
var token = await Storage.getStringList(saveBlueToken);
|
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||||||
List<int> getTokenList = changeStringListToIntList(token!);
|
final List<int> getTokenList = changeStringListToIntList(token!);
|
||||||
|
|
||||||
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
final List<String>? publicKey =
|
||||||
List<int> getPublicKeyList = changeStringListToIntList(publicKey!);
|
await Storage.getStringList(saveBluePublicKey);
|
||||||
|
final List<int> getPublicKeyList =
|
||||||
|
changeStringListToIntList(publicKey!);
|
||||||
|
|
||||||
String autoTime;
|
String autoTime;
|
||||||
if(state.isOpen.value == false){
|
if (state.isOpen.value == false) {
|
||||||
autoTime = "0";
|
autoTime = '0';
|
||||||
}else{
|
} else {
|
||||||
if(state.isCustomLockTime.value == true){
|
if (state.isCustomLockTime.value == true) {
|
||||||
autoTime = state.timeController.text;
|
autoTime = state.timeController.text;
|
||||||
}else{
|
} else {
|
||||||
autoTime = state.autoLockTime.value;
|
autoTime = state.autoLockTime.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,7 +151,7 @@ class AutomaticBlockingLogic extends BaseGetXController{
|
|||||||
userID: await Storage.getUid(),
|
userID: await Storage.getUid(),
|
||||||
featureBit: 29,
|
featureBit: 29,
|
||||||
featureParaLength: 2,
|
featureParaLength: 2,
|
||||||
featureData: [int.parse(autoTime)],
|
featureData: <int>[int.parse(autoTime)],
|
||||||
token: getTokenList,
|
token: getTokenList,
|
||||||
needAuthor: 1,
|
needAuthor: 1,
|
||||||
publicKey: getPublicKeyList,
|
publicKey: getPublicKeyList,
|
||||||
@ -151,7 +160,7 @@ class AutomaticBlockingLogic extends BaseGetXController{
|
|||||||
dismissEasyLoading();
|
dismissEasyLoading();
|
||||||
cancelBlueConnetctToastTimer();
|
cancelBlueConnetctToastTimer();
|
||||||
state.sureBtnState.value = 0;
|
state.sureBtnState.value = 0;
|
||||||
if(state.ifCurrentScreen.value == true){
|
if (state.ifCurrentScreen.value == true) {
|
||||||
showBlueConnetctToast();
|
showBlueConnetctToast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,36 +168,42 @@ class AutomaticBlockingLogic extends BaseGetXController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ifCanNext() {
|
void ifCanNext() {
|
||||||
if(((state.isOpen.value != (state.lockSetInfoData.value.lockSettingInfo!.autoLock! == 1 ? true : false)) &&
|
final int autoLock = state.lockSetInfoData.value.lockSettingInfo!.autoLock!;
|
||||||
(state.autoLockTime.value != state.lockSetInfoData.value.lockSettingInfo!.autoLockSecond!.toString()) &&
|
final String autoLockSecond =
|
||||||
(state.isJustForShow.value == false)) || ((state.isOpen.value = true) && (state.lockSetInfoData.value.lockSettingInfo!.autoLock! == 1) &&
|
state.lockSetInfoData.value.lockSettingInfo!.autoLockSecond!.toString();
|
||||||
(state.autoLockTime.value != state.lockSetInfoData.value.lockSettingInfo!.autoLockSecond!.toString()) &&
|
final bool openLock = autoLock == 1;
|
||||||
(state.isJustForShow.value == false))){
|
final bool isNotJustForShow = state.isJustForShow.value == false;
|
||||||
|
final bool isEditAutoLockSecond =
|
||||||
|
state.autoLockTime.value != autoLockSecond;
|
||||||
|
|
||||||
|
if (!isNotJustForShow) {
|
||||||
|
//普通用户
|
||||||
|
state.canNext.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.isOpen.value != openLock || isEditAutoLockSecond) {
|
||||||
state.canNext.value = true;
|
state.canNext.value = true;
|
||||||
}else{
|
} else {
|
||||||
state.canNext.value = false;
|
state.canNext.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onReady() {
|
void onReady() {
|
||||||
// TODO: implement onReady
|
|
||||||
super.onReady();
|
super.onReady();
|
||||||
|
|
||||||
_initReplySubscription();
|
_initReplySubscription();
|
||||||
|
Storage.getAutomaticLockOffTime()
|
||||||
|
.then((String value) => state.timeController.text = value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
// TODO: implement onInit
|
|
||||||
super.onInit();
|
super.onInit();
|
||||||
|
|
||||||
// _readSupportFunctionsWithParameters();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onClose() {
|
void onClose() {
|
||||||
// TODO: implement onClose
|
|
||||||
super.onClose();
|
super.onClose();
|
||||||
_replySubscription.cancel();
|
_replySubscription.cancel();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,9 +4,10 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:star_lock/main/lockDetail/lockSet/automaticBlocking/automaticBlocking_state.dart';
|
||||||
|
import 'package:star_lock/tools/storage.dart';
|
||||||
|
|
||||||
import '../../../../app_settings/app_colors.dart';
|
import '../../../../app_settings/app_colors.dart';
|
||||||
import '../../../../blue/blue_manage.dart';
|
|
||||||
import '../../../../tools/appRouteObserver.dart';
|
import '../../../../tools/appRouteObserver.dart';
|
||||||
import '../../../../tools/commonItem.dart';
|
import '../../../../tools/commonItem.dart';
|
||||||
import '../../../../tools/showBottomSheetTool.dart';
|
import '../../../../tools/showBottomSheetTool.dart';
|
||||||
@ -22,9 +23,10 @@ class AutomaticBlockingPage extends StatefulWidget {
|
|||||||
State<AutomaticBlockingPage> createState() => _AutomaticBlockingPageState();
|
State<AutomaticBlockingPage> createState() => _AutomaticBlockingPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AutomaticBlockingPageState extends State<AutomaticBlockingPage> with RouteAware {
|
class _AutomaticBlockingPageState extends State<AutomaticBlockingPage>
|
||||||
final logic = Get.put(AutomaticBlockingLogic());
|
with RouteAware {
|
||||||
final state = Get.find<AutomaticBlockingLogic>().state;
|
final AutomaticBlockingLogic logic = Get.put(AutomaticBlockingLogic());
|
||||||
|
final AutomaticBlockingState state = Get.find<AutomaticBlockingLogic>().state;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -33,85 +35,90 @@ class _AutomaticBlockingPageState extends State<AutomaticBlockingPage> with Rout
|
|||||||
appBar: TitleAppBar(
|
appBar: TitleAppBar(
|
||||||
barTitle: TranslationLoader.lanKeys!.automaticBlocking!.tr,
|
barTitle: TranslationLoader.lanKeys!.automaticBlocking!.tr,
|
||||||
haveBack: true,
|
haveBack: true,
|
||||||
actionsList: [
|
actionsList: <Widget>[
|
||||||
Obx(() => TextButton(
|
Obx(() => TextButton(
|
||||||
onPressed: state.canNext.value == false ? null :() {
|
onPressed: state.canNext.value == false
|
||||||
// if(state.isJustForShow.value == true){
|
? null
|
||||||
// return;
|
: () {
|
||||||
// }
|
if (state.isOpen.value == false) {
|
||||||
// if(state.isCustomLockTime.value == true && state.timeController.text.isEmpty){
|
ShowTipView().showIosTipWithContentDialog(
|
||||||
// logic.showToast("请输入自定义时间");
|
'关闭后,智能锁将设置为全天常开模式,直到手动关闭'.tr,
|
||||||
// return;
|
logic.sendAutoLock);
|
||||||
// }
|
} else {
|
||||||
|
logic.sendAutoLock();
|
||||||
if(state.isOpen.value == false){
|
}
|
||||||
ShowTipView().showIosTipWithContentDialog('关闭后,智能锁将设置为全天常开模式,直到手动关闭'.tr, (){
|
},
|
||||||
logic.sendAutoLock();
|
child: Text(
|
||||||
});
|
state.canNext.value == false
|
||||||
}else{
|
? ''
|
||||||
logic.sendAutoLock();
|
: TranslationLoader.lanKeys!.save!.tr,
|
||||||
}
|
style: TextStyle(color: Colors.white, fontSize: 24.sp),
|
||||||
},
|
),
|
||||||
child: Text(
|
)),
|
||||||
state.canNext.value == false ? "" : TranslationLoader.lanKeys!.save!.tr,
|
|
||||||
style: TextStyle(color: Colors.white, fontSize: 24.sp),
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
],
|
],
|
||||||
backgroundColor: AppColors.mainColor),
|
backgroundColor: AppColors.mainColor),
|
||||||
body: ListView(
|
body: ListView(
|
||||||
children: [
|
children: <Widget>[
|
||||||
Obx(() => CommonItem(
|
Obx(
|
||||||
leftTitel: TranslationLoader.lanKeys!.automaticBlocking!.tr,
|
() => CommonItem(
|
||||||
isHaveLine: false,
|
leftTitel: TranslationLoader.lanKeys!.automaticBlocking!.tr,
|
||||||
isHaveRightWidget: true,
|
isHaveLine: false,
|
||||||
rightWidget:
|
isHaveRightWidget: true,
|
||||||
SizedBox(width: 60.w, height: 50.h, child: _switch())),),
|
rightWidget:
|
||||||
|
SizedBox(width: 60.w, height: 50.h, child: _switch())),
|
||||||
|
),
|
||||||
Visibility(
|
Visibility(
|
||||||
visible: state.isOpen.value == true ? true : false,
|
visible: state.isOpen.value == true,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: <Widget>[
|
||||||
Container(height: 10.h,),
|
Container(
|
||||||
Builder(builder: (context) {
|
height: 10.h,
|
||||||
|
),
|
||||||
|
Builder(builder: (BuildContext context) {
|
||||||
return Obx(() => CommonItem(
|
return Obx(() => CommonItem(
|
||||||
leftTitel: TranslationLoader.lanKeys!.delayTime!.tr,
|
leftTitel: TranslationLoader.lanKeys!.delayTime!.tr,
|
||||||
rightTitle: state.isCustomLockTime.value == true ? "自定义".tr : (state.autoLockTime.value.isNotEmpty && state.autoLockTime.value != "0") ? "${state.autoLockTime}s" : "",
|
rightTitle: state.isCustomLockTime.value == true
|
||||||
|
? '自定义'.tr
|
||||||
|
: (state.autoLockTime.value.isNotEmpty &&
|
||||||
|
state.autoLockTime.value != '0')
|
||||||
|
? '${state.autoLockTime}s'
|
||||||
|
: '',
|
||||||
isHaveLine: false,
|
isHaveLine: false,
|
||||||
isHaveDirection: true,
|
isHaveDirection: true,
|
||||||
action: () {
|
action: () {
|
||||||
if(state.isJustForShow.value == true){
|
if (state.isJustForShow.value == true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var list = [
|
final List<String> list = <String>[
|
||||||
"5",
|
'5',
|
||||||
"10",
|
'10',
|
||||||
"15",
|
'15',
|
||||||
"30",
|
'30',
|
||||||
"60",
|
'60',
|
||||||
TranslationLoader.lanKeys!.custom!.tr
|
TranslationLoader.lanKeys!.custom!.tr
|
||||||
];
|
];
|
||||||
ShowBottomSheetTool().showSingleRowPicker(
|
ShowBottomSheetTool().showSingleRowPicker(
|
||||||
//上下文
|
//上下文
|
||||||
context,
|
context,
|
||||||
//默认的索引
|
//默认的索引
|
||||||
normalIndex: 0,
|
normalIndex: 0,
|
||||||
title: TranslationLoader.lanKeys!.time!.tr,
|
title: TranslationLoader.lanKeys!.time!.tr,
|
||||||
cancelTitle: TranslationLoader.lanKeys!.cancel!.tr,
|
cancelTitle:
|
||||||
|
TranslationLoader.lanKeys!.cancel!.tr,
|
||||||
sureTitle: TranslationLoader.lanKeys!.sure!.tr,
|
sureTitle: TranslationLoader.lanKeys!.sure!.tr,
|
||||||
//要显示的列表
|
//要显示的列表
|
||||||
//可自定义数据适配器
|
|
||||||
//adapter: PickerAdapter(),
|
|
||||||
data: list,
|
data: list,
|
||||||
//选择事件的回调
|
//选择事件的回调
|
||||||
clickCallBack: (int index, var str) {
|
clickCallBack: (int index, Object str) {
|
||||||
if(index != 5){
|
if (index != 5) {
|
||||||
state.isCustomLockTime.value = false;
|
state.isCustomLockTime.value = false;
|
||||||
state.autoLockTime.value = str.toString();
|
state.autoLockTime.value = str.toString();
|
||||||
}else{
|
Storage.saveAutomaticLockOffTime(str.toString());
|
||||||
state.isCustomLockTime.value = true;
|
} else {
|
||||||
}
|
state.isCustomLockTime.value = true;
|
||||||
logic.ifCanNext();
|
}
|
||||||
});
|
logic.ifCanNext();
|
||||||
|
});
|
||||||
}));
|
}));
|
||||||
}),
|
}),
|
||||||
Container(height: 10.h),
|
Container(height: 10.h),
|
||||||
@ -122,37 +129,37 @@ class _AutomaticBlockingPageState extends State<AutomaticBlockingPage> with Rout
|
|||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
left: 30.w, top: 10.w, right: 30.w, bottom: 10.w),
|
left: 30.w, top: 10.w, right: 30.w, bottom: 10.w),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: <Widget>[
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: <Widget>[
|
||||||
Text(
|
Text(
|
||||||
"${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.time!.tr}(S)",
|
'${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.time!.tr}(S)',
|
||||||
style: TextStyle(fontSize: 24.sp),
|
style: TextStyle(fontSize: 24.sp),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Obx(() => TextField(
|
Obx(() => TextField(
|
||||||
//输入框一行
|
//输入框一行
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
controller: state.timeController,
|
controller: state.timeController,
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
autofocus: false,
|
autofocus: false,
|
||||||
readOnly: state.isJustForShow.value == true ? true : false,
|
readOnly: state.isJustForShow.value == true,
|
||||||
onChanged: (value) {
|
onChanged: (String value) {
|
||||||
state.autoLockTime.value = value;
|
state.autoLockTime.value = value;
|
||||||
logic.ifCanNext();
|
logic.ifCanNext();
|
||||||
},
|
},
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
//输入里面输入文字内边距设置
|
//输入里面输入文字内边距设置
|
||||||
contentPadding:
|
contentPadding: const EdgeInsets.only(
|
||||||
const EdgeInsets.only(top: 12.0, bottom: 8.0),
|
top: 12.0, bottom: 8.0),
|
||||||
hintText:
|
hintText:
|
||||||
"${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.time!.tr}(S)",
|
'${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.time!.tr}(S)',
|
||||||
hintStyle: TextStyle(fontSize: 24.sp),
|
hintStyle: TextStyle(fontSize: 24.sp),
|
||||||
//不需要输入框下划线
|
//不需要输入框下划线
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
Container(
|
Container(
|
||||||
height: 0.5.h,
|
height: 0.5.h,
|
||||||
color: Colors.grey,
|
color: Colors.grey,
|
||||||
@ -167,7 +174,7 @@ class _AutomaticBlockingPageState extends State<AutomaticBlockingPage> with Rout
|
|||||||
padding: EdgeInsets.all(30.w),
|
padding: EdgeInsets.all(30.w),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [
|
children: <Widget>[
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
TranslationLoader.lanKeys!.automaticBlockingTip!.tr,
|
TranslationLoader.lanKeys!.automaticBlockingTip!.tr,
|
||||||
@ -186,21 +193,19 @@ class _AutomaticBlockingPageState extends State<AutomaticBlockingPage> with Rout
|
|||||||
trackColor: CupertinoColors.systemGrey5,
|
trackColor: CupertinoColors.systemGrey5,
|
||||||
thumbColor: CupertinoColors.white,
|
thumbColor: CupertinoColors.white,
|
||||||
value: state.isOpen.value,
|
value: state.isOpen.value,
|
||||||
onChanged: state.isJustForShow.value == true ? null : (value){
|
onChanged: state.isJustForShow.value == true
|
||||||
setState(() {
|
? null
|
||||||
state.isOpen.value = value;
|
: (bool value) {
|
||||||
if(state.isOpen.value == false){
|
setState(() {
|
||||||
state.autoLockTime.value = "";
|
state.isOpen.value = value;
|
||||||
}
|
logic.ifCanNext();
|
||||||
logic.ifCanNext();
|
});
|
||||||
});
|
},
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
// TODO: implement didChangeDependencies
|
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
|
|
||||||
/// 路由订阅
|
/// 路由订阅
|
||||||
@ -209,7 +214,6 @@ class _AutomaticBlockingPageState extends State<AutomaticBlockingPage> with Rout
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
// TODO: implement dispose
|
|
||||||
/// 取消路由订阅
|
/// 取消路由订阅
|
||||||
AppRouteObserver().routeObserver.unsubscribe(this);
|
AppRouteObserver().routeObserver.unsubscribe(this);
|
||||||
super.dispose();
|
super.dispose();
|
||||||
@ -227,7 +231,9 @@ class _AutomaticBlockingPageState extends State<AutomaticBlockingPage> with Rout
|
|||||||
void didPop() {
|
void didPop() {
|
||||||
super.didPop();
|
super.didPop();
|
||||||
logic.cancelBlueConnetctToastTimer();
|
logic.cancelBlueConnetctToastTimer();
|
||||||
if (EasyLoading.isShow) EasyLoading.dismiss(animation: true);
|
if (EasyLoading.isShow) {
|
||||||
|
EasyLoading.dismiss(animation: true);
|
||||||
|
}
|
||||||
state.ifCurrentScreen.value = false;
|
state.ifCurrentScreen.value = false;
|
||||||
state.sureBtnState.value = 0;
|
state.sureBtnState.value = 0;
|
||||||
}
|
}
|
||||||
@ -244,9 +250,10 @@ class _AutomaticBlockingPageState extends State<AutomaticBlockingPage> with Rout
|
|||||||
void didPushNext() {
|
void didPushNext() {
|
||||||
super.didPushNext();
|
super.didPushNext();
|
||||||
logic.cancelBlueConnetctToastTimer();
|
logic.cancelBlueConnetctToastTimer();
|
||||||
if (EasyLoading.isShow) EasyLoading.dismiss(animation: true);
|
if (EasyLoading.isShow) {
|
||||||
|
EasyLoading.dismiss(animation: true);
|
||||||
|
}
|
||||||
state.ifCurrentScreen.value = false;
|
state.ifCurrentScreen.value = false;
|
||||||
state.sureBtnState.value = 0;
|
state.sureBtnState.value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -98,8 +98,11 @@ class BaseGetXController extends GetxController {
|
|||||||
"${'操作失败,请确认锁是否在附近,或重启手机蓝牙后再试。'.tr}${isContains == true ? "如果是全自动锁,请使屏幕变亮" : ""}");
|
"${'操作失败,请确认锁是否在附近,或重启手机蓝牙后再试。'.tr}${isContains == true ? "如果是全自动锁,请使屏幕变亮" : ""}");
|
||||||
}
|
}
|
||||||
|
|
||||||
void showToast(String status, {Function? something}) {
|
void showToast(String status,
|
||||||
EasyLoading.showToast(status, duration: 2000.milliseconds);
|
{Function? something,
|
||||||
|
EasyLoadingMaskType maskType = EasyLoadingMaskType.none}) {
|
||||||
|
EasyLoading.showToast(status,
|
||||||
|
duration: 2000.milliseconds, maskType: maskType);
|
||||||
if (something != null) {
|
if (something != null) {
|
||||||
delay(duration: 2100.milliseconds, something: something);
|
delay(duration: 2100.milliseconds, something: something);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,37 +8,35 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
import '../login/login/entity/LoginData.dart';
|
import '../login/login/entity/LoginData.dart';
|
||||||
import '../main/lockMian/entity/lockListInfo_entity.dart';
|
import '../main/lockMian/entity/lockListInfo_entity.dart';
|
||||||
|
|
||||||
const saveBluePublicKey = "BluePublicKey";
|
const String saveBluePublicKey = 'BluePublicKey';
|
||||||
const saveBluePrivateKey = "BluePrivateKey";
|
const String saveBluePrivateKey = 'BluePrivateKey';
|
||||||
const saveBlueSignKey = "BlueSignKey";
|
const String saveBlueSignKey = 'BlueSignKey';
|
||||||
const saveBlueToken = "BlueGetToken";
|
const String saveBlueToken = 'BlueGetToken';
|
||||||
const currentConnectionLockId = "CurrentConnectionLockId";
|
const String currentConnectionLockId = 'CurrentConnectionLockId';
|
||||||
const currentConnectionMacAddress = "CurrentConnectionMacAddress";
|
const String currentConnectionMacAddress = 'CurrentConnectionMacAddress';
|
||||||
const ifIsDemoModeOrNot = "IfIsDemoModeOrNot";
|
const String ifIsDemoModeOrNot = 'IfIsDemoModeOrNot';
|
||||||
const isAgreePrivacy = "isAgreePrivacy"; //是否同意隐私协议弹窗
|
const String isAgreePrivacy = 'isAgreePrivacy'; //是否同意隐私协议弹窗
|
||||||
const isAgreePosition = "isAgreePosition"; //是否同意获取位置弹窗
|
const String isAgreePosition = 'isAgreePosition'; //是否同意获取位置弹窗
|
||||||
const isAgreeCamera = "isAgreeCamera"; //是否同意获取相机/相册弹窗
|
const String isAgreeCamera = 'isAgreeCamera'; //是否同意获取相机/相册弹窗
|
||||||
|
|
||||||
const isShowUpdateVersion = "isShowUpdateVersion"; //是否更新弹窗
|
const String isShowUpdateVersion = 'isShowUpdateVersion'; //是否更新弹窗
|
||||||
const saveLockAlias = "saveLockAlias"; //锁别名
|
const String saveLockAlias = 'saveLockAlias'; //锁别名
|
||||||
const pushDeviceID = 'pushDeviceID'; //推送设备ID
|
const String pushDeviceID = 'pushDeviceID'; //推送设备ID
|
||||||
const saveIsVip = "saveIsVip"; //是否是VIP
|
const String saveIsVip = 'saveIsVip'; //是否是VIP
|
||||||
|
|
||||||
const saveUserLoginData = "userLoginData";
|
const String saveUserLoginData = 'userLoginData';
|
||||||
const saveLockMainListData = "lockMainListData";
|
const String saveLockMainListData = 'lockMainListData';
|
||||||
const isOpenDeBug = "isOpenDeBug"; //是否打开 debug
|
const String isOpenDeBug = 'isOpenDeBug'; //是否打开 debug
|
||||||
|
const String automaticLockOffTime = 'automaticLockOffTime'; //自动关锁时间
|
||||||
|
|
||||||
class Storage {
|
class Storage {
|
||||||
Storage._internal();
|
|
||||||
|
|
||||||
factory Storage() => _instance;
|
factory Storage() => _instance;
|
||||||
|
|
||||||
|
Storage._internal();
|
||||||
|
|
||||||
static late final Storage _instance = Storage._internal();
|
static late final Storage _instance = Storage._internal();
|
||||||
|
|
||||||
static late SharedPreferences _preferences;
|
|
||||||
|
|
||||||
static Future<Storage> getInstance() async {
|
static Future<Storage> getInstance() async {
|
||||||
_preferences = await SharedPreferences.getInstance();
|
|
||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,127 +71,124 @@ class Storage {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// int
|
// int
|
||||||
static Future<void> setInt(key, value) async {
|
static Future<void> setInt(String key, dynamic value) async {
|
||||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
final SharedPreferences sp = await SharedPreferences.getInstance();
|
||||||
sp.setInt(key, value);
|
sp.setInt(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<int?> getInt(key) async {
|
static Future<int?> getInt(String key) async {
|
||||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
final SharedPreferences sp = await SharedPreferences.getInstance();
|
||||||
return sp.getInt(key);
|
return sp.getInt(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool
|
// bool
|
||||||
static Future<void> setBool(key, value) async {
|
static Future<void> setBool(String key, dynamic value) async {
|
||||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
final SharedPreferences sp = await SharedPreferences.getInstance();
|
||||||
sp.setBool(key, value);
|
sp.setBool(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool?> getBool(key) async {
|
static Future<bool?> getBool(String key) async {
|
||||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
final SharedPreferences sp = await SharedPreferences.getInstance();
|
||||||
return sp.getBool(key);
|
return sp.getBool(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// double
|
// double
|
||||||
static Future<void> setDouble(key, value) async {
|
static Future<void> setDouble(String key, dynamic value) async {
|
||||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
final SharedPreferences sp = await SharedPreferences.getInstance();
|
||||||
sp.setDouble(key, value);
|
sp.setDouble(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<double?> getDouble(key) async {
|
static Future<double?> getDouble(String key) async {
|
||||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
final SharedPreferences sp = await SharedPreferences.getInstance();
|
||||||
return sp.getDouble(key);
|
return sp.getDouble(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// string
|
// string
|
||||||
static Future<void> setString(key, value) async {
|
static Future<void> setString(String key, dynamic value) async {
|
||||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
final SharedPreferences sp = await SharedPreferences.getInstance();
|
||||||
sp.setString(key, value);
|
sp.setString(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String?> getString(key) async {
|
static Future<String?> getString(String key) async {
|
||||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
final SharedPreferences sp = await SharedPreferences.getInstance();
|
||||||
return sp.getString(key);
|
return sp.getString(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 字符串数组
|
// 字符串数组
|
||||||
static Future<void> setStringList(key, value) async {
|
static Future<void> setStringList(String key, dynamic value) async {
|
||||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
final SharedPreferences sp = await SharedPreferences.getInstance();
|
||||||
sp.setStringList(key, value);
|
sp.setStringList(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<List<String>?> getStringList(key) async {
|
static Future<List<String>?> getStringList(String key) async {
|
||||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
final SharedPreferences sp = await SharedPreferences.getInstance();
|
||||||
return sp.getStringList(key);
|
return sp.getStringList(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断本地是否包含某个key
|
// 判断本地是否包含某个key
|
||||||
static Future<bool> ifHaveKey(key) async {
|
static Future<bool> ifHaveKey(String key) async {
|
||||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
final SharedPreferences sp = await SharedPreferences.getInstance();
|
||||||
bool isContainKey = sp.containsKey(key) ?? false;
|
final bool isContainKey = sp.containsKey(key);
|
||||||
// AppLog.log(isContainKey);
|
// AppLog.log(isContainKey);
|
||||||
return isContainKey;
|
return isContainKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 移除数据
|
// 移除数据
|
||||||
static Future<void> removeData(key) async {
|
static Future<void> removeData(String key) async {
|
||||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
final SharedPreferences sp = await SharedPreferences.getInstance();
|
||||||
sp.remove(key);
|
sp.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 移除所有的键值对
|
// 移除所有的键值对
|
||||||
static Future<void> clearAll() async {
|
static Future<void> clearAll() async {
|
||||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
final SharedPreferences sp = await SharedPreferences.getInstance();
|
||||||
sp.clear();
|
sp.clear();
|
||||||
|
|
||||||
// 重新设置需要保留的数据
|
// 重新设置需要保留的数据
|
||||||
if (isAgreePrivacy != null) {
|
//退出登录不清除隐私协议同意状态
|
||||||
//退出登录不清除隐私协议同意状态
|
await setString(isAgreePrivacy, isAgreePrivacy);
|
||||||
await setString(isAgreePrivacy, isAgreePrivacy);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String?> getUid() async {
|
static Future<String?> getUid() async {
|
||||||
LoginData? loginData = await getLoginData();
|
final LoginData? loginData = await getLoginData();
|
||||||
String? uid = loginData!.uid.toString();
|
final String uid = loginData!.uid.toString();
|
||||||
// AppLog.log("pubUid:$uid");
|
// AppLog.log("pubUid:$uid");
|
||||||
return uid;
|
return uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String?> getUserid() async {
|
static Future<String?> getUserid() async {
|
||||||
LoginData? loginData = await getLoginData();
|
final LoginData? loginData = await getLoginData();
|
||||||
String? userid = loginData!.userid.toString();
|
final String userid = loginData!.userid.toString();
|
||||||
// AppLog.log("pubUid:$uid");
|
// AppLog.log("pubUid:$uid");
|
||||||
return userid;
|
return userid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String?> getMobile() async {
|
static Future<String?> getMobile() async {
|
||||||
LoginData? loginData = await getLoginData();
|
final LoginData? loginData = await getLoginData();
|
||||||
String? mobile = loginData!.mobile;
|
final String? mobile = loginData!.mobile;
|
||||||
return mobile ?? '';
|
return mobile ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String?> getEmail() async {
|
static Future<String?> getEmail() async {
|
||||||
LoginData? loginData = await getLoginData();
|
final LoginData? loginData = await getLoginData();
|
||||||
String? email = loginData!.email;
|
final String? email = loginData!.email;
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String?> getNickname() async {
|
static Future<String?> getNickname() async {
|
||||||
LoginData? loginData = await getLoginData();
|
final LoginData? loginData = await getLoginData();
|
||||||
String? nickname = loginData!.nickname;
|
final String? nickname = loginData!.nickname;
|
||||||
return nickname;
|
return nickname;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String?> getHeadUrl() async {
|
static Future<String?> getHeadUrl() async {
|
||||||
LoginData? loginData = await getLoginData();
|
final LoginData? loginData = await getLoginData();
|
||||||
String? headUrl = loginData!.headUrl;
|
final String? headUrl = loginData!.headUrl;
|
||||||
return headUrl;
|
return headUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<LoginData?> getLoginData() async {
|
static Future<LoginData?> getLoginData() async {
|
||||||
LoginData? loginData;
|
LoginData? loginData;
|
||||||
final data = await Storage.getString(saveUserLoginData);
|
final String? data = await Storage.getString(saveUserLoginData);
|
||||||
if (data != null && data.isNotEmpty) {
|
if (data != null && data.isNotEmpty) {
|
||||||
loginData = LoginData.fromJson(jsonDecode(data));
|
loginData = LoginData.fromJson(jsonDecode(data));
|
||||||
}
|
}
|
||||||
@ -211,11 +206,21 @@ class Storage {
|
|||||||
|
|
||||||
static Future<LockListInfoGroupEntity?> getLockMainListData() async {
|
static Future<LockListInfoGroupEntity?> getLockMainListData() async {
|
||||||
LockListInfoGroupEntity? lockListInfoGroupEntity;
|
LockListInfoGroupEntity? lockListInfoGroupEntity;
|
||||||
final data = await Storage.getString(saveLockMainListData);
|
final String? data = await Storage.getString(saveLockMainListData);
|
||||||
if (data != null && data.isNotEmpty) {
|
if (data != null && data.isNotEmpty) {
|
||||||
lockListInfoGroupEntity =
|
lockListInfoGroupEntity =
|
||||||
LockListInfoGroupEntity.fromJson(jsonDecode(data));
|
LockListInfoGroupEntity.fromJson(jsonDecode(data));
|
||||||
}
|
}
|
||||||
return lockListInfoGroupEntity;
|
return lockListInfoGroupEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//设置自动关锁时间
|
||||||
|
static Future<void> saveAutomaticLockOffTime(String data) async {
|
||||||
|
await Storage.setString(automaticLockOffTime, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<String> getAutomaticLockOffTime() async {
|
||||||
|
final String data = await Storage.getString(automaticLockOffTime) ?? '0';
|
||||||
|
return data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:star_lock/app_settings/app_settings.dart';
|
import 'package:star_lock/app_settings/app_settings.dart';
|
||||||
@ -7,7 +6,7 @@ import 'package:star_lock/tools/storage.dart';
|
|||||||
import 'package:star_lock/translations/trans_lib.dart';
|
import 'package:star_lock/translations/trans_lib.dart';
|
||||||
|
|
||||||
class PermissionDialog {
|
class PermissionDialog {
|
||||||
static Map<Permission, String> titles = {
|
static Map<Permission, String> titles = <Permission, String>{
|
||||||
Permission.camera: '相机'.tr,
|
Permission.camera: '相机'.tr,
|
||||||
Permission.photos: '相册'.tr,
|
Permission.photos: '相册'.tr,
|
||||||
Permission.storage: '读写'.tr,
|
Permission.storage: '读写'.tr,
|
||||||
@ -17,7 +16,7 @@ class PermissionDialog {
|
|||||||
Permission.bluetoothConnect: '蓝牙'.tr,
|
Permission.bluetoothConnect: '蓝牙'.tr,
|
||||||
};
|
};
|
||||||
|
|
||||||
static Map<Permission, String> contents = {
|
static Map<Permission, String> contents = <Permission, String>{
|
||||||
Permission.camera: '需要访问相机权限才能拍照上传文件例如头像上传'.tr,
|
Permission.camera: '需要访问相机权限才能拍照上传文件例如头像上传'.tr,
|
||||||
Permission.photos: '需要访问相机权限才能使用相册图片上传文件上传头像'.tr,
|
Permission.photos: '需要访问相机权限才能使用相册图片上传文件上传头像'.tr,
|
||||||
Permission.storage: '需要访问读写权限才能使用本地图片上传头像'.tr,
|
Permission.storage: '需要访问读写权限才能使用本地图片上传头像'.tr,
|
||||||
@ -32,18 +31,18 @@ class PermissionDialog {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool application = true;
|
bool application = true;
|
||||||
List<Permission> permissions = [
|
final List<Permission> permissions = <Permission>[
|
||||||
Permission.bluetooth,
|
Permission.bluetooth,
|
||||||
Permission.bluetoothScan,
|
Permission.bluetoothScan,
|
||||||
Permission.bluetoothConnect,
|
Permission.bluetoothConnect,
|
||||||
];
|
];
|
||||||
Future<bool> getPermissionStatus(List<Permission> permissions) async {
|
Future<bool> getPermissionStatus(List<Permission> permissions) async {
|
||||||
bool isGranted = true;
|
bool isGranted = true;
|
||||||
List<PermissionStatus> permissionStatus = [];
|
final List<PermissionStatus> permissionStatus = <PermissionStatus>[];
|
||||||
for (Permission per in permissions) {
|
for (final Permission per in permissions) {
|
||||||
permissionStatus.add(await per.status);
|
permissionStatus.add(await per.status);
|
||||||
}
|
}
|
||||||
for (PermissionStatus per in permissionStatus) {
|
for (final PermissionStatus per in permissionStatus) {
|
||||||
isGranted = isGranted && per.isGranted;
|
isGranted = isGranted && per.isGranted;
|
||||||
}
|
}
|
||||||
if (GetPlatform.isIOS) {
|
if (GetPlatform.isIOS) {
|
||||||
@ -52,19 +51,19 @@ class PermissionDialog {
|
|||||||
return isGranted;
|
return isGranted;
|
||||||
}
|
}
|
||||||
|
|
||||||
Permission permission = Permission.bluetoothScan;
|
const Permission permission = Permission.bluetoothScan;
|
||||||
dynamic cache = await Storage.getString(titles[permission]);
|
final dynamic cache = await Storage.getString(titles[permission]!);
|
||||||
bool isGranted = await getPermissionStatus(permissions);
|
final bool isGranted = await getPermissionStatus(permissions);
|
||||||
if (GetPlatform.isAndroid && !isGranted && cache is! String) {
|
if (GetPlatform.isAndroid && !isGranted && cache is! String) {
|
||||||
application = await showCupertinoDialog(
|
application = await showCupertinoDialog(
|
||||||
context: Get.context!,
|
context: Get.context!,
|
||||||
builder: (context) {
|
builder: (BuildContext context) {
|
||||||
return PopScope(
|
return PopScope(
|
||||||
canPop: false,
|
canPop: false,
|
||||||
child: CupertinoAlertDialog(
|
child: CupertinoAlertDialog(
|
||||||
title: Text('${'申请'.tr}${titles[permission] ?? ''}${'权限'.tr}'),
|
title: Text('${'申请'.tr}${titles[permission] ?? ''}${'权限'.tr}'),
|
||||||
content: Text(contents[permission] ?? ''),
|
content: Text(contents[permission] ?? ''),
|
||||||
actions: [
|
actions: <Widget>[
|
||||||
CupertinoDialogAction(
|
CupertinoDialogAction(
|
||||||
child: Text('不允许'.tr),
|
child: Text('不允许'.tr),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -83,12 +82,12 @@ class PermissionDialog {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (application) {
|
if (application) {
|
||||||
await Storage.setString(titles[permission], titles[permission]);
|
await Storage.setString(titles[permission]!, titles[permission]);
|
||||||
}
|
}
|
||||||
} else if (cache is! String) {
|
} else if (cache is! String) {
|
||||||
await Storage.setString(titles[permission], titles[permission]);
|
await Storage.setString(titles[permission]!, titles[permission]);
|
||||||
} else {
|
} else {
|
||||||
bool isGranted = await getPermissionStatus(permissions);
|
final bool isGranted = await getPermissionStatus(permissions);
|
||||||
if (!isGranted) {
|
if (!isGranted) {
|
||||||
showSet(permission);
|
showSet(permission);
|
||||||
return false;
|
return false;
|
||||||
@ -96,7 +95,7 @@ class PermissionDialog {
|
|||||||
}
|
}
|
||||||
if (application) {
|
if (application) {
|
||||||
await permissions.request();
|
await permissions.request();
|
||||||
bool isGranted = await getPermissionStatus(permissions);
|
final bool isGranted = await getPermissionStatus(permissions);
|
||||||
return isGranted;
|
return isGranted;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -107,20 +106,20 @@ class PermissionDialog {
|
|||||||
if (Get.context == null) {
|
if (Get.context == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool isAndroid33 =
|
final bool isAndroid33 =
|
||||||
AppPlatform.isAndroid && AppPlatform.getSdkIntValue() >= 33;
|
AppPlatform.isAndroid && AppPlatform.getSdkIntValue() >= 33;
|
||||||
|
|
||||||
//通用的局部函数
|
//通用的局部函数
|
||||||
List<Permission> requestPermission() {
|
List<Permission> requestPermission() {
|
||||||
List<Permission> permissions;
|
List<Permission> permissions;
|
||||||
if (isAndroid33) {
|
if (isAndroid33) {
|
||||||
permissions = [
|
permissions = <Permission>[
|
||||||
Permission.mediaLibrary,
|
Permission.mediaLibrary,
|
||||||
Permission.photos,
|
Permission.photos,
|
||||||
Permission.videos,
|
Permission.videos,
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
permissions = [
|
permissions = <Permission>[
|
||||||
Permission.storage,
|
Permission.storage,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -129,7 +128,7 @@ class PermissionDialog {
|
|||||||
|
|
||||||
Future<bool> permissionStatus(List<Permission> permissions) async {
|
Future<bool> permissionStatus(List<Permission> permissions) async {
|
||||||
bool isGranted = true;
|
bool isGranted = true;
|
||||||
for (Permission permission in permissions) {
|
for (final Permission permission in permissions) {
|
||||||
isGranted =
|
isGranted =
|
||||||
isGranted && (await permission.status) == PermissionStatus.granted;
|
isGranted && (await permission.status) == PermissionStatus.granted;
|
||||||
}
|
}
|
||||||
@ -142,20 +141,20 @@ class PermissionDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool application = true;
|
bool application = true;
|
||||||
Permission permission = Permission.photos;
|
const Permission permission = Permission.photos;
|
||||||
List<Permission> permissions = requestPermission();
|
final List<Permission> permissions = requestPermission();
|
||||||
dynamic cache = await Storage.getString(titles[permission]);
|
final dynamic cache = await Storage.getString(titles[permission]??'');
|
||||||
bool isGranted = await permissionStatus(permissions);
|
final bool isGranted = await permissionStatus(permissions);
|
||||||
if (AppPlatform.isAndroid && !isGranted && cache is! String) {
|
if (AppPlatform.isAndroid && !isGranted && cache is! String) {
|
||||||
application = await showCupertinoDialog(
|
application = await showCupertinoDialog(
|
||||||
context: Get.context!,
|
context: Get.context!,
|
||||||
builder: (context) {
|
builder: (BuildContext context) {
|
||||||
return PopScope(
|
return PopScope(
|
||||||
canPop: false,
|
canPop: false,
|
||||||
child: CupertinoAlertDialog(
|
child: CupertinoAlertDialog(
|
||||||
title: Text('${'申请'.tr}${titles[permission] ?? ''}${'权限'.tr}'),
|
title: Text('${'申请'.tr}${titles[permission] ?? ''}${'权限'.tr}'),
|
||||||
content: Text(contents[permission] ?? ''),
|
content: Text(contents[permission] ?? ''),
|
||||||
actions: [
|
actions: <Widget>[
|
||||||
CupertinoDialogAction(
|
CupertinoDialogAction(
|
||||||
child: Text('不允许'.tr),
|
child: Text('不允许'.tr),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -173,18 +172,18 @@ class PermissionDialog {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (application) {
|
if (application) {
|
||||||
await Storage.setString(titles[permission], titles[permission]);
|
await Storage.setString(titles[permission]!, titles[permission]);
|
||||||
}
|
}
|
||||||
} else if (cache is String) {
|
} else if (cache is String) {
|
||||||
bool isDenied = !(await permissionStatus(permissions));
|
final bool isDenied = !(await permissionStatus(permissions));
|
||||||
if (isDenied) {
|
if (isDenied) {
|
||||||
showSet(permission);
|
showSet(permission);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (application) {
|
if (application) {
|
||||||
Map<Permission, PermissionStatus> statuses = await permissions.request();
|
final Map<Permission, PermissionStatus> statuses = await permissions.request();
|
||||||
bool isGranted = await permissionStatus(statuses.keys.toList());
|
final bool isGranted = await permissionStatus(statuses.keys.toList());
|
||||||
return isGranted;
|
return isGranted;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -195,14 +194,14 @@ class PermissionDialog {
|
|||||||
if (Get.context == null) {
|
if (Get.context == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool isAndroid33 =
|
final bool isAndroid33 =
|
||||||
AppPlatform.isAndroid && AppPlatform.getSdkIntValue() >= 33;
|
AppPlatform.isAndroid && AppPlatform.getSdkIntValue() >= 33;
|
||||||
|
|
||||||
//通用的局部函数
|
//通用的局部函数
|
||||||
List<Permission> requestPermission() {
|
List<Permission> requestPermission() {
|
||||||
List<Permission> permissions;
|
List<Permission> permissions;
|
||||||
if (isAndroid33) {
|
if (isAndroid33) {
|
||||||
permissions = [
|
permissions = <Permission>[
|
||||||
Permission.mediaLibrary,
|
Permission.mediaLibrary,
|
||||||
Permission.photos,
|
Permission.photos,
|
||||||
// Permission.audio,
|
// Permission.audio,
|
||||||
@ -210,7 +209,7 @@ class PermissionDialog {
|
|||||||
Permission.manageExternalStorage,
|
Permission.manageExternalStorage,
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
permissions = [
|
permissions = <Permission>[
|
||||||
Permission.storage,
|
Permission.storage,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -219,7 +218,7 @@ class PermissionDialog {
|
|||||||
|
|
||||||
Future<bool> permissionStatus(List<Permission> permissions) async {
|
Future<bool> permissionStatus(List<Permission> permissions) async {
|
||||||
bool isGranted = true;
|
bool isGranted = true;
|
||||||
for (Permission permission in permissions) {
|
for (final Permission permission in permissions) {
|
||||||
isGranted =
|
isGranted =
|
||||||
isGranted && (await permission.status) == PermissionStatus.granted;
|
isGranted && (await permission.status) == PermissionStatus.granted;
|
||||||
}
|
}
|
||||||
@ -234,20 +233,20 @@ class PermissionDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool application = true;
|
bool application = true;
|
||||||
Permission permission = Permission.photos;
|
const Permission permission = Permission.photos;
|
||||||
List<Permission> permissions = requestPermission();
|
final List<Permission> permissions = requestPermission();
|
||||||
dynamic cache = await Storage.getString(titles[permission]);
|
final dynamic cache = await Storage.getString(titles[permission]??'');
|
||||||
bool isGranted = await permissionStatus(permissions);
|
final bool isGranted = await permissionStatus(permissions);
|
||||||
if (AppPlatform.isAndroid && !isGranted && cache is! String) {
|
if (AppPlatform.isAndroid && !isGranted && cache is! String) {
|
||||||
application = await showCupertinoDialog(
|
application = await showCupertinoDialog(
|
||||||
context: Get.context!,
|
context: Get.context!,
|
||||||
builder: (context) {
|
builder: (BuildContext context) {
|
||||||
return PopScope(
|
return PopScope(
|
||||||
canPop: false,
|
canPop: false,
|
||||||
child: CupertinoAlertDialog(
|
child: CupertinoAlertDialog(
|
||||||
title: Text('${'申请'.tr}${titles[permission] ?? ''}${'权限'.tr}'),
|
title: Text('${'申请'.tr}${titles[permission] ?? ''}${'权限'.tr}'),
|
||||||
content: Text('需要访问读写权限才能使用手动升级固件'.tr),
|
content: Text('需要访问读写权限才能使用手动升级固件'.tr),
|
||||||
actions: [
|
actions: <Widget>[
|
||||||
CupertinoDialogAction(
|
CupertinoDialogAction(
|
||||||
child: Text('不允许'.tr),
|
child: Text('不允许'.tr),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -265,18 +264,18 @@ class PermissionDialog {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (application) {
|
if (application) {
|
||||||
await Storage.setString(titles[permission], titles[permission]);
|
await Storage.setString(titles[permission]??'', titles[permission]);
|
||||||
}
|
}
|
||||||
} else if (cache is String) {
|
} else if (cache is String) {
|
||||||
bool isDenied = !(await permissionStatus(permissions));
|
final bool isDenied = !(await permissionStatus(permissions));
|
||||||
if (isDenied) {
|
if (isDenied) {
|
||||||
showSet(permission);
|
showSet(permission);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (application) {
|
if (application) {
|
||||||
Map<Permission, PermissionStatus> statuses = await permissions.request();
|
final Map<Permission, PermissionStatus> statuses = await permissions.request();
|
||||||
bool isGranted = await permissionStatus(statuses.keys.toList());
|
final bool isGranted = await permissionStatus(statuses.keys.toList());
|
||||||
return isGranted;
|
return isGranted;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -288,18 +287,18 @@ class PermissionDialog {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool application = true;
|
bool application = true;
|
||||||
PermissionStatus status = await permission.status;
|
final PermissionStatus status = await permission.status;
|
||||||
dynamic cache = await Storage.getString(titles[permission]);
|
final dynamic cache = await Storage.getString(titles[permission]??'');
|
||||||
if (AppPlatform.isAndroid && !status.isGranted && cache is! String) {
|
if (AppPlatform.isAndroid && !status.isGranted && cache is! String) {
|
||||||
application = await showCupertinoDialog(
|
application = await showCupertinoDialog(
|
||||||
context: Get.context!,
|
context: Get.context!,
|
||||||
builder: (context) {
|
builder: (BuildContext context) {
|
||||||
return PopScope(
|
return PopScope(
|
||||||
canPop: false,
|
canPop: false,
|
||||||
child: CupertinoAlertDialog(
|
child: CupertinoAlertDialog(
|
||||||
title: Text('${'申请'.tr}${titles[permission] ?? ''}${'权限'.tr}'),
|
title: Text('${'申请'.tr}${titles[permission] ?? ''}${'权限'.tr}'),
|
||||||
content: Text(content ?? contents[permission] ?? ''),
|
content: Text(content ?? contents[permission] ?? ''),
|
||||||
actions: [
|
actions: <Widget>[
|
||||||
CupertinoDialogAction(
|
CupertinoDialogAction(
|
||||||
child: Text('不允许'.tr),
|
child: Text('不允许'.tr),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -317,7 +316,7 @@ class PermissionDialog {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (application) {
|
if (application) {
|
||||||
await Storage.setString(titles[permission], titles[permission]);
|
await Storage.setString(titles[permission]??'', titles[permission]);
|
||||||
}
|
}
|
||||||
} else if (cache is String) {
|
} else if (cache is String) {
|
||||||
if (status.isDenied) {
|
if (status.isDenied) {
|
||||||
@ -326,7 +325,7 @@ class PermissionDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (application) {
|
if (application) {
|
||||||
PermissionStatus status = await permission.request();
|
final PermissionStatus status = await permission.request();
|
||||||
return status.isGranted;
|
return status.isGranted;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -339,14 +338,14 @@ class PermissionDialog {
|
|||||||
}
|
}
|
||||||
showCupertinoDialog(
|
showCupertinoDialog(
|
||||||
context: Get.context!,
|
context: Get.context!,
|
||||||
builder: (context) {
|
builder: (BuildContext context) {
|
||||||
return PopScope(
|
return PopScope(
|
||||||
canPop: false,
|
canPop: false,
|
||||||
child: CupertinoAlertDialog(
|
child: CupertinoAlertDialog(
|
||||||
title: Text('${titles[permission] ?? ''}${'权限被拒绝'.tr}'),
|
title: Text('${titles[permission] ?? ''}${'权限被拒绝'.tr}'),
|
||||||
content: Text(
|
content: Text(
|
||||||
'${contents[permission] ?? ''},${'请手动在系统设置中开启'.tr}${titles[permission]}${'权限以继续使用应用'.tr}'),
|
'${contents[permission] ?? ''},${'请手动在系统设置中开启'.tr}${titles[permission]}${'权限以继续使用应用'.tr}'),
|
||||||
actions: [
|
actions: <Widget>[
|
||||||
CupertinoDialogAction(
|
CupertinoDialogAction(
|
||||||
child: Text('去设置'.tr),
|
child: Text('去设置'.tr),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user