Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update json scan_result parsing #584

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions lib/scan_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ScanResult {
: peripheral = Peripheral.fromJson(json, manager),
rssi = json[_ScanResultMetadata.rssi],
isConnectable = json[_ScanResultMetadata.isConnectable],
overflowServiceUuids = json[_ScanResultMetadata.overflowServiceUuids],
overflowServiceUuids = _mapToListOfStringsOrNull(json[_ScanResultMetadata.overflowServiceUuids]),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

advertisementData = AdvertisementData._fromJson(json);
}

Expand Down Expand Up @@ -78,12 +78,12 @@ class AdvertisementData {
}

static Uint8List _decodeBase64OrNull(String base64Value) {
if (base64Value != null)
if (base64Value != null) {
return base64.decode(base64Value);
else
} else {
return null;
}
}

static List<String> _mapToListOfStringsOrNull(List<dynamic> values) =>
values?.cast();
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change of behaviour? Most of those properties might be an array or null on native and that's what this function did - either map dynamics from the list to strings or preserve the null.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be a better idea to, with recent nullsafety changes in mind, return an empty list instead of null?
Otherwise it would be no problem to just continue with the values?.cast()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null is a more definitive indication that there are no such values retrieved. I like the idea of eliminating null, but I'd have to examine the rest of this file and analyze if this could be breaking or not. I'll try to do that tomorrow.