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

Conversation

sjoerd0301
Copy link

iOS has overflow uuids, the list containing these items is a List<dynamic> which couldn't be cast to a List<String>

@CLAassistant
Copy link

CLAassistant commented Mar 24, 2021

CLA assistant check
All committers have signed the CLA.

@@ -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.

👍

}

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.

@sjoerd0301 sjoerd0301 requested a review from mikolak June 24, 2021 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants