getDevices method
Implementation
Stream<List<DeviceData>> getDevices() {
return _posEventChannelDevice.receiveBroadcastStream().map((event) {
if (event is String) {
try {
final result = jsonDecode(event);
if (result is Map<String, dynamic>) {
if (result['event'] == 'devicesFound') {
final deviceData = result['data'] as List<dynamic>;
final devices = deviceData
.map((e) => e as Map<String, dynamic>)
.map((e) => DeviceData(e['name'], e['address'], e['isBle']));
return devices.toList();
}
return [];
}
return [];
} catch (e, s) {
log(s.toString());
return [];
}
}
return [];
});
}