BleDevice.fromMap constructor
BleDevice.fromMap(
- Map map
Converts a Map to a BleDevice object.
The map
, which contains information about the discovered Bluetooth device, comes from the plugin's method
channel. Therefore, the type annotation is <dynamic, dynamic>.
Implementation
factory BleDevice.fromMap(Map<dynamic, dynamic> map) {
// Parse the manufacturer data from the string if it exists.
final String? manufacturerDataString = map['manufacturerData'] as String?;
ManufacturerData? manufacturerData;
if (manufacturerDataString != null && manufacturerDataString.isNotEmpty) {
manufacturerData = ManufacturerData.fromString(manufacturerDataString);
}
// Get the advertised service UUIDs, which is a list of strings.
final List<dynamic>? advertisedServiceUuidsDynamic = map['advertisedServiceUuids'] as List<dynamic>?;
final List<String>? advertisedServiceUuids =
advertisedServiceUuidsDynamic?.map((dynamic uuid) => uuid as String).toList();
return BleDevice(
name: map['name'] as String?,
address: map['address'] as String,
advertisedServiceUuids: advertisedServiceUuids ?? [],
rssi: map['rssi'] as int,
manufacturerData: manufacturerData,
);
}