diff --git a/lib/scan_result.dart b/lib/scan_result.dart index 8f29805c..2e7d2b79 100644 --- a/lib/scan_result.dart +++ b/lib/scan_result.dart @@ -27,27 +27,25 @@ class ScanResult { /// A packet of data advertised by the peripheral. final AdvertisementData advertisementData; - + ScanResult._( - this.peripheral, + this.peripheral, this.rssi, - this.advertisementData, - {this.isConnectable, - List<String>? overflowServiceUuids, + this.advertisementData, { + this.isConnectable, + List<String>? overflowServiceUuids, }) : overflowServiceUuids = overflowServiceUuids ?? <String>[]; - factory ScanResult.fromJson( - Map<String, dynamic?> json, - ManagerForPeripheral manager - ) { + Map<String, dynamic?> json, ManagerForPeripheral manager) { assert(json[_ScanResultMetadata.rssi] is int); return ScanResult._( - Peripheral.fromJson(json, manager), + Peripheral.fromJson(json, manager), json[_ScanResultMetadata.rssi], AdvertisementData._fromJson(json), isConnectable: json[_ScanResultMetadata.isConnectable], - overflowServiceUuids: json[_ScanResultMetadata.overflowServiceUuids] + overflowServiceUuids: _mapToListOfStringsOrNull( + json[_ScanResultMetadata.overflowServiceUuids]), ); } } @@ -83,10 +81,8 @@ class AdvertisementData { _mapToListOfStringsOrNull(json[_ScanResultMetadata.serviceUuids]), localName = json[_ScanResultMetadata.localName], txPowerLevel = json[_ScanResultMetadata.txPowerLevel], - solicitedServiceUuids = - _mapToListOfStringsOrNull( - json[_ScanResultMetadata.solicitedServiceUuids] - ); + solicitedServiceUuids = _mapToListOfStringsOrNull( + json[_ScanResultMetadata.solicitedServiceUuids]); static Map<String, Uint8List>? _getServiceDataOrNull( Map<String, dynamic>? serviceData) { @@ -106,3 +102,6 @@ class AdvertisementData { static List<String>? _mapToListOfStringsOrNull(List<dynamic>? values) => values?.cast<String>(); } + +List<String> _mapToListOfStringsOrNull(List<dynamic>? values) => + (values ?? []).cast();