85 lines
2.4 KiB
Dart
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();
|
|
}
|
|
} |