1、添加网关列表调用接口

2、添加扫描网关逻辑
This commit is contained in:
魏少阳 2024-09-14 16:31:45 +08:00
parent bb97183c18
commit bcb7643a08
12 changed files with 307 additions and 127 deletions

View File

@ -150,34 +150,34 @@ class _GatewayConfigurationWifiPageState extends State<GatewayConfigurationWifiP
}),
),
SizedBox(height: 10.h),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Obx(() => GestureDetector(
child: SizedBox(
// width: 150.w,
height: 50.h,
// color: Colors.red,
child: Center(
child: Text(
state.isUseStaticIP.value
? '不使用静态IP'.tr
: '使用静态IP'.tr,
style: TextStyle(
fontSize: 22.sp, color: AppColors.mainColor)),
),
),
onTap: () {
state.isUseStaticIP.value = !state.isUseStaticIP.value;
},
)),
SizedBox(width: 30.w),
],
),
SizedBox(
height: 50.h,
),
// Row(
// mainAxisAlignment: MainAxisAlignment.end,
// children: <Widget>[
// Obx(() => GestureDetector(
// child: SizedBox(
// // width: 150.w,
// height: 50.h,
// // color: Colors.red,
// child: Center(
// child: Text(
// state.isUseStaticIP.value
// ? '不使用静态IP'.tr
// : '使用静态IP'.tr,
// style: TextStyle(
// fontSize: 22.sp, color: AppColors.mainColor)),
// ),
// ),
// onTap: () {
// state.isUseStaticIP.value = !state.isUseStaticIP.value;
//
// },
// )),
// SizedBox(width: 30.w),
// ],
// ),
// SizedBox(
// height: 50.h,
// ),
],
),
)

View File

@ -0,0 +1,69 @@
import 'dart:io';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:star_lock/tools/baseGetXController.dart';
import '../../../../appRouters.dart';
import '../../../../app_settings/app_settings.dart';
import '../../../../blue/blue_manage.dart';
import '../../../../widget/permission/permission_dialog.dart';
import 'selectGatewayList_state.dart';
class SelectGatewayListLogic extends BaseGetXController {
SelectGatewayListState state = SelectGatewayListState();
void startScanBlueList() {
BlueManage().startScan(2000, (List<ScanResult> list) {
state.devices.clear();
for (int i = 0; i < list.length; i++) {
final ScanResult device = list[i];
// if ((device.advertisementData.serviceUuids.isNotEmpty
// ? device.advertisementData.serviceUuids[0]
// : '')
// .toString()[31] !=
// '1') {
state.devices.add(list[i]);
// AppLog.log('device:${list[i]}');
// }
}
});
}
Future<void> getNearByLimits() async {
if (!Platform.isIOS) {
final bool bluetoothRequest = await PermissionDialog.requestBluetooth();
final bool locationRequest = await PermissionDialog.request(Permission.location);
AppLog.log('locationRequest:$locationRequest');
if (!bluetoothRequest || !locationRequest) {
return;
}
}
startScanBlueList();
}
//
void connect(String deviceName) {
BlueManage().blueSendData(deviceName, (BluetoothConnectionState state) async {
// AppLog.log('点击要添加的设备了');
if (state == BluetoothConnectionState.connected) {
Get.toNamed(Routers.gatewayConfigurationWifiPage);
} else if (state == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
}
}, isAddEquipment: true);
}
@override
void onInit() {
super.onInit();
}
@override
void onReady() {
super.onReady();
getNearByLimits();
}
}

View File

