fix:修复设备列表显示异常的问题

This commit is contained in:
anfe 2024-06-04 16:38:23 +08:00
parent 46caa46338
commit 0593da7598
3 changed files with 151 additions and 96 deletions

View File

@ -10,14 +10,14 @@ import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant import io.flutter.plugins.GeneratedPluginRegistrant
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
class MainActivity: FlutterActivity() { class MainActivity : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(flutterEngine!!) GeneratedPluginRegistrant.registerWith(flutterEngine!!)
MethodChannel(flutterEngine?.dartExecutor!!.binaryMessenger, "starLockFlutterSend").setMethodCallHandler { call, result -> MethodChannel(flutterEngine?.dartExecutor!!.binaryMessenger, "starLockFlutterSend").setMethodCallHandler { call, result ->
if (call.method == "loadNativeShare") { if (call.method == "loadNativeShare") {
var map = call.arguments as Map<String, String> var map = call.arguments as Map<String, String>
shareText(map["shareText"], "分享") shareText(map["shareText"] , "分享")
} else if (call.method == "sendGetBlueStatus") { } else if (call.method == "sendGetBlueStatus") {
// 蓝牙是否开启 // 蓝牙是否开启
// println("收到原生的信息了 methodmethodmethod: ${call.method}") // println("收到原生的信息了 methodmethodmethod: ${call.method}")
@ -58,8 +58,7 @@ class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) { override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine); GeneratedPluginRegistrant.registerWith(flutterEngine);
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "starLockFlutterSend").setMethodCallHandler { MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "starLockFlutterSend").setMethodCallHandler { call, result ->
call, result ->
println("methodmethodmethod: ${call.method}") println("methodmethodmethod: ${call.method}")
// 在这里处理从 Flutter 发送过来的方法调用 // 在这里处理从 Flutter 发送过来的方法调用
if (call.method == "loadNativeShare") { if (call.method == "loadNativeShare") {

View File

@ -230,25 +230,20 @@ class _LockListXHJPageState extends State<LockListXHJPage> with RouteAware {
Widget _xhjLockInfoListItem( Widget _xhjLockInfoListItem(
LockListInfoItemEntity keyInfo, bool isLast, Function() action) { LockListInfoItemEntity keyInfo, bool isLast, Function() action) {
String lockAlias = keyInfo.lockAlias!; final String lockAlias = keyInfo.lockAlias!;
final TextStyle lockAliasTextStyle = TextStyle( final TextStyle lockAliasTextStyle = TextStyle(
fontSize: 24.sp, fontSize: 25.sp,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: keyInfo.passageMode == 1 color: keyInfo.passageMode == 1
? AppColors.openPassageModeColor ? AppColors.openPassageModeColor
: AppColors.darkGrayTextColor, : AppColors.darkGrayTextColor,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
); );
final TextPainter textPainter = TextPainter( final List<String> useKeyTypeListStr = logic.getUseKeyTypeListStr(
text: TextSpan(text: lockAlias, style: lockAliasTextStyle), keyInfo.startDate, keyInfo.endDate, keyInfo.keyType);
maxLines: 1, final bool isThree = useKeyTypeListStr.length == 3;
textDirection: TextDirection.ltr) final bool isOne = useKeyTypeListStr.length == 1;
..layout(minWidth: 0, maxWidth: double.infinity);
final double textSizeWidth = textPainter.size.width; //
if (textSizeWidth > Get.width * .6) {
lockAlias = '${lockAlias.substring(0, 14)}...';
}
return GestureDetector( return GestureDetector(
onTap: action, onTap: action,
child: Container( child: Container(
@ -270,6 +265,7 @@ class _LockListXHJPageState extends State<LockListXHJPage> with RouteAware {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Row( Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Image.asset( Image.asset(
'images/icon_lock_circle.png', 'images/icon_lock_circle.png',
@ -277,50 +273,85 @@ class _LockListXHJPageState extends State<LockListXHJPage> with RouteAware {
height: 48.r, height: 48.r,
color: AppColors.mainColor, color: AppColors.mainColor,
), ),
const Spacer(),
Column(
children: <Widget>[
Row(
children: <Widget>[
Image.asset(
logic.showElectricIcon(keyInfo.electricQuantity!),
width: 30.w,
height: 24.w,
),
SizedBox(width: 2.w),
Text(
'${keyInfo.electricQuantity!}%',
style: TextStyle(
fontSize: 16.sp,
color: AppColors.darkGrayTextColor),
),
],
),
Text(
keyInfo.isLockOwner == 1
? '超级管理员'.tr
: (keyInfo.keyRight == 1 ? '授权管理员'.tr : '普通用户'.tr),
style: TextStyle(
fontSize: 16.sp,
color: AppColors.darkGrayTextColor),
)
],
),
], ],
), ),
SizedBox( SizedBox(
height: 10.h, height: 8.h,
), ),
FittedBox( Text(
fit: BoxFit.scaleDown, lockAlias,
child: Text(lockAlias, style: lockAliasTextStyle, maxLines: 1), style: lockAliasTextStyle,
maxLines: 2,
), ),
Visibility( Row(
visible: keyInfo.passageMode == 1, children: [
child: Padding( Visibility(
padding: EdgeInsets.only(top: 5.h), visible: keyInfo.passageMode == 1,
child: Row( child: Container(
children: <Widget>[ padding:
Container( EdgeInsets.only(top: 5.h, right: 5.w, left: 5.w),
padding: EdgeInsets.only(right: 5.w, left: 5.w), decoration: BoxDecoration(
decoration: BoxDecoration( borderRadius: BorderRadius.circular(5.w),
borderRadius: BorderRadius.circular(5.w), color: AppColors.openPassageModeColor,
color: AppColors.openPassageModeColor, ),
), child: Text('常开模式开启'.tr,
child: Text('常开模式开启'.tr, style: TextStyle(
fontSize: 18.sp,
color: AppColors.appBarIconColor)),
)),
SizedBox(
width: 5.w,
),
Visibility(
visible: keyInfo.lockSetting!.remoteUnlock == 1,
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.only(
top: 5.h, right: 5.w, left: 5.w),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.w),
color: AppColors.mainColor,
),
child: Text(
'远程开锁'.tr,
style: TextStyle( style: TextStyle(
fontSize: 18.sp, fontSize: 18.sp, color: Colors.white),
color: AppColors.appBarIconColor)), ),
), ),
], ],
), )),
)), ],
Visibility( ),
visible: keyInfo.lockSetting!.remoteUnlock == 1,
child: Padding(
padding: EdgeInsets.only(top: 5.h),
child: Row(
children: <Widget>[
Text(
'远程开锁'.tr,
style: TextStyle(
fontSize: 18.sp,
color: AppColors.darkGrayTextColor),
),
],
),
)),
Visibility( Visibility(
visible: (keyInfo.keyType == XSConstantMacro.keyTypeTime || visible: (keyInfo.keyType == XSConstantMacro.keyTypeTime ||
keyInfo.keyType == XSConstantMacro.keyTypeLoop) && keyInfo.keyType == XSConstantMacro.keyTypeLoop) &&
@ -331,7 +362,7 @@ class _LockListXHJPageState extends State<LockListXHJPage> with RouteAware {
keyInfo.keyStatus == keyInfo.keyStatus ==
XSConstantMacro.keyStatusExpired), XSConstantMacro.keyStatusExpired),
child: Padding( child: Padding(
padding: EdgeInsets.only(top: 20.h), padding: EdgeInsets.only(top: 5.h),
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
Container( Container(
@ -353,37 +384,40 @@ class _LockListXHJPageState extends State<LockListXHJPage> with RouteAware {
), ),
)), )),
SizedBox(height: 5.h), SizedBox(height: 5.h),
Row( if (isThree)
children: <Widget>[ Column(
Expanded( crossAxisAlignment: CrossAxisAlignment.start,
child: Text( children: <Widget>[
keyInfo.isLockOwner == 1 Text(
? '超级管理员'.tr Characters(useKeyTypeListStr[0]).join('\u{200B}'),
: (keyInfo.keyRight == 1 ? '授权管理员'.tr : '普通用户'.tr),
style: TextStyle( style: TextStyle(
fontSize: 16.sp, color: AppColors.darkGrayTextColor), fontSize: 16.sp, color: AppColors.darkGrayTextColor),
), ),
), Row(
Image.asset( children: [
logic.showElectricIcon(keyInfo.electricQuantity!), Text(
width: 30.w, Characters(useKeyTypeListStr[1]).join('\u{200B}'),
height: 24.w, style: TextStyle(
), fontSize: 16.sp,
SizedBox(width: 2.w), color: AppColors.darkGrayTextColor),
Text( ),
'${keyInfo.electricQuantity!}%', SizedBox(width: 5.w),
style: TextStyle( Text(
fontSize: 16.sp, color: AppColors.darkGrayTextColor), useKeyTypeListStr[2],
), style: TextStyle(
], fontSize: 16.sp,
), color: AppColors.darkGrayTextColor),
Text( ),
Characters(logic.getUseKeyTypeStr( ],
keyInfo.startDate, keyInfo.endDate, keyInfo.keyType)) ),
.join('\u{200B}'), ],
style: TextStyle( )
fontSize: 16.sp, color: AppColors.darkGrayTextColor), else if (isOne)
) Text(
useKeyTypeListStr[0],
style: TextStyle(
fontSize: 16.sp, color: AppColors.darkGrayTextColor),
),
], ],
), ),
), ),

View File

@ -21,7 +21,7 @@ class BaseGetXController extends GetxController {
bool currentPage = true; bool currentPage = true;
var pageNo = 1; var pageNo = 1;
var pageSize = "20"; var pageSize = '20';
@override @override
void onReady() { void onReady() {
@ -93,7 +93,7 @@ class BaseGetXController extends GetxController {
} }
void showBlueConnetctToast() { void showBlueConnetctToast() {
bool isContains = BlueManage().connectDeviceName.contains("T9A"); bool isContains = BlueManage().connectDeviceName.contains('T9A');
showToast( showToast(
"${'操作失败,请确认锁是否在附近,或重启手机蓝牙后再试。'.tr}${isContains == true ? "如果是全自动锁,请使屏幕变亮" : ""}"); "${'操作失败,请确认锁是否在附近,或重启手机蓝牙后再试。'.tr}${isContains == true ? "如果是全自动锁,请使屏幕变亮" : ""}");
} }
@ -123,10 +123,10 @@ class BaseGetXController extends GetxController {
} }
void showOperationSuccessful({String? status, Function? something}) => void showOperationSuccessful({String? status, Function? something}) =>
showSuccess(status ?? "成功", something: something); showSuccess(status ?? '成功', something: something);
void showOperationFailed({String? status, Function? something}) => void showOperationFailed({String? status, Function? something}) =>
showError(status ?? "失败", something: something); showError(status ?? '失败', something: something);
void logOff() async { void logOff() async {
await ClientManager().logOff(); await ClientManager().logOff();
@ -136,11 +136,11 @@ class BaseGetXController extends GetxController {
void checkBlueIsOpen(void Function() action) { void checkBlueIsOpen(void Function() action) {
NativeInteractionTool().sendGetBlueStatus(); NativeInteractionTool().sendGetBlueStatus();
NativeInteractionTool().receiveChannelBlueIsOnEvent((String status) { NativeInteractionTool().receiveChannelBlueIsOnEvent((String status) {
if (status == "1") { if (status == '1') {
// //
AppLog.log('蓝牙已打开'); AppLog.log('蓝牙已打开');
action(); action();
} else if (status == "0") { } else if (status == '0') {
// //
AppLog.log('蓝牙未打开'); AppLog.log('蓝牙未打开');
showIosTipViewDialog(); showIosTipViewDialog();
@ -148,7 +148,7 @@ class BaseGetXController extends GetxController {
} else { } else {
// //
AppLog.log('设备不支持蓝牙'); AppLog.log('设备不支持蓝牙');
showToast("设备不支持蓝牙"); showToast('设备不支持蓝牙');
return; return;
} }
}); });
@ -159,8 +159,8 @@ class BaseGetXController extends GetxController {
context: Get.context!, context: Get.context!,
builder: (BuildContext context) { builder: (BuildContext context) {
return ShowIosTipView( return ShowIosTipView(
title: "提示", title: '提示',
tipTitle: "蓝牙未打开,请到设置里面打开蓝牙", tipTitle: '蓝牙未打开,请到设置里面打开蓝牙',
sureClick: () { sureClick: () {
Get.back(); Get.back();
if (Platform.isIOS) { if (Platform.isIOS) {
@ -184,23 +184,45 @@ class BaseGetXController extends GetxController {
"${DateTool().dateToYMDHNString(startDate.toString())}-${DateTool().dateToYMDHNString(endDate.toString())} ${"限时".tr}"; "${DateTool().dateToYMDHNString(startDate.toString())}-${DateTool().dateToYMDHNString(endDate.toString())} ${"限时".tr}";
} else if (keyType == XSConstantMacro.keyTypeLong) { } else if (keyType == XSConstantMacro.keyTypeLong) {
// //
// DateTime dateStr = DateTime.fromMillisecondsSinceEpoch(indexEntity.date!);
// useDateStr = '${dateStr.toLocal().toString().substring(0, 16)}\n永久';
useDateStr = '永久'.tr; useDateStr = '永久'.tr;
} else if (keyType == XSConstantMacro.keyTypeOnce) { } else if (keyType == XSConstantMacro.keyTypeOnce) {
// //
// DateTime dateStr = DateTime.fromMillisecondsSinceEpoch(indexEntity.date!);
// useDateStr = '${dateStr.toLocal().toString().substring(0, 16)} \n单次';
useDateStr = '单次'.tr; useDateStr = '单次'.tr;
} else if (keyType == XSConstantMacro.keyTypeLoop) { } else if (keyType == XSConstantMacro.keyTypeLoop) {
// //
useDateStr = useDateStr =
"${DateTool().dateToYMDString(startDate.toString())}-${DateTool().dateToYMDString(endDate.toString())} ${"循环".tr}"; "${DateTool().dateToYMDString(startDate.toString())}-${DateTool().dateToYMDString(endDate.toString())} ${"循环".tr}";
} }
return useDateStr; return useDateStr;
} }
List<String> getUseKeyTypeListStr(
int? startDate, int? endDate, int? keyType) {
final List<String> useDateListStr = <String>[];
if (keyType == XSConstantMacro.keyTypeTime) {
//
useDateListStr.addAll(<String>[
DateTool().dateToYMDHNString(startDate.toString()),
DateTool().dateToYMDHNString(endDate.toString()),
'限时'.tr,
]);
} else if (keyType == XSConstantMacro.keyTypeLong) {
//
useDateListStr.add('永久'.tr);
} else if (keyType == XSConstantMacro.keyTypeOnce) {
//
useDateListStr.add('单次'.tr);
} else if (keyType == XSConstantMacro.keyTypeLoop) {
//
useDateListStr.addAll(<String>[
DateTool().dateToYMDString(startDate.toString()),
DateTool().dateToYMDString(endDate.toString()),
'循环'.tr,
]);
}
return useDateListStr;
}
static List splitList(List list, int len) { static List splitList(List list, int len) {
if (len <= 1) { if (len <= 1) {
return [list]; return [list];