From e8178835755fbf64aa6e8f07ef160fcdb0e97814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=B0=91=E9=98=B3?= <786612630@qq.com> Date: Tue, 20 Aug 2024 09:53:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=AA=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lan/lan_en.json | 12 ++- lan/lan_keys.json | 12 ++- lan/lan_zh.json | 12 ++- lib/app_settings/app_colors.dart | 28 +++--- lib/app_settings/app_settings.dart | 6 +- lib/blue/io_reply.dart | 36 ++++---- lib/blue/io_sender.dart | 24 +++--- lib/blue/io_tool/io_model.dart | 28 +++--- lib/blue/io_tool/io_tool.dart | 6 +- lib/blue/sm4Encipher/utils/ec.dart | 6 +- lib/blue/sm4Encipher/utils/utils.dart | 20 ++--- lib/network/api_provider_base.dart | 6 +- lib/network/response_interceptor.dart | 4 +- lib/tools/advancedCalendar/src/header.dart | 2 +- lib/tools/advancedCalendar/src/widget.dart | 63 +++++++------- lib/tools/bugly/bugly_tool.dart | 2 +- .../time_picker/model/date_item_model.dart | 50 +++++++---- .../time_picker/model/date_time_data.dart | 12 +-- .../pickers/time_picker/model/pduration.dart | 86 +++++++++---------- .../pickers/time_picker/model/suffix.dart | 46 +++++----- lib/tools/pickers/time_picker/time_utils.dart | 2 +- lib/widget/permission/permission_dialog.dart | 2 +- 22 files changed, 256 insertions(+), 209 deletions(-) diff --git a/lan/lan_en.json b/lan/lan_en.json index 51729a68..87569770 100755 --- a/lan/lan_en.json +++ b/lan/lan_en.json @@ -861,5 +861,15 @@ "QQ空间": "QQZone", "微博": "Weibo", "FaceBook": "FaceBook", - "链接": "Link" + "链接": "Link", + "今天": "Today", + "密码错误": "Password error", + "网络中断": "Network interruption", + "钥匙不存在": "Key does not exist", + "钥匙过期": "Key expired", + "钥匙已存在": "Key already exists", + "密码失效": "Password invalid", + "门锁时间异常": "Door lock time abnormal", + "APP(手机)未联网": "APP (mobile phone) is not connected to the Internet", + "数据不存在": "Data does not exist" } diff --git a/lan/lan_keys.json b/lan/lan_keys.json index 0879f3e0..65cf917c 100755 --- a/lan/lan_keys.json +++ b/lan/lan_keys.json @@ -893,5 +893,15 @@ "QQ空间": "QQ空间", "微博": "微博", "FaceBook": "FaceBook", - "链接": "链接" + "链接": "链接", + "今天": "今天", + "密码错误": "密码错误", + "网络中断": "网络中断", + "钥匙不存在": "钥匙不存在", + "钥匙过期": "钥匙过期", + "钥匙已存在": "钥匙已存在", + "密码失效": "密码失效", + "门锁时间异常": "门锁时间异常", + "APP(手机)未联网": "APP(手机)未联网", + "数据不存在": "数据不存在" } diff --git a/lan/lan_zh.json b/lan/lan_zh.json index a8aaad89..b7ae345f 100755 --- a/lan/lan_zh.json +++ b/lan/lan_zh.json @@ -859,5 +859,15 @@ "QQ空间": "QQ空间", "微博": "微博", "FaceBook": "FaceBook", - "链接": "链接" + "链接": "链接", + "今天": "今天", + "密码错误": "密码错误", + "网络中断": "网络中断", + "钥匙不存在": "钥匙不存在", + "钥匙过期": "钥匙过期", + "钥匙已存在": "钥匙已存在", + "密码失效": "密码失效", + "门锁时间异常": "门锁时间异常", + "APP(手机)未联网": "APP(手机)未联网", + "数据不存在": "数据不存在" } diff --git a/lib/app_settings/app_colors.dart b/lib/app_settings/app_colors.dart index 17be1c83..ee4fd41b 100755 --- a/lib/app_settings/app_colors.dart +++ b/lib/app_settings/app_colors.dart @@ -120,23 +120,23 @@ class AppColors { static Color progressBgColor = const Color(0xFF022345); static Color progressValueColor = const Color(0xFF0093E5); - static const greyLineColor = Color.fromRGBO(240, 240, 240, 1); //灰色分割线220 - static const darkGrayTextColor = Color.fromRGBO(65, 65, 65, 1); //深灰色字体 - static const placeholderTextColor = Color.fromRGBO(128, 128, 128, 1); //占位字体颜色 - static const greyBackgroundColor = Color.fromRGBO(240, 240, 240, 1); //灰色背景色 - static const btnDisableColor = Color.fromRGBO(178, 178, 178, 1); //按钮不可用灰色 - static const toBeReceiveBgColor = Color.fromRGBO(246, 203, 203, 1); //待接收红色背景 - static const expireTextBgColor = Color.fromRGBO(253, 166, 8, 1); //即将到期时间字体背景色 - static const blueTextTipsColor = Color.fromRGBO(0, 113, 255, 1); //蓝色字体tips - static const blueViewBgColor = + static const Color greyLineColor = Color.fromRGBO(240, 240, 240, 1); //灰色分割线220 + static const Color darkGrayTextColor = Color.fromRGBO(65, 65, 65, 1); //深灰色字体 + static const Color placeholderTextColor = Color.fromRGBO(128, 128, 128, 1); //占位字体颜色 + static const Color greyBackgroundColor = Color.fromRGBO(240, 240, 240, 1); //灰色背景色 + static const Color btnDisableColor = Color.fromRGBO(178, 178, 178, 1); //按钮不可用灰色 + static const Color toBeReceiveBgColor = Color.fromRGBO(246, 203, 203, 1); //待接收红色背景 + static const Color expireTextBgColor = Color.fromRGBO(253, 166, 8, 1); //即将到期时间字体背景色 + static const Color blueTextTipsColor = Color.fromRGBO(0, 113, 255, 1); //蓝色字体tips + static const Color blueViewBgColor = Color.fromRGBO(223, 237, 254, 1); //蓝色背景板 139 148 176 - static const msgNoticeTextColor = Color.fromRGBO(139, 148, 176, 1); //消息提醒字体颜色 - static const alphaBgViewColor = Color.fromRGBO(0, 0, 0, 0.2); //透明度背景 - static const vipFeatureBgColor = + static const Color msgNoticeTextColor = Color.fromRGBO(139, 148, 176, 1); //消息提醒字体颜色 + static const Color alphaBgViewColor = Color.fromRGBO(0, 0, 0, 0.2); //透明度背景 + static const Color vipFeatureBgColor = Color.fromRGBO(251, 248, 229, 1); //需开通高级功能背景色 - static const vipFeatureBtnBgColor = + static const Color vipFeatureBtnBgColor = Color.fromRGBO(197, 167, 109, 1); //需开通高级功能按钮背景色 - static const vipFeatureBtnTextColor = + static const Color vipFeatureBtnTextColor = Color.fromRGBO(110, 98, 81, 1); //需开通高级功能字体颜色 static Color openPassageModeColor = const Color(0xFFEB2A3B); // 首页开启常开模式颜色(红色) diff --git a/lib/app_settings/app_settings.dart b/lib/app_settings/app_settings.dart index f03b8cf1..a79ebe66 100755 --- a/lib/app_settings/app_settings.dart +++ b/lib/app_settings/app_settings.dart @@ -1,7 +1,7 @@ -import 'package:flutter/foundation.dart'; -import 'package:get/get.dart'; import 'dart:io'; +import 'package:flutter/foundation.dart'; +import 'package:get/get.dart'; import 'package:star_lock/mine/about/debug/debug_console.dart'; class AppLog { @@ -103,7 +103,7 @@ class AppDate { static int timeZeroOffset() => DateTime.now().timeZoneOffset.inHours; } -//TODO:错误类型 +// 错误类型 enum ErrorType { modeNotMatch, notConnected, diff --git a/lib/blue/io_reply.dart b/lib/blue/io_reply.dart index adf8c457..be395c47 100755 --- a/lib/blue/io_reply.dart +++ b/lib/blue/io_reply.dart @@ -24,27 +24,27 @@ abstract class Reply{ case 0x01: // 包格式错误 AppLog.log('$logTag ${commandType!.typeName} 0x01 包格式错误'); - showErrorMessage('包格式错误'); + // showErrorMessage('包格式错误'); break; case 0x02: // 密码错误 AppLog.log('$logTag ${commandType!.typeName} 0x02 密码错误'); - showErrorMessage('密码错误'); + showErrorMessage('密码错误'.tr); break; case 0x03: // 网络中断 AppLog.log('$logTag ${commandType!.typeName} 0x03 网络中断'); - showErrorMessage('网络中断'); + showErrorMessage('网络中断'.tr); break; case 0x04: // 用户未登记 AppLog.log('$logTag ${commandType!.typeName} 0x04 用户未登记'); - showErrorMessage('用户未登记'); + // showErrorMessage('用户未登记'); break; case 0x05: // 参数错误 AppLog.log('$logTag ${commandType!.typeName} 0x05 参数错误'); - showErrorMessage('参数错误'); + // showErrorMessage('参数错误'); break; case 0x06: // 需要鉴权 @@ -59,42 +59,42 @@ abstract class Reply{ case 0x08: // 应答超时 AppLog.log('$logTag ${commandType!.typeName} 0x08 应答超时'); - showErrorMessage('应答超时'); + // showErrorMessage('应答超时'); break; case 0x09: // 权限校验错误 AppLog.log('$logTag ${commandType!.typeName} 0x09 权限校验错误'); - showErrorMessage('权限校验错误'); + // showErrorMessage('权限校验错误'); break; case 0x0a: // 钥匙不存在 - showErrorMessage('钥匙不存在'); + showErrorMessage('钥匙不存在'.tr); AppLog.log('$logTag ${commandType!.typeName} 0x0a 钥匙不存在'); break; case 0x0b: // 钥匙过期 - showErrorMessage('钥匙过期'); + showErrorMessage('钥匙过期'.tr); AppLog.log('$logTag ${commandType!.typeName} 0x0b 钥匙过期'); break; case 0x0c: // 钥匙数量已到上限 - showErrorMessage('钥匙数量已到上限'); + // showErrorMessage('钥匙数量已到上限'); AppLog.log('$logTag ${commandType!.typeName} 0x0c 钥匙数量已到上限'); break; case 0x0d: // 钥匙无效 - showErrorMessage('钥匙无效'); + showErrorMessage('钥匙无效'.tr); AppLog.log('$logTag ${commandType!.typeName} 0x0d 钥匙无效'); break; case 0x0e: // 钥匙已存在 - showErrorMessage('钥匙已存在'); + showErrorMessage('钥匙已存在'.tr); AppLog.log('$logTag ${commandType!.typeName} 0x0e 钥匙已存在'); break; case 0x0f: // 用户已存在 AppLog.log('$logTag ${commandType!.typeName} 0x0f 用户已存在'); - showErrorMessage('用户已存在'); + // showErrorMessage('用户已存在'); break; case 0x10: // 密码失效 @@ -104,27 +104,27 @@ abstract class Reply{ case 0x11: // 无效指令 AppLog.log('$logTag ${commandType!.typeName} 0x11 无效指令'); - showErrorMessage('无效指令'); + // showErrorMessage('无效指令'); break; case 0x12: // 门锁时间异常 AppLog.log('$logTag ${commandType!.typeName} 0x12 门锁时间异常'); - showErrorMessage('门锁时间异常'); + showErrorMessage('门锁时间异常'.tr); break; case 0x15: // APP(手机)未联网 AppLog.log('$logTag ${commandType!.typeName} 0x15 APP(手机)未联网'); - showErrorMessage('APP(手机)未联网'); + showErrorMessage('APP(手机)未联网'.tr); break; case 0x16: // 正在开锁中... AppLog.log('$logTag ${commandType!.typeName} $status 正在开锁中...'); - showErrorMessage('正在开锁中...'); + showErrorMessage('正在开锁中...'.tr); break; case 0xff: // 异常,未知错误 AppLog.log('$logTag ${commandType!.typeName} 0xff 异常,未知错误'); - showErrorMessage('异常,未知错误'); + // showErrorMessage('异常,未知错误'); break; default: //失败 diff --git a/lib/blue/io_sender.dart b/lib/blue/io_sender.dart index 5270d56d..7fec2557 100755 --- a/lib/blue/io_sender.dart +++ b/lib/blue/io_sender.dart @@ -14,7 +14,7 @@ abstract class SenderProtocol extends IOData { // var uint8View1 = Uint8List(300); CommandType? commandType; //指令类型 - final List header = [ + final List header = [ 0XEF, 0X01, 0XEE, @@ -26,7 +26,7 @@ abstract class SenderProtocol extends IOData { int identifier = 0x20; // 高 4 位表示包版本,低 4 位用来指示后面数据的加密类型,长度为 1 字节,加密类型取值说明,0:明文,1:AES128,2:SM4(事先约定密钥),3:SM4(设备指定密钥) - List? commandData = []; //数据块 + List? commandData = []; //数据块 // final int? tail = 0xFF; //用来校验包的完整性,采用 CRC 校验方法,长度为 2 个字节 SenderProtocol(this.commandType) { @@ -42,7 +42,7 @@ abstract class SenderProtocol extends IOData { //TODO:拼装数据 List packageData() { commandData = messageDetail(); - List commandList = []; + List commandList = []; // 帧头 commandList.addAll(header); @@ -78,7 +78,7 @@ abstract class SenderProtocol extends IOData { commandList.addAll(commandData!); //数据块 // 校验位 - var mcrc = crc_16(commandList); + int mcrc = crc_16(commandList); double mcrcDouble = mcrc / 256; int mcrcDouble1 = mcrcDouble.toInt(); int mcrcDouble2 = mcrc % 256; @@ -94,7 +94,7 @@ abstract class SenderProtocol extends IOData { //TODO:长度 int dataSourceLength() => commandData!.length; - var crcTable = [ + List crcTable = [ 0x0000, 0x1021, 0x2042, @@ -355,9 +355,9 @@ abstract class SenderProtocol extends IOData { int crc_16(buffer) { var len = buffer.length; - var value_ = 0x0000; //0xa635; //初始值,根据CRC类型设定 - var tmp; - for (var i = 0; i < buffer.length; i++) { + int value_ = 0x0000; //0xa635; //初始值,根据CRC类型设定 + int tmp; + for (int i = 0; i < buffer.length; i++) { tmp = reverse8(buffer[i]); value_ = ((value_ << 8) ^ crcTable[((value_ >> 8) ^ tmp) & 0xFF]) & 0xFFFF; @@ -367,8 +367,8 @@ abstract class SenderProtocol extends IOData { } int reverse8(data) { - var i; - var temp = 0; + int i; + int temp = 0; for (i = 0; i < 8; i++) { //字节反转 temp |= ((data >> i) & 0x01) << (7 - i); @@ -377,8 +377,8 @@ abstract class SenderProtocol extends IOData { } int reverse16(data) { - var i; - var temp = 0; + int i; + int temp = 0; for (i = 0; i < 16; i++) { //反转 temp |= ((data >> i) & 0x0001) << (15 - i); diff --git a/lib/blue/io_tool/io_model.dart b/lib/blue/io_tool/io_model.dart index 018ce49d..ccb1dec5 100755 --- a/lib/blue/io_tool/io_model.dart +++ b/lib/blue/io_tool/io_model.dart @@ -10,14 +10,6 @@ extension Extension on DataChannel { } class EventSendModel { - List data = []; - String? topic = ''; - DataChannel? sendChannel; - - String? deviceId; - Uuid? serviceId; - Uuid? characteristicId; - bool? allowLongWrite = false; EventSendModel( {required this.data, @@ -27,31 +19,39 @@ class EventSendModel { this.serviceId, this.characteristicId, this.allowLongWrite}); + List data = []; + String? topic = ''; + DataChannel? sendChannel; + + String? deviceId; + Uuid? serviceId; + Uuid? characteristicId; + bool? allowLongWrite = false; } ///接收数据类 class EventReceiveModel { + + EventReceiveModel({required this.data, this.sendChannel, this.tag}); dynamic data; String? tag = ''; DataChannel? sendChannel; - - EventReceiveModel({required this.data, this.sendChannel, this.tag}); } ///解析数据域 class EventParseModel { + + EventParseModel({required this.type, required this.data, this.commandIndex}); int? type; int? commandIndex; dynamic data; - - EventParseModel({required this.type, required this.data, this.commandIndex}); } ///debug info model class StateModel { + + StateModel({this.title = '', this.subTitle = '', this.result = false}); final String title; final String subTitle; final bool result; - - StateModel({this.title = '', this.subTitle = '', this.result = false}); } diff --git a/lib/blue/io_tool/io_tool.dart b/lib/blue/io_tool/io_tool.dart index 698e33d3..e4f311d8 100755 --- a/lib/blue/io_tool/io_tool.dart +++ b/lib/blue/io_tool/io_tool.dart @@ -51,7 +51,7 @@ int _hexToInt(String hex) { // a..f val += (hexDigit - 87) * (1 << (4 * (len - 1 - i))); } else { - throw FormatException("Invalid hexadecimal value"); + throw const FormatException('Invalid hexadecimal value'); } } return val; @@ -74,13 +74,13 @@ List getFixedLengthList(List data, int length) { //int ---> 指定长度的hex (如指定长度为6的情况,0x000001 0x001234, 0xefab23) String intToFormatHex(int num, int length) { final String hexString = num.toRadixString(16); - final String formatString = hexString.padLeft(length, "0"); + final String formatString = hexString.padLeft(length, '0'); return formatString; } String uint8ToHex(Uint8List byteArr) { if (byteArr.isEmpty) { - return ""; + return ''; } final Uint8List result = Uint8List(byteArr.length << 1); final List hexTable = [ diff --git a/lib/blue/sm4Encipher/utils/ec.dart b/lib/blue/sm4Encipher/utils/ec.dart index 66d137c7..20d15d95 100755 --- a/lib/blue/sm4Encipher/utils/ec.dart +++ b/lib/blue/sm4Encipher/utils/ec.dart @@ -8,8 +8,10 @@ class ECFieldElementFp { /// 判断相等 bool equals(ECFieldElementFp other) { - if (other == this) return true; - return (q == other.q && x == other.x); + if (other == this) { + return true; + } + return q == other.q && x == other.x; } /// 返回具体数值 diff --git a/lib/blue/sm4Encipher/utils/utils.dart b/lib/blue/sm4Encipher/utils/utils.dart index 5ed948db..d65034df 100755 --- a/lib/blue/sm4Encipher/utils/utils.dart +++ b/lib/blue/sm4Encipher/utils/utils.dart @@ -3,41 +3,41 @@ import 'dart:convert'; class SMUtils{ static int leftShift(int x, int n){ - int s = n & 31; + final int s = n & 31; x = (x & 0xFFFFFFFF).toSigned(32); return (((x << s) | ((x & 0xFFFFFFFF) >> (32 - s))) & 0xFFFFFFFF).toSigned(32); } static int rightShift(int x, int n) { - int s = n & 31; + final int s = n & 31; x = (x & 0xFFFFFFFF).toSigned(32); return ((x >> s) | ((x << (32 - s)) & 0xFFFFFFFF)).toSigned(32); } static String bytesToHexString(List bytes) { - final buffer = StringBuffer(); - for (final byte in bytes) { + final StringBuffer buffer = StringBuffer(); + for (final int byte in bytes) { buffer.write(byte.toRadixString(16).padLeft(2, '0')); } return buffer.toString(); } static List hexStringToBytes(String hexString) { - final length = hexString.length ~/ 2; - final bytes = List.filled(length, 0); + final int length = hexString.length ~/ 2; + final List bytes = List.filled(length, 0); for (int i = 0; i < length; i++) { - final byteString = hexString.substring(i * 2, i * 2 + 2); + final String byteString = hexString.substring(i * 2, i * 2 + 2); bytes[i] = int.parse(byteString, radix: 16); } return bytes; } static String utf8ToHexString(String input) { - List utf8Encoded = utf8.encode(input); + final List utf8Encoded = utf8.encode(input); // 转换到16进制 - StringBuffer hexChars = StringBuffer(); + final StringBuffer hexChars = StringBuffer(); for (int i = 0; i < utf8Encoded.length; i++) { - int bite = utf8Encoded[i]; + final int bite = utf8Encoded[i]; hexChars.write((bite >> 4).toRadixString(16)); hexChars.write((bite & 0x0f).toRadixString(16)); } diff --git a/lib/network/api_provider_base.dart b/lib/network/api_provider_base.dart index 83b9ae9e..6eb0ac4a 100755 --- a/lib/network/api_provider_base.dart +++ b/lib/network/api_provider_base.dart @@ -90,7 +90,7 @@ class BaseProvider extends GetConnect with Api { Get.offNamedUntil(Routers.starLockLoginPage, (route) => false); break; case 500: - EasyLoading.showToast('服务器错误', duration: 2000.milliseconds); + // EasyLoading.showToast('服务器错误', duration: 2000.milliseconds); break; case 421: case 422: @@ -102,11 +102,11 @@ class BaseProvider extends GetConnect with Api { // Toast.show(msg: "用户不存在"); // break; case 10001: - EasyLoading.showToast('数据不存在', duration: 2000.milliseconds); + EasyLoading.showToast('数据不存在'.tr, duration: 2000.milliseconds); break; case 434: //与后台约定弹出确认框提示 ShowTipView() - .showSureBtnTipsAlert(tipsText: T['errorMsg'], sureText: '确定'); + .showSureBtnTipsAlert(tipsText: T['errorMsg'], sureText: ''); break; } } diff --git a/lib/network/response_interceptor.dart b/lib/network/response_interceptor.dart index 15986185..78e0e3a8 100755 --- a/lib/network/response_interceptor.dart +++ b/lib/network/response_interceptor.dart @@ -1,5 +1,7 @@ -import 'package:get/get.dart'; + import 'dart:async'; + +import 'package:get/get.dart'; import 'package:get/get_connect/http/src/request/request.dart'; import '../tools/manager/client_manager.dart'; diff --git a/lib/tools/advancedCalendar/src/header.dart b/lib/tools/advancedCalendar/src/header.dart index 026da55b..2b8bc331 100755 --- a/lib/tools/advancedCalendar/src/header.dart +++ b/lib/tools/advancedCalendar/src/header.dart @@ -47,7 +47,7 @@ class Header extends StatelessWidget { vertical: 4.0, ), child: Text( - '今天', + '今天'.tr, style: TextStyle( color: Colors.black, fontSize: 24.sp, diff --git a/lib/tools/advancedCalendar/src/widget.dart b/lib/tools/advancedCalendar/src/widget.dart index 468f8fe8..702b32e6 100755 --- a/lib/tools/advancedCalendar/src/widget.dart +++ b/lib/tools/advancedCalendar/src/widget.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; import 'package:intl/intl.dart'; import 'package:star_lock/tools/eventBusEventManage.dart'; @@ -103,7 +104,7 @@ class _AdvancedCalendarState extends State void initState() { super.initState(); - final monthPageIndex = widget.preloadMonthViewAmount ~/ 2; + final int monthPageIndex = widget.preloadMonthViewAmount ~/ 2; _monthViewCurrentPage = ValueNotifier(monthPageIndex); @@ -111,7 +112,7 @@ class _AdvancedCalendarState extends State initialPage: monthPageIndex, ); - final weekPageIndex = widget.preloadWeekViewAmount ~/ 2; + final int weekPageIndex = widget.preloadWeekViewAmount ~/ 2; _weekPageController = PageController( initialPage: weekPageIndex, @@ -130,7 +131,7 @@ class _AdvancedCalendarState extends State _monthRangeList = List.generate( widget.preloadMonthViewAmount, - (index) => ViewRange.generateDates( + (int index) => ViewRange.generateDates( _todayDate!, _todayDate!.month + (index - _monthPageController!.initialPage), widget.weeksInMonthViewAmount, @@ -150,19 +151,19 @@ class _AdvancedCalendarState extends State _weekPageController!.jumpToPage(widget.preloadWeekViewAmount ~/ 2); }); if (widget.startWeekDay != null && widget.startWeekDay! < 7) { - final time = _controller.value.subtract( + final DateTime time = _controller.value.subtract( Duration(days: _controller.value.weekday - widget.startWeekDay!), ); - final list = List.generate( + final List list = List.generate( 8, - (index) => time.add(Duration(days: index * 1)), + (int index) => time.add(Duration(days: index * 1)), ).toList(); // _weekNames = List.generate(7, (index) { // return DateFormat("EEEE").format(list[index]).split('').first; // } // ); //by DaisyWu 修改源文件为中文环境下 周一到周日 - _weekNames = List.generate(7, (index) { + _weekNames = List.generate(7, (int index) { String fullWeekName = DateFormat.E('zh_CN').format(list[index]); // 获取星期的完整形式 return fullWeekName @@ -173,23 +174,23 @@ class _AdvancedCalendarState extends State @override Widget build(BuildContext context) { - final theme = Theme.of(context); + final ThemeData theme = Theme.of(context); return Material( color: Colors.transparent, child: DefaultTextStyle.merge( style: theme.textTheme.bodyMedium, child: GestureDetector( - onVerticalDragStart: (details) { + onVerticalDragStart: (DragStartDetails details) { _captureOffset = details.globalPosition; }, - onVerticalDragUpdate: (details) { - final moveOffset = details.globalPosition; - final diffY = moveOffset.dy - _captureOffset!.dy; + onVerticalDragUpdate: (DragUpdateDetails details) { + final Offset moveOffset = details.globalPosition; + final double diffY = moveOffset.dy - _captureOffset!.dy; _animationController.value = _animationValue + diffY / (widget.weekLineHeight * 5); }, - onVerticalDragEnd: (details) => _handleFinishDrag(), + onVerticalDragEnd: (DragEndDetails details) => _handleFinishDrag(), onVerticalDragCancel: _handleFinishDrag, child: Container( color: Colors.transparent, @@ -197,10 +198,10 @@ class _AdvancedCalendarState extends State mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, - children: [ + children: [ ValueListenableBuilder( valueListenable: _monthViewCurrentPage, - builder: (_, value, __) { + builder: (_, int value, __) { return Header( monthDate: _monthRangeList[_monthViewCurrentPage.value].firstDay, @@ -217,12 +218,12 @@ class _AdvancedCalendarState extends State keepLineSize: widget.keepLineSize, weekNames: _weekNames != null ? _weekNames! - : const ['日', '一', '二', '三', '四', '五', '六'], + : ['简写周日'.tr, '简写周一'.tr, '简写周二'.tr, '简写周三'.tr, '简写周四'.tr, '简写周五'.tr, '简写周六'.tr], ), AnimatedBuilder( animation: _animationController, builder: (_, __) { - final height = Tween( + final double height = Tween( begin: widget.weekLineHeight, end: widget.weekLineHeight * widget.weeksInMonthViewAmount, @@ -231,12 +232,12 @@ class _AdvancedCalendarState extends State height: height, child: ValueListenableBuilder( valueListenable: _controller, - builder: (_, selectedDate, __) { + builder: (_, DateTime selectedDate, __) { AppLog.log('****selectedDate: $selectedDate'); eventBus.fire(DoorLockLogListRefreshUI(selectedDate)); return Stack( alignment: Alignment.center, - children: [ + children: [ IgnorePointer( ignoring: _animationController.value == 0.0, child: Opacity( @@ -245,7 +246,7 @@ class _AdvancedCalendarState extends State end: 1.0, ).evaluate(_animationController), child: PageView.builder( - onPageChanged: (pageIndex) { + onPageChanged: (int pageIndex) { if (widget.onHorizontalDrag != null) { widget.onHorizontalDrag!( _monthRangeList[pageIndex].firstDay, @@ -258,7 +259,7 @@ class _AdvancedCalendarState extends State ? const AlwaysScrollableScrollPhysics() : const NeverScrollableScrollPhysics(), itemCount: _monthRangeList.length, - itemBuilder: (_, pageIndex) { + itemBuilder: (_, int pageIndex) { return MonthView( innerDot: widget.innerDot, monthView: _monthRangeList[pageIndex], @@ -278,12 +279,12 @@ class _AdvancedCalendarState extends State ), ValueListenableBuilder( valueListenable: _monthViewCurrentPage, - builder: (_, pageIndex, __) { - final index = selectedDate.findWeekIndex( + builder: (_, int pageIndex, __) { + final int index = selectedDate.findWeekIndex( _monthRangeList[_monthViewCurrentPage.value] .dates, ); - final offset = index / + final double offset = index / (widget.weeksInMonthViewAmount - 1) * 2 - 1.0; @@ -300,10 +301,10 @@ class _AdvancedCalendarState extends State child: SizedBox( height: widget.weekLineHeight, child: PageView.builder( - onPageChanged: (indexPage) { - final pageIndex = + onPageChanged: (int indexPage) { + final int pageIndex = _monthRangeList.indexWhere( - (index) => + (ViewRange index) => index.firstDay.month == _weekRangeList[indexPage] .first @@ -323,7 +324,7 @@ class _AdvancedCalendarState extends State controller: _weekPageController, itemCount: _weekRangeList.length, physics: _closeMonthScroll(), - itemBuilder: (context, index) { + itemBuilder: (BuildContext context, int index) { return WeekView( innerDot: widget.innerDot, dates: _weekRangeList[index], @@ -384,7 +385,7 @@ class _AdvancedCalendarState extends State _handleDateChanged(date); _monthViewCurrentPage.value = _monthRangeList - .lastIndexWhere((monthRange) => monthRange.dates.contains(date)); + .lastIndexWhere((ViewRange monthRange) => monthRange.dates.contains(date)); } void _handleDateChanged(DateTime date) { @@ -411,10 +412,10 @@ class _AdvancedCalendarState extends State } ScrollPhysics _closeMonthScroll() { - if ((_monthViewCurrentPage.value == + if (_monthViewCurrentPage.value == (widget.preloadMonthViewAmount ~/ 2) + 3 || _monthViewCurrentPage.value == - (widget.preloadMonthViewAmount ~/ 2) - 3)) { + (widget.preloadMonthViewAmount ~/ 2) - 3) { return const NeverScrollableScrollPhysics(); } else { return const AlwaysScrollableScrollPhysics(); diff --git a/lib/tools/bugly/bugly_tool.dart b/lib/tools/bugly/bugly_tool.dart index fb50076c..69113f12 100644 --- a/lib/tools/bugly/bugly_tool.dart +++ b/lib/tools/bugly/bugly_tool.dart @@ -1,6 +1,6 @@ + import 'dart:async'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_bugly_plugin/flutter_bugly_plugin.dart'; import 'package:star_lock/app_settings/app_settings.dart'; diff --git a/lib/tools/pickers/time_picker/model/date_item_model.dart b/lib/tools/pickers/time_picker/model/date_item_model.dart index 17f5bbe7..85a123f0 100755 --- a/lib/tools/pickers/time_picker/model/date_item_model.dart +++ b/lib/tools/pickers/time_picker/model/date_item_model.dart @@ -4,6 +4,18 @@ import 'package:star_lock/tools/pickers/time_picker/model/date_mode.dart'; class DateItemModel { + + DateItemModel( + this.year, this.month, this.day, this.hour, this.minute, this.second); + + DateItemModel.parse(DateMode dateMode) { + year = DateModeMap[dateMode]!.contains('年'); + month = DateModeMap[dateMode]!.contains('月'); + day = DateModeMap[dateMode]!.contains('日'); + hour = DateModeMap[dateMode]!.contains('时'); + minute = DateModeMap[dateMode]!.contains('分'); + second = DateModeMap[dateMode]!.contains('秒'); + } late bool year; late bool month; late bool day; @@ -11,34 +23,34 @@ class DateItemModel { late bool minute; late bool second; - DateItemModel( - this.year, this.month, this.day, this.hour, this.minute, this.second); - - DateItemModel.parse(DateMode dateMode) { - this.year = DateModeMap[dateMode]!.contains('年'); - this.month = DateModeMap[dateMode]!.contains('月'); - this.day = DateModeMap[dateMode]!.contains('日'); - this.hour = DateModeMap[dateMode]!.contains('时'); - this.minute = DateModeMap[dateMode]!.contains('分'); - this.second = DateModeMap[dateMode]!.contains('秒'); - } - // 返回需要显示多少个picker int get length { int i = 0; - if (this.year) ++i; - if (this.month) ++i; - if (this.day) ++i; - if (this.hour) ++i; - if (this.minute) ++i; - if (this.second) ++i; + if (year) { + ++i; + } + if (month) { + ++i; + } + if (day) { + ++i; + } + if (hour) { + ++i; + } + if (minute) { + ++i; + } + if (second) { + ++i; + } return i; } } const DateModeMap = { - DateMode.YMDHMS: "年月日时分秒", + DateMode.YMDHMS: '年月日时分秒', DateMode.YMDHM: '年月日时分', DateMode.YMDH: '年月日时', DateMode.YMD: '年月日', diff --git a/lib/tools/pickers/time_picker/model/date_time_data.dart b/lib/tools/pickers/time_picker/model/date_time_data.dart index 54d41c08..2161f477 100755 --- a/lib/tools/pickers/time_picker/model/date_time_data.dart +++ b/lib/tools/pickers/time_picker/model/date_time_data.dart @@ -4,12 +4,12 @@ import 'package:star_lock/tools/pickers/time_picker/model/date_type.dart'; /// 时间选择器 item 生成的对应数据 class DateTimeData { - List _year = []; - List _month = []; - List _day = []; - List _hour = []; - List _minute = []; - List _second = []; + final List _year = []; + final List _month = []; + final List _day = []; + final List _hour = []; + final List _minute = []; + final List _second = []; List getListByName(DateType type) { switch (type) { diff --git a/lib/tools/pickers/time_picker/model/pduration.dart b/lib/tools/pickers/time_picker/model/pduration.dart index 15596825..ab641835 100755 --- a/lib/tools/pickers/time_picker/model/pduration.dart +++ b/lib/tools/pickers/time_picker/model/pduration.dart @@ -18,14 +18,43 @@ import 'package:star_lock/tools/pickers/time_picker/model/date_type.dart'; /// {year: 2020, month: 3, day: 4, hour: 0, minute: 0, second: 0} bool intEmpty(int? value) { - return (value == null || value == 0); + return value == null || value == 0; } bool intNotEmpty(int? value) { - return (value != null && value != 0); + return value != null && value != 0; } class PDuration { + + PDuration( + {this.year = 0, + this.month = 0, + this.day = 0, + this.hour = 0, + this.minute = 0, + this.second = 0}); + + // 注意默认会设为0 不是null + PDuration.parse(DateTime? dateTime) { + dateTime ??= DateTime.now(); + year = dateTime.year; + month = dateTime.month; + day = dateTime.day; + hour = dateTime.hour; + minute = dateTime.minute; + second = dateTime.second; + } + + PDuration.now() { + var thisInstant = new DateTime.now(); + year = thisInstant.year; + month = thisInstant.month; + day = thisInstant.day; + hour = thisInstant.hour; + minute = thisInstant.minute; + second = thisInstant.second; + } int? year; int? month; int? day; @@ -33,54 +62,25 @@ class PDuration { int? minute; int? second; - PDuration( - {this.year: 0, - this.month: 0, - this.day: 0, - this.hour: 0, - this.minute: 0, - this.second: 0}); - - // 注意默认会设为0 不是null - PDuration.parse(DateTime? dateTime) { - dateTime ??= DateTime.now(); - this.year = dateTime.year; - this.month = dateTime.month; - this.day = dateTime.day; - this.hour = dateTime.hour; - this.minute = dateTime.minute; - this.second = dateTime.second; - } - - PDuration.now() { - var thisInstant = new DateTime.now(); - this.year = thisInstant.year; - this.month = thisInstant.month; - this.day = thisInstant.day; - this.hour = thisInstant.hour; - this.minute = thisInstant.minute; - this.second = thisInstant.second; - } - void setSingle(DateType dateType, var value) { switch (dateType) { case DateType.Year: - this.year = value; + year = value; break; case DateType.Month: - this.month = value; + month = value; break; case DateType.Day: - this.day = value; + day = value; break; case DateType.Hour: - this.hour = value; + hour = value; break; case DateType.Minute: - this.minute = value; + minute = value; break; case DateType.Second: - this.second = value; + second = value; break; } } @@ -89,17 +89,17 @@ class PDuration { int getSingle(DateType dateType) { switch (dateType) { case DateType.Year: - return this.year ?? 0; + return year ?? 0; case DateType.Month: - return this.month ?? 0; + return month ?? 0; case DateType.Day: - return this.day ?? 0; + return day ?? 0; case DateType.Hour: - return this.hour ?? 0; + return hour ?? 0; case DateType.Minute: - return this.minute ?? 0; + return minute ?? 0; case DateType.Second: - return this.second ?? 0; + return second ?? 0; } } diff --git a/lib/tools/pickers/time_picker/model/suffix.dart b/lib/tools/pickers/time_picker/model/suffix.dart index b883ce78..a84037f1 100755 --- a/lib/tools/pickers/time_picker/model/suffix.dart +++ b/lib/tools/pickers/time_picker/model/suffix.dart @@ -4,6 +4,23 @@ import 'package:star_lock/tools/pickers/time_picker/model/date_type.dart'; /// 后缀标签 class Suffix { + + Suffix( + {this.years = '', + this.month = '', + this.days = '', + this.hours = '', + this.minutes = '', + this.seconds = ''}); + + Suffix.normal() { + years = '年'; + month = '月'; + days = '日'; + hours = '时'; + minutes = '分'; + seconds = '秒'; + } late String years; late String month; late String days; @@ -11,37 +28,20 @@ class Suffix { late String minutes; late String seconds; - Suffix.normal() { - this.years = '年'; - this.month = '月'; - this.days = '日'; - this.hours = '时'; - this.minutes = '分'; - this.seconds = '秒'; - } - - Suffix( - {this.years: '', - this.month: '', - this.days: '', - this.hours: '', - this.minutes: '', - this.seconds: ''}); - String getSingle(DateType dateType) { switch (dateType) { case DateType.Year: - return this.years; + return years; case DateType.Month: - return this.month; + return month; case DateType.Day: - return this.days; + return days; case DateType.Hour: - return this.hours; + return hours; case DateType.Minute: - return this.minutes; + return minutes; case DateType.Second: - return this.seconds; + return seconds; } } } diff --git a/lib/tools/pickers/time_picker/time_utils.dart b/lib/tools/pickers/time_picker/time_utils.dart index 95a256ae..7c5dca74 100755 --- a/lib/tools/pickers/time_picker/time_utils.dart +++ b/lib/tools/pickers/time_picker/time_utils.dart @@ -71,7 +71,7 @@ class TimeUtils { } String intToStr(int v) { - return (v < 10) ? "0$v" : "$v"; + return (v < 10) ? '0$v' : '$v'; } diff --git a/lib/widget/permission/permission_dialog.dart b/lib/widget/permission/permission_dialog.dart index c15f1737..5d0f1d03 100755 --- a/lib/widget/permission/permission_dialog.dart +++ b/lib/widget/permission/permission_dialog.dart @@ -282,7 +282,7 @@ class PermissionDialog { //显示权限判断申请框 static Future request(Permission permission, [String? content]) async { - AppLog.log('context:${content}'); + AppLog.log('context:$content'); if (Get.context == null) { return false; }