213 lines
6.5 KiB
Dart
213 lines
6.5 KiB
Dart
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 '../../../app_settings/app_colors.dart';
|
|
import '../../../blue/blue_manage.dart';
|
|
import '../../../tools/appRouteObserver.dart';
|
|
import '../../../tools/titleAppBar.dart';
|
|
import '../../../translations/trans_lib.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 logic = Get.put(NearbyLockLogic());
|
|
final state = Get.find<NearbyLockLogic>().state;
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppColors.mainBackgroundColor,
|
|
appBar: F.sw(
|
|
defaultCall: () => TitleAppBar(
|
|
barTitle: TranslationLoader.lanKeys!.nearbyLock!.tr,
|
|
haveBack: true,
|
|
backgroundColor: AppColors.mainColor,
|
|
actionsList: [
|
|
CupertinoActivityIndicator(
|
|
radius: 18.w,
|
|
color: Colors.white,
|
|
),
|
|
SizedBox(width: 30.w)
|
|
]),
|
|
xhjCall: () => TitleAppBar(
|
|
barTitle: TranslationLoader.lanKeys!.nearbyLock!.tr,
|
|
haveBack: true,
|
|
backgroundColor: Colors.white,
|
|
iconColor: AppColors.blackColor,
|
|
titleColor: AppColors.blackColor,
|
|
actionsList: [
|
|
CupertinoActivityIndicator(
|
|
radius: 18.w,
|
|
color: AppColors.blackColor,
|
|
),
|
|
SizedBox(width: 30.w)
|
|
]),
|
|
),
|
|
body: Obx(() {
|
|
return ListView.separated(
|
|
itemCount: state.devices.length,
|
|
itemBuilder: (c, index) {
|
|
return nearbyLockItem(
|
|
'images/icon_lockGroup_item.png', state.devices[index], () {
|
|
// Navigator.pushNamed(context, Routers.lockAddressPage);
|
|
// logic.getPublicKey(state.devices[index].serviceUuids[0].toString());
|
|
state.selectLockName.value =
|
|
state.devices[index].advertisementData.advName;
|
|
logic.connect(state.devices[index].advertisementData.advName);
|
|
// Get.toNamed(Routers.lockAddressGaoDePage);
|
|
});
|
|
},
|
|
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) {
|
|
return GestureDetector(
|
|
onTap: ((scanResult.advertisementData.serviceUuids.isNotEmpty
|
|
? scanResult.advertisementData.serviceUuids[0]
|
|
: "")
|
|
.toString()[33] ==
|
|
"1")
|
|
? action
|
|
: null,
|
|
child: Column(
|
|
// mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
height: 89.h,
|
|
width: 1.sw,
|
|
color: Colors.white,
|
|
child: Row(
|
|
children: [
|
|
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: [
|
|
// 第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(
|
|
'images/main/icon_main_addLock.png',
|
|
width: 36.w,
|
|
height: 36.w,
|
|
),
|
|
SizedBox(width: 30.w),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
// TODO: implement didChangeDependencies
|
|
super.didChangeDependencies();
|
|
|
|
/// 路由订阅
|
|
AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
// TODO: implement 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();
|
|
BlueManage().disconnect();
|
|
}
|
|
|
|
/// 从下级返回 当前界面即将出现
|
|
@override
|
|
void didPopNext() {
|
|
super.didPopNext();
|
|
|
|
state.ifCurrentScreen.value = true;
|
|
logic.startScanBlueList();
|
|
}
|
|
|
|
/// 进入下级界面 当前界面即将消失
|
|
@override
|
|
void didPushNext() {
|
|
super.didPushNext();
|
|
|
|
state.ifCurrentScreen.value = false;
|
|
logic.cancelBlueConnetctToastTimer();
|
|
logic.stopScanBlueList();
|
|
BlueManage().disconnect();
|
|
}
|
|
}
|