app-starlock/lib/mine/gateway/addGateway/selectGateway/selectGatewayList_logic.dart
魏少阳 6b792df101 1、添加网关获取附近WiFi协议及逻辑
2、添加添加网关协议、接口及逻辑
3、添加网关详情功能
4、添加删除网关功能
2024-09-19 09:26:07 +08:00

85 lines
2.4 KiB
Dart

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]}');
// }
}
});
}
void stopScanBlueList() {
// BlueManage().disconnect();
BlueManage().stopScan();
}
void blueDisconnect() {
BlueManage().disconnect();
}
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(ScanResult device) {
showEasyLoading();
showBlueConnetctToastTimer(action: () {
dismissEasyLoading();
});
BlueManage().blueSendData(device.advertisementData.advName, (BluetoothConnectionState state) async {
// AppLog.log('点击要添加的设备了');
if (state == BluetoothConnectionState.connected) {
dismissEasyLoading();
Get.toNamed(Routers.gatewayGetWifiListPage, arguments: {
'macAddress':device.device.remoteId.str
});
} else{
dismissEasyLoading();
}
}, isAddEquipment: true);
}
@override
void onInit() {
super.onInit();
}
@override
void onReady() {
super.onReady();
getNearByLimits();
}
}