BleCharacteristicValue.fromMap constructor

BleCharacteristicValue.fromMap(
  1. Map map
)

Factory constructor that creates an instance of BleCharacteristicValue from a map. This is typically used to convert data coming from the platform side using methods provided by the flutter_splendid_ble plugin.

The map is expected to have the keys 'characteristicUuid', 'deviceAddress', and 'value'.

Example:

final mapData = {
  'characteristicUuid': 'some-uuid',
  'deviceAddress': '00:1A:7D:DA:71:11',
  'value': [10, 20, 30],
};
final charValue = BleCharacteristicValue.fromMap(mapData);
print(charValue.characteristicUuid);  // prints 'some-uuid'

Implementation

factory BleCharacteristicValue.fromMap(Map<dynamic, dynamic> map) {
  try {
    return BleCharacteristicValue(
      characteristicUuid: map['characteristicUuid'] as String,
      deviceAddress: map['deviceAddress'] as String,
      value: (map['value'] as List).map((e) => e as int).toList(),
    );
  } catch (e) {
    throw FormatException(
      'Failed to construct BleCharacteristicValue from Map, $map, with exception, $e',
    );
  }
}