264 lines
8.4 KiB
Dart
Executable File
264 lines
8.4 KiB
Dart
Executable File
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/appRouters.dart';
|
|
import 'package:star_lock/flavors.dart';
|
|
import 'package:star_lock/mine/addLock/nearbyLock/nearbyLock_state.dart';
|
|
import '../../../app_settings/app_colors.dart';
|
|
import '../../../tools/appRouteObserver.dart';
|
|
import '../../../tools/titleAppBar.dart';
|
|
import 'nearbyLock_logic.dart';
|
|
|
|
class NearbyLockPage extends StatefulWidget {
|
|
const NearbyLockPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<NearbyLockPage> createState() => _NearbyLockPageState();
|
|
}
|
|
|
|
class _NearbyLockPageState extends State<NearbyLockPage> with RouteAware {
|
|
final NearbyLockLogic logic = Get.put(NearbyLockLogic());
|
|
final NearbyLockState state = Get.find<NearbyLockLogic>().state;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppColors.mainBackgroundColor,
|
|
appBar: F.sw(
|
|
skyCall: () => TitleAppBar(
|
|
barTitle: '附近的锁'.tr,
|
|
haveBack: true,
|
|
backgroundColor: AppColors.mainColor,
|
|
actionsList: <Widget>[
|
|
CupertinoActivityIndicator(
|
|
radius: 18.w,
|
|
color: Colors.white,
|
|
),
|
|
SizedBox(width: 30.w)
|
|
]),
|
|
xhjCall: () => TitleAppBar(
|
|
barTitle: '附近的锁'.tr,
|
|
haveBack: true,
|
|
backgroundColor: Colors.white,
|
|
iconColor: AppColors.blackColor,
|
|
titleColor: AppColors.blackColor,
|
|
actionsList: <Widget>[
|
|
CupertinoActivityIndicator(
|
|
radius: 18.w,
|
|
color: AppColors.blackColor,
|
|
),
|
|
SizedBox(width: 30.w)
|
|
]),
|
|
),
|
|
body: Stack(
|
|
children: [
|
|
Obx(listView),
|
|
Positioned(
|
|
left: 16.w,
|
|
bottom: 64.h,
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
Get.toNamed(Routers.lockAddFaqPage);
|
|
},
|
|
child: Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 10.w),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(20.w),
|
|
boxShadow: const <BoxShadow>[
|
|
BoxShadow(
|
|
color: Colors.black12,
|
|
blurRadius: 8,
|
|
offset: Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: Wrap(
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
alignment: WrapAlignment.center,
|
|
children: [
|
|
Icon(Icons.help_outline,
|
|
color: AppColors.touristColor, size: 22.w),
|
|
SizedBox(width: 6.w),
|
|
ConstrainedBox(
|
|
constraints: BoxConstraints(
|
|
maxWidth: 1.sw - 80.w), // 适当减去icon和padding宽度
|
|
child: Text(
|
|
'找不到锁?点此查看。'.tr,
|
|
style: TextStyle(
|
|
color: AppColors.touristColor,
|
|
fontSize: 18.sp,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
maxLines: 3, // 最多显示3行
|
|
overflow: TextOverflow.ellipsis, // 超出部分省略号
|
|
softWrap: true, // 自动换行
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget listView() {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: ListView.separated(
|
|
itemCount: state.devices.length,
|
|
itemBuilder: (BuildContext c, int index) {
|
|
return nearbyLockItem(
|
|
'images/icon_lockGroup_item.png', state.devices[index], () {
|
|
String advName = state.devices[index].advertisementData.advName;
|
|
state.selectLockName.value = advName;
|
|
logic.getServerDatetime();
|
|
});
|
|
},
|
|
separatorBuilder: (BuildContext context, int index) {
|
|
return Divider(
|
|
height: 1,
|
|
color: AppColors.greyLineColor,
|
|
indent: 20.w,
|
|
endIndent: 0,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
// 移除了原有的"无法连接?尝试升级"按钮
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget nearbyLockItem(
|
|
String lockTypeIcon, ScanResult scanResult, Function() action) {
|
|
// 如果广播名称为空或空字符串,则不显示该项
|
|
if (scanResult.advertisementData.advName.isEmpty) {
|
|
return const SizedBox.shrink();
|
|
}
|
|
|
|
return GestureDetector(
|
|
onTap: () {
|
|
final String? serviceUuid =
|
|
scanResult.advertisementData.serviceUuids.isNotEmpty
|
|
? scanResult.advertisementData.serviceUuids[0].toString()
|
|
: null;
|
|
|
|
// 检查 serviceUuid 是否存在且长度足够,并判断第 34 个字符是否为 '1'
|
|
final isPaired = !logic.isPaired(serviceUuid!);
|
|
if (serviceUuid != null && isPaired) {
|
|
action();
|
|
}
|
|
},
|
|
child: Column(
|
|
children: <Widget>[
|
|
Container(
|
|
height: 89.h,
|
|
width: 1.sw,
|
|
color: Colors.white,
|
|
child: Row(
|
|
children: <Widget>[
|
|
SizedBox(width: 20.w),
|
|
Image.asset(
|
|
lockTypeIcon,
|
|
width: 56.w,
|
|
height: 56.w,
|
|
),
|
|
SizedBox(width: 20.w),
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
// 第32、33两位00 表示休眠, 01表示唤醒
|
|
Text(scanResult.advertisementData.advName,
|
|
style: TextStyle(
|
|
fontSize: 20.sp,
|
|
color: logic.isSleeping(
|
|
scanResult.advertisementData.serviceUuids[0]
|
|
.toString(),
|
|
)
|
|
? Colors.grey
|
|
: AppColors.blackColor)),
|
|
],
|
|
),
|
|
SizedBox(
|
|
width: 10.w,
|
|
),
|
|
Image.asset(
|
|
'images/mine/icon_mine_main_about.png',
|
|
width: 22.w,
|
|
height: 22.w,
|
|
),
|
|
Expanded(child: SizedBox(width: 20.w)),
|
|
Image.asset(
|
|
'images/main/icon_main_addLock.png',
|
|
width: 36.w,
|
|
height: 36.w,
|
|
color: AppColors.mainColor,
|
|
),
|
|
SizedBox(width: 30.w),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
super.didChangeDependencies();
|
|
|
|
/// 路由订阅
|
|
AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
/// 取消路由订阅
|
|
AppRouteObserver().routeObserver.unsubscribe(this);
|
|
super.dispose();
|
|
}
|
|
|
|
/// 从上级界面进入 当前界面即将出现
|
|
@override
|
|
void didPush() {
|
|
super.didPush();
|
|
}
|
|
|
|
/// 返回上一个界面 当前界面即将消失
|
|
@override
|
|
void didPop() {
|
|
super.didPop();
|
|
EasyLoading.isShow ? EasyLoading.dismiss() : null;
|
|
state.ifCurrentScreen.value = false;
|
|
logic.cancelBlueConnetctToastTimer();
|
|
logic.stopScanBlueList();
|
|
}
|
|
|
|
/// 从下级返回 当前界面即将出现
|
|
@override
|
|
void didPopNext() {
|
|
super.didPopNext();
|
|
state.ifCurrentScreen.value = true;
|
|
logic.startScanBlueList();
|
|
}
|
|
|
|
/// 进入下级界面 当前界面即将消失
|
|
@override
|
|
void didPushNext() {
|
|
super.didPushNext();
|
|
state.ifCurrentScreen.value = false;
|
|
logic.cancelBlueConnetctToastTimer();
|
|
logic.stopScanBlueList();
|
|
}
|
|
}
|