220 lines
6.3 KiB
Dart
220 lines
6.3 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/appRouters.dart';
|
|
import 'package:star_lock/blue/blue_manage.dart';
|
|
import 'package:system_settings/system_settings.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
import '../common/XSConstantMacro/XSConstantMacro.dart';
|
|
import 'NativeInteractionTool.dart';
|
|
import 'manager/client_manager.dart';
|
|
import 'showIosTipView.dart';
|
|
|
|
class BaseGetXController extends GetxController {
|
|
int currentTimeSeconds = 0;
|
|
|
|
bool currentPage = true;
|
|
var pageNo = 1;
|
|
var pageSize = "20";
|
|
|
|
@override
|
|
void onReady() {
|
|
super.onReady();
|
|
Get.log('$runtimeType onReady');
|
|
currentPage = true;
|
|
}
|
|
|
|
@override
|
|
// TODO: implement onDelete
|
|
InternalFinalCallback<void> get onDelete => super.onDelete;
|
|
|
|
@override
|
|
// TODO: implement onStart
|
|
InternalFinalCallback<void> get onStart => super.onStart;
|
|
|
|
@override
|
|
void onInit() {
|
|
// TODO: implement onInit
|
|
Get.log('$runtimeType onInit ');
|
|
super.onInit();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
// TODO: implement onClose
|
|
super.onClose();
|
|
currentPage = false;
|
|
Get.log('onClose -----> $runtimeType');
|
|
}
|
|
|
|
Future delay({Duration? duration, Function? something}) => Future.delayed(
|
|
duration ?? 500.milliseconds, something as FutureOr Function()?);
|
|
|
|
void showEasyLoading() => EasyLoading.show();
|
|
|
|
void dismissEasyLoading() => EasyLoading.dismiss();
|
|
|
|
Timer? _timer;
|
|
// CancelableOperation? _operation;
|
|
void showBlueConnetctToastTimer({bool isShowBlueConnetctToast = true, Function? action}) {
|
|
if (_timer != null && _timer!.isActive) {
|
|
_timer!.cancel();
|
|
_timer = null;
|
|
}
|
|
_timer = Timer.periodic(15.seconds, (timer) {
|
|
if (action != null) {
|
|
action();
|
|
}
|
|
cancelBlueConnetctToastTimer();
|
|
if (isShowBlueConnetctToast == true) {
|
|
showBlueConnetctToast();
|
|
}
|
|
});
|
|
}
|
|
|
|
void cancelBlueConnetctToastTimer() {
|
|
Get.log('cancelBlueConnetctToastTimer');
|
|
if (_timer != null && _timer!.isActive) {
|
|
_timer!.cancel();
|
|
_timer = null;
|
|
}
|
|
}
|
|
|
|
void showBlueConnetctToast() {
|
|
bool isContains = BlueManage().connectDeviceName!.contains("T9A");
|
|
showToast(
|
|
"连接设备失败,请确保在设备附近,设备未被连接,设备已打开${isContains == true ? "。如果是全自动锁,请使屏幕变亮" : ""}");
|
|
}
|
|
|
|
void showToast(String status, {Function? something}) {
|
|
EasyLoading.showToast(status, duration: 2000.milliseconds);
|
|
if (something != null) {
|
|
delay(duration: 2100.milliseconds, something: something);
|
|
}
|
|
}
|
|
|
|
void showError(String status, {Function? something}) {
|
|
EasyLoading.showError(status, duration: 2000.milliseconds);
|
|
if (something != null) {
|
|
delay(duration: 2100.milliseconds, something: something);
|
|
}
|
|
}
|
|
|
|
void showSuccess(String status, {Function? something}) {
|
|
EasyLoading.showSuccess(status, duration: 1500.milliseconds);
|
|
if (something != null) {
|
|
delay(duration: 2000.milliseconds, something: something);
|
|
}
|
|
}
|
|
|
|
void showOperationSuccessful({String? status, Function? something}) =>
|
|
showSuccess(status ?? "成功", something: something);
|
|
void showOperationFailed({String? status, Function? something}) =>
|
|
showError(status ?? "失败", something: something);
|
|
|
|
void logOff() async {
|
|
await ClientManager().logOff();
|
|
Get.offAllNamed(Routers.starLockLoginPage);
|
|
}
|
|
|
|
void checkBlueIsOpen(void Function() action) {
|
|
NativeInteractionTool().sendGetBlueStatus();
|
|
NativeInteractionTool().receiveChannelBlueIsOnEvent((String status) {
|
|
print("22222222");
|
|
if (status == "1") {
|
|
// 蓝牙已打开
|
|
Get.log('蓝牙已打开');
|
|
action();
|
|
} else if (status == "0") {
|
|
// 蓝牙未打开
|
|
Get.log('蓝牙未打开');
|
|
showIosTipViewDialog();
|
|
return;
|
|
} else {
|
|
// 蓝牙未打开
|
|
Get.log('设备不支持蓝牙');
|
|
showToast("设备不支持蓝牙");
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
|
|
void showIosTipViewDialog() {
|
|
showDialog(
|
|
context: Get.context!,
|
|
builder: (BuildContext context) {
|
|
return ShowIosTipView(
|
|
title: "提示",
|
|
tipTitle: "蓝牙未打开,请到设置里面打开蓝牙",
|
|
sureClick: () {
|
|
Get.back();
|
|
if (Platform.isIOS) {
|
|
launch('App-Prefs:');
|
|
} else {
|
|
SystemSettings.system();
|
|
}
|
|
},
|
|
cancelClick: () {
|
|
Get.back();
|
|
},
|
|
);
|
|
});
|
|
}
|
|
|
|
String getUseKeyTypeStr(int? startDate, int? endDate, int? keyType) {
|
|
String useDateStr = '';
|
|
if (keyType == XSConstantMacro.keyTypeTime) {
|
|
//限期
|
|
DateTime startDateStr = DateTime.fromMillisecondsSinceEpoch(startDate!);
|
|
DateTime endDateStr = DateTime.fromMillisecondsSinceEpoch(endDate!);
|
|
useDateStr =
|
|
'${startDateStr.toLocal().toString().substring(0, 16)} - ${endDateStr.toLocal().toString().substring(0, 16)}';
|
|
} else if (keyType == XSConstantMacro.keyTypeLong) {
|
|
//永久
|
|
// DateTime dateStr = DateTime.fromMillisecondsSinceEpoch(indexEntity.date!);
|
|
// useDateStr = '${dateStr.toLocal().toString().substring(0, 16)}\n永久';
|
|
useDateStr = '永久';
|
|
} else if (keyType == XSConstantMacro.keyTypeOnce) {
|
|
//单次
|
|
// DateTime dateStr = DateTime.fromMillisecondsSinceEpoch(indexEntity.date!);
|
|
// useDateStr = '${dateStr.toLocal().toString().substring(0, 16)} \n单次';
|
|
useDateStr = '单次';
|
|
} else if (keyType == XSConstantMacro.keyTypeLoop) {
|
|
//循环
|
|
useDateStr = '循环';
|
|
}
|
|
|
|
return useDateStr;
|
|
}
|
|
|
|
static List splitList(List list, int len) {
|
|
if (len <= 1) {
|
|
return [list];
|
|
}
|
|
List result = [];
|
|
int index = 1;
|
|
while (true) {
|
|
if (index * len < list.length) {
|
|
List temp = list.skip((index - 1) * len).take(len).toList();
|
|
result.add(temp);
|
|
index++;
|
|
continue;
|
|
}
|
|
List temp = list.skip((index - 1) * len).toList();
|
|
result.add(temp);
|
|
break;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
|
|
///Extension_Int
|
|
extension Extension_Int on int {
|
|
bool get codeIsSuccessful => this == 0;
|
|
bool get msgCodeIsSuccessful => this == 1;
|
|
}
|