315 lines
9.3 KiB
Dart
Executable File
315 lines
9.3 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/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: Obx(listView),
|
|
);
|
|
}
|
|
|
|
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,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
Padding(
|
|
padding: EdgeInsets.only(left: 15.w, bottom: 10.h),
|
|
child: TextButton(
|
|
onPressed: () async {
|
|
bool skip = false;
|
|
if (!state.otaState.value) {
|
|
skip = await Get.dialog(
|
|
const _TipDialog(),
|
|
);
|
|
}
|
|
state.otaState.value = skip;
|
|
},
|
|
child: Text(
|
|
state.otaState.value ? '点击返回设备配对'.tr : '无法连接?尝试升级'.tr,
|
|
style: TextStyle(fontSize: 22.sp),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget nearbyLockItem(
|
|
String lockTypeIcon, ScanResult scanResult, Function() action) {
|
|
return GestureDetector(
|
|
onTap: ((scanResult.advertisementData.serviceUuids.isNotEmpty
|
|
? scanResult.advertisementData.serviceUuids[0]
|
|
: '')
|
|
.toString()[33] ==
|
|
'1')
|
|
? action
|
|
: null,
|
|
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: ((scanResult.advertisementData.serviceUuids
|
|
.isNotEmpty
|
|
? scanResult.advertisementData
|
|
.serviceUuids[0]
|
|
: '')
|
|
.toString()[33] ==
|
|
'1')
|
|
? AppColors.blackColor
|
|
: Colors.grey)),
|
|
],
|
|
),
|
|
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(
|
|
state.otaState.value
|
|
? 'images/ota_upgrade_icon.png'
|
|
: '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();
|
|
if (!logic.state.otaState.value) {
|
|
state.ifCurrentScreen.value = false;
|
|
logic.cancelBlueConnetctToastTimer();
|
|
logic.stopScanBlueList();
|
|
}
|
|
}
|
|
}
|
|
|
|
class _TipDialog extends StatelessWidget {
|
|
const _TipDialog({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CupertinoAlertDialog(
|
|
title: Text(
|
|
'固件升级提示'.tr,
|
|
),
|
|
content: Text('请先获取固件文件到手机本地,再选择升级'.tr),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: Get.back,
|
|
child: Text(
|
|
'取消'.tr,
|
|
style: TextStyle(fontSize: 22.sp, color: AppColors.blackColor),
|
|
),
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
Get.back(result: true);
|
|
},
|
|
child: Text(
|
|
'确定'.tr,
|
|
style: TextStyle(fontSize: 22.sp, color: AppColors.blackColor),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class OTAProgressDialog extends StatelessWidget {
|
|
NearbyLockLogic logic;
|
|
|
|
OTAProgressDialog({required this.logic, Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Obx(() {
|
|
return CupertinoAlertDialog(
|
|
title: Text(
|
|
'固件升级中'.tr,
|
|
),
|
|
content: Column(
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: EdgeInsets.only(top: 20.h, bottom: 10.h),
|
|
child: Text(
|
|
'传输期间请勿离开当前页面'.tr,
|
|
style: TextStyle(fontSize: 20.sp, color: AppColors.blackColor),
|
|
),
|
|
),
|
|
Row(
|
|
children: <Widget>[
|
|
Text(
|
|
'传输中'.tr,
|
|
style: TextStyle(fontSize: 18.sp, color: AppColors.mainColor),
|
|
),
|
|
SizedBox(
|
|
width: 15.w,
|
|
),
|
|
Expanded(
|
|
child: LinearProgressIndicator(
|
|
value: logic.state.otaProgress.value,
|
|
color: AppColors.mainColor,
|
|
)),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: () {
|
|
logic.closeOTADAta();
|
|
},
|
|
child: Text(
|
|
'取消升级'.tr,
|
|
style: TextStyle(fontSize: 22.sp, color: AppColors.blackColor),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
});
|
|
}
|
|
}
|