195 lines
6.0 KiB
Dart
Executable File
195 lines
6.0 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/app_settings/app_settings.dart';
|
|
import 'package:star_lock/tools/noData.dart';
|
|
|
|
import '../../../../appRouters.dart';
|
|
import '../../../../app_settings/app_colors.dart';
|
|
import '../../../../tools/appRouteObserver.dart';
|
|
import '../../../../tools/titleAppBar.dart';
|
|
import 'selectGatewayList_logic.dart';
|
|
import 'selectGatewayList_state.dart';
|
|
|
|
class SelectGatewayListPage extends StatefulWidget {
|
|
const SelectGatewayListPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<SelectGatewayListPage> createState() => _SelectGatewayListPageState();
|
|
}
|
|
|
|
class _SelectGatewayListPageState extends State<SelectGatewayListPage>
|
|
with RouteAware {
|
|
final SelectGatewayListLogic logic = Get.put(SelectGatewayListLogic());
|
|
final SelectGatewayListState state = Get.find<SelectGatewayListLogic>().state;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppColors.mainBackgroundColor,
|
|
appBar: TitleAppBar(
|
|
barTitle: '选择网关'.tr,
|
|
haveBack: true,
|
|
backgroundColor: AppColors.mainColor,
|
|
actionsList: <Widget>[
|
|
CupertinoActivityIndicator(
|
|
radius: 18.w,
|
|
color: Colors.white,
|
|
),
|
|
SizedBox(width: 30.w)
|
|
]),
|
|
body:
|
|
// ListView.builder(
|
|
// itemCount: 10,
|
|
// itemBuilder: (BuildContext c, int index) {
|
|
// return _selectGatewayListListItem(
|
|
// 'images/mine/icon_mine_gatewayListMainIcon.png',
|
|
// 'G2 41c21c',
|
|
// '-34', () {
|
|
// Navigator.pushNamed(
|
|
// context, Routers.gatewayConfigurationWifiPage);
|
|
// });
|
|
// })
|
|
Obx(() => ListView.builder(
|
|
itemCount: state.devices.length,
|
|
itemBuilder: (BuildContext c, int index) {
|
|
final ScanResult device = state.devices[index];
|
|
return _selectGatewayListListItem(device, () {
|
|
state.currentDevice = device;
|
|
logic.connect(device);
|
|
});
|
|
})),
|
|
);
|
|
}
|
|
|
|
Widget _selectGatewayListListItem(ScanResult device, Function() action) {
|
|
return GestureDetector(
|
|
onTap: action,
|
|
child: Container(
|
|
// height: 100.h,
|
|
margin: const EdgeInsets.only(bottom: 2),
|
|
padding:
|
|
EdgeInsets.only(left: 10.w, right: 20.w, top: 16.h, bottom: 16.h),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(10.w),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
SizedBox(
|
|
width: 10.w,
|
|
),
|
|
Image.asset(
|
|
'images/mine/icon_mine_gatewayListMainIcon.png',
|
|
width: 60.w,
|
|
height: 60.w,
|
|
),
|
|
SizedBox(
|
|
width: 20.w,
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
device.advertisementData.advName ?? '未知设备',
|
|
style: TextStyle(fontSize: 24.sp),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 5.h),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Image.asset(
|
|
'images/mine/icon_mine_gatewaySignal_strong.png',
|
|
width: 22.w,
|
|
height: 22.w,
|
|
),
|
|
SizedBox(
|
|
width: 10.w,
|
|
),
|
|
Text(
|
|
device.rssi.toString(),
|
|
style: TextStyle(fontSize: 22.sp),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(width: 20.h),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(width: 20.h),
|
|
Image.asset(
|
|
'images/icon_add_white.png',
|
|
width: 36.w,
|
|
height: 36.w,
|
|
color: AppColors.mainColor,
|
|
),
|
|
SizedBox(
|
|
width: 20.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
|
|
Future<void> didPop() async {
|
|
super.didPop();
|
|
|
|
EasyLoading.isShow ? EasyLoading.dismiss() : null;
|
|
logic.cancelBlueConnetctToastTimer();
|
|
logic.blueDisconnect();
|
|
await Future.delayed(Duration(milliseconds: 500));
|
|
await logic.stopScanBlueList();
|
|
AppLog.log('停止网关列表 didPop被调用了');
|
|
}
|
|
|
|
/// 从下级返回 当前界面即将出现
|
|
@override
|
|
void didPopNext() {
|
|
super.didPopNext();
|
|
AppLog.log('扫描网关列表 didPopNext被调用了');
|
|
logic.blueDisconnect();
|
|
logic.startScanBlueList();
|
|
}
|
|
|
|
/// 进入下级界面 当前界面即将消失
|
|
@override
|
|
void didPushNext() {
|
|
super.didPushNext();
|
|
logic.cancelBlueConnetctToastTimer();
|
|
logic.stopScanBlueList();
|
|
}
|
|
}
|