scanBluetoothDevices method
Implementation
@override
Future<List<EspBluetoothDevice>> scanBluetoothDevices() async {
try {
final result = await methodChannel.invokeMethod<List>('searchBleEspDevices');
if (result != null) {
if (result.isEmpty) {
throw PlatformException(code: 'NO_DATA', message: 'No available device.');
}
final devices = result.map<EspBluetoothDevice>((e) {
final data = Map<String, dynamic>.from(e);
return EspBluetoothDevice.fromJson(data);
}).toList();
return devices;
} else {
throw PlatformException(code: 'NO_DATA', message: 'Opps, Something went wrong.');
}
} on PlatformException catch (e) {
throw _onPlatformException(e);
} catch (e) {
rethrow;
}
}