@ -1,11 +1,15 @@
import 'package:flutter/material.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_lock/tools/noData.dart';
import '../../../../appRouters.dart';
import '../../../../app_settings/app_colors.dart';
import '../../../../tools/titleAppBar.dart';
import '../../../../translations/trans_lib.dart';
import 'selectGatewayList_logic.dart';
import 'selectGatewayList_state.dart';
class SelectGatewayListPage extends StatefulWidget {
const SelectGatewayListPage({Key? key}) : super(key: key);
@ -15,6 +19,9 @@ class SelectGatewayListPage extends StatefulWidget {
}
class _SelectGatewayListPageState extends State<SelectGatewayListPage> {
final SelectGatewayListLogic logic = Get.put(SelectGatewayListLogic());
final SelectGatewayListState state = Get.find<SelectGatewayListLogic>().state;
@override
Widget build(BuildContext context) {
return Scaffold(
@ -23,22 +30,33 @@ class _SelectGatewayListPageState extends State<SelectGatewayListPage> {
barTitle: '选择网关'.tr,
haveBack: true,
backgroundColor: AppColors.mainColor),
body: ListView.builder(
itemCount: 10,
itemBuilder: (c, index) {
return _selectGatewayListListItem(
'images/mine/icon_mine_gatewayListMainIcon.png',
'G2 41c21c',
'-34', () {
Navigator.pushNamed(
context, Routers.gatewayConfigurationWifiPage);
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(() =>
state.devices.isNotEmpty?
ListView.builder(
itemCount: state.devices.length,
itemBuilder: (BuildContext c, int index) {
final ScanResult device = state.devices[index];
return _selectGatewayListListItem(device, () {
logic.connect(device.advertisementData.advName);
});
}),
}):NoData()
),
);
}
Widget _selectGatewayListListItem(String lockTypeIcon, String gateWayName,
String networkSignal, Function() action) {
Widget _selectGatewayListListItem(ScanResult device, Function() action) {
return GestureDetector(
onTap: action,
child: Container(
@ -56,7 +74,7 @@ class _SelectGatewayListPageState extends State<SelectGatewayListPage> {
width: 10.w,
),
Image.asset(
lockTypeIcon,
'images/mine/icon_mine_gatewayListMainIcon.png',
width: 60.w,
height: 60.w,
),
@ -67,37 +85,32 @@ class _SelectGatewayListPageState extends State<SelectGatewayListPage> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
// color: Colors.red,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
gateWayName,
style: TextStyle(fontSize: 24.sp),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
device.advertisementData.advName ?? '未知设备',
style: TextStyle(fontSize: 24.sp),
),
],
),
SizedBox(height: 5.h),
Container(
child: 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(
networkSignal,
style: TextStyle(fontSize: 22.sp),
),
],
),
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),
],

View File

@ -0,0 +1,7 @@
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:get/get.dart';
class SelectGatewayListState{
RxList<ScanResult> devices = <ScanResult>[].obs;
}

View File

@ -0,0 +1,38 @@
import 'package:star_lock/tools/baseGetXController.dart';
import '../../../network/api_repository.dart';
import '../../mineSet/transferGateway/selectGetewayList_entity.dart';
import 'gatewayList_state.dart';
class GatewayListLogic extends BaseGetXController {
GatewayListState state = GatewayListState();
//
Future<GetewayDataEntity> getGatewayListData(
{required bool isRefresh}) async {
//
if (isRefresh) {
state.getewayListData.clear();
pageNo = 1;
}
final GetewayDataEntity entity = await ApiRepository.to.getGatewayListData(
pageNo: pageNo.toString(),
pageSize: pageSize,
);
if (entity.errorCode!.codeIsSuccessful) {
//
state.getewayListData.addAll(entity.data!.list!);
//
pageNo++;
}
return entity;
}
@override
void onInit() {
super.onInit();
}
}

View File

@ -4,7 +4,11 @@ import 'package:get/get.dart';
import '../../../appRouters.dart';
import '../../../app_settings/app_colors.dart';
import '../../../tools/storage.dart';
import '../../../tools/titleAppBar.dart';
import '../../mineSet/transferGateway/selectGetewayList_entity.dart';
import 'gatewayList_logic.dart';
import 'gatewayList_state.dart';
class GatewayListPage extends StatefulWidget {
const GatewayListPage({Key? key}) : super(key: key);
@ -14,6 +18,27 @@ class GatewayListPage extends StatefulWidget {
}
class _GatewayListPageState extends State<GatewayListPage> {
final GatewayListLogic logic = Get.put(GatewayListLogic());
final GatewayListState state = Get.find<GatewayListLogic>().state;
Future<void> getHttpData({required bool isRefresh}) async {
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
if (isDemoMode == false) {
logic.getGatewayListData(isRefresh: isRefresh).then((GetewayDataEntity value) {
if (mounted) {
setState(() {});
}
});
}
}
@override
void initState() {
super.initState();
getHttpData(isRefresh: true);
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -22,7 +47,7 @@ class _GatewayListPageState extends State<GatewayListPage> {
barTitle: '网关'.tr,
haveBack: true,
backgroundColor: AppColors.mainColor,
actionsList: [
actionsList: <Widget>[
GestureDetector(
onTap: () {
Get.toNamed(Routers.selectGatewayTypeNextTipPage);
@ -38,14 +63,11 @@ class _GatewayListPageState extends State<GatewayListPage> {
],
),
body: ListView.separated(
itemCount: 5,
itemBuilder: (c, index) {
return _gatewatListItem(
'images/mine/icon_mine_gatewayListMainIcon.png',
'',
'',
'2', () {
Navigator.pushNamed(context, Routers.gatewayDetailPage);
itemCount: state.getewayListData.length,
itemBuilder: (BuildContext c, int index) {
final GetewayItemData item = state.getewayListData[index];
return _gatewatListItem(item, () {
Get.toNamed(Routers.gatewayDetailPage);
});
},
separatorBuilder: (BuildContext context, int index) {
@ -60,8 +82,7 @@ class _GatewayListPageState extends State<GatewayListPage> {
);
}
Widget _gatewatListItem(String lockTypeIcon, String gateWayName,
String isOnline, String lockNumber, Function() action) {
Widget _gatewatListItem(GetewayItemData getewayItemData, Function() action) {
return GestureDetector(
onTap: action,
child: Container(
@ -74,12 +95,12 @@ class _GatewayListPageState extends State<GatewayListPage> {
borderRadius: BorderRadius.circular(10.w),
),
child: Row(
children: [
children: <Widget>[
SizedBox(
width: 10.w,
),
Image.asset(
lockTypeIcon,
'images/mine/icon_mine_gatewayListMainIcon.png',
width: 60.w,
height: 60.w,
),
@ -89,12 +110,12 @@ class _GatewayListPageState extends State<GatewayListPage> {
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
children: <Widget>[
Text(
gateWayName,
getewayItemData.gatewayName ?? '',
style: TextStyle(fontSize: 24.sp),
),
],
@ -102,7 +123,7 @@ class _GatewayListPageState extends State<GatewayListPage> {
SizedBox(height: 5.h),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
children: <Widget>[
Image.asset(
'images/mine/icon_mine_gatewayListOnline.png',
width: 22.w,
@ -112,7 +133,7 @@ class _GatewayListPageState extends State<GatewayListPage> {
width: 10.w,
),
Text(
'',
getewayItemData.isOnline == 1 ? '在线' : '离线',
style: TextStyle(fontSize: 18.sp),
),
SizedBox(
@ -127,7 +148,7 @@ class _GatewayListPageState extends State<GatewayListPage> {
width: 10.w,
),
Text(
'2',
getewayItemData.lockNum.toString(),
style: TextStyle(
fontSize: 18.sp, fontWeight: FontWeight.w500),
),

View File

@ -0,0 +1,9 @@
import 'package:get/get.dart';
import '../../mineSet/transferGateway/selectGetewayList_entity.dart';
class GatewayListState{
final RxList<GetewayItemData> getewayListData = <GetewayItemData>[].obs;
}

View File

@ -1,8 +1,4 @@
class GetewayDataEntity {
int? errorCode;
String? description;
String? errorMsg;
GetewayListData? data;
GetewayDataEntity(
{this.errorCode, this.description, this.errorMsg, this.data});
@ -13,6 +9,10 @@ class GetewayDataEntity {
errorMsg = json['errorMsg'];
data = json['data'] != null ? GetewayListData.fromJson(json['data']) : null;
}
int? errorCode;
String? description;
String? errorMsg;
GetewayListData? data;
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
@ -27,11 +27,6 @@ class GetewayDataEntity {
}
class GetewayListData {
List<GetewayItemData>? list;
int? pageNo;
int? pageSize;
int? pages;
int? total;
GetewayListData({this.list, this.pageNo, this.pageSize, this.pages, this.total});
@ -47,6 +42,11 @@ class GetewayListData {
pages = json['pages'];
total = json['total'];
}
List<GetewayItemData>? list;
int? pageNo;
int? pageSize;
int? pages;
int? total;
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
@ -62,50 +62,71 @@ class GetewayListData {
}
class GetewayItemData {
String? serialNumber;
int? plugId;
String? plugName;
String? networkName;
int? lockNum;
String? plugMac;
String? networkMac;
int? isOnline;
String? plugVersion;
int? select = 0;
GetewayItemData(
{this.serialNumber,
this.plugId,
this.plugName,
this.gatewayMac,
this.gatewayName,
this.gatewayType,
this.networkName,
this.lockNum,
this.plugMac,
this.networkMac,
this.lockNum,
this.isOnline,
this.plugVersion});
this.firmwareInfo,
this.needUpgrade,
this.version,
this.gatewayId});
GetewayItemData.fromJson(Map<String, dynamic> json) {
serialNumber = json['serialNumber'];
plugId = json['plugId'];
plugName = json['plugName'];
gatewayMac = json['gatewayMac'];
gatewayName = json['gatewayName'];
gatewayType = json['gatewayType'];
networkName = json['networkName'];
lockNum = json['lockNum'];
plugMac = json['plugMac'];
networkMac = json['networkMac'];
lockNum = json['lockNum'];
isOnline = json['isOnline'];
plugVersion = json['plugVersion'];
if (json['firmwareInfo'] != null) {
firmwareInfo = <Null>[];
json['firmwareInfo'].forEach((v) {
firmwareInfo!.add(v);
});
}
needUpgrade = json['needUpgrade'];
version = json['version'];
gatewayId = json['gatewayId'];
}
String? serialNumber;
String? gatewayMac;
String? gatewayName;
int? gatewayType;
String? networkName;
String? networkMac;
int? lockNum;
int? isOnline;
List? firmwareInfo;
int? needUpgrade;
String? version;
int? gatewayId;
int? select = 0;
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['serialNumber'] = serialNumber;
data['plugId'] = plugId;
data['plugName'] = plugName;
data['gatewayMac'] = gatewayMac;
data['gatewayName'] = gatewayName;
data['gatewayType'] = gatewayType;
data['networkName'] = networkName;
data['lockNum'] = lockNum;
data['plugMac'] = plugMac;
data['networkMac'] = networkMac;
data['lockNum'] = lockNum;
data['isOnline'] = isOnline;
data['plugVersion'] = plugVersion;
if (firmwareInfo != null) {
data['firmwareInfo'] = firmwareInfo!.map((v) => v.toJson()).toList();
}
data['needUpgrade'] = needUpgrade;
data['version'] = version;
data['gatewayId'] = gatewayId;
return data;
}
}

View File

@ -123,7 +123,7 @@ class _SelectGetewayListPageState extends State<SelectGetewayListPage> {
SizedBox(
width: 16.w,
),
Text(getewayItemData.plugName!, style: TextStyle(fontSize: 24.sp),)
Text(getewayItemData.gatewayName!, style: TextStyle(fontSize: 24.sp),)
],
),
),
@ -143,7 +143,7 @@ class _SelectGetewayListPageState extends State<SelectGetewayListPage> {
for (final GetewayItemData element in state.getewayListData.value) {
if(element.select == 1){
isCanNext = true;
idList.add(element.plugId);
idList.add(element.gatewayId);
}
}
if(isCanNext == false){

View File

@ -148,7 +148,7 @@ abstract class Api {
final String transferLockURL = '/room/transfer'; //
final String removeBadLockURL = '/lock/removeBadLock'; //
final String gatewaykListURL = '/plug/list'; //
final String gatewaykListURL = '/gateway/list'; //
final String transferGatewayConfirmURL =
'/plug/transferPlugConfirm'; //
final String transferGatewayURL = '/plug/transfer'; //

View File

@ -2605,6 +2605,7 @@ class ApiProvider extends BaseProvider {
// 'language': language,
}),
isUnShowLoading: true);
}
extension ExtensionString on String {

View File

@ -2596,4 +2596,5 @@ class ApiRepository {
);
return LoginEntity.fromJson(res.body);
}
}