Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions lib/scan_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
);
}
}
Expand Down Expand Up @@ -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) {
Expand All @@ -106,3 +102,6 @@ class AdvertisementData {
static List<String>? _mapToListOfStringsOrNull(List<dynamic>? values) =>
values?.cast<String>();
}

List<String> _mapToListOfStringsOrNull(List<dynamic>? values) =>
(values ?? []).cast();