Skip to content

Conversation

@mfiels
Copy link
Contributor

@mfiels mfiels commented Jun 30, 2018

I noticed this while playing around with Flutter on the latest VM internally.

The IntelliJ plugin was silently failing to discover my iOS simulators. It was due to this code hitting runtime type errors under 2.0.0-dev.66.0:

type 'List<dynamic>' is not a subtype of type 'List<Map<String, String>>'
#0      SimControl.getDevices (package:flutter_tools/src/ios/simulators.dart:100:67)

I added a test that passes without thesimulators.dart changes when run with 2.0.0-dev.63.0, and fails with 2.0.0-dev.66.0.

With the simulators.dart changes the test passes when run with either 2.0.0-dev.63.0 or 2.0.0-dev.66.0.

This is due to the way the JSON is represented here as a Map<String, dynamic>. This code feels pretty loose with types in general and could probably be cleaned up a bit more, but I'm just looking to take the path of least resistance to getting the IntelliJ plugin's device discovery working again.

Copy link
Contributor

@devoncarew devoncarew left a comment

Choose a reason for hiding this comment

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

I noticed this while playing around with Flutter on the latest VM internally.

Cool, I was wondering how you were running flutter_tools in --preview-dart-2.

I have some pretty specific comments in-line, which closely parallels work that I have locally.

This code feels pretty loose with types in general

Yeah, this was written before strong mode at runtime was a thing. The types on the left are more an indication of what we'd want the types to be, rather than what they actually are.

Copy link
Contributor

@devoncarew devoncarew Jun 30, 2018

Choose a reason for hiding this comment

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

I'd change the definition of _list() to return Map<String, dynamic> instead of a raw dynamic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps something like:

  final List<dynamic> devicesData = devicesSection[deviceCategory];
  for (Map<String, dynamic> data in devicesData.map(castStringKeyedMap)) {
    devices.add(new SimDevice(deviceCategory, data));
  }

and castStringKeyedMap would look like:

Map<String, dynamic> castStringKeyedMap(dynamic untyped) {
  final Map<dynamic, dynamic> map = untyped;
  return map.cast<String, dynamic>();
}

The casting will ensure that the items in the list we iterate over are Map<String, dynamic> typed, and not Map<dynamic, dynamic>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can avoid converting to the toString() values here and below, and assume that the values in the map are strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@mfiels mfiels force-pushed the fix-ios-discovery branch from 4aa63d7 to 482ac57 Compare June 30, 2018 23:40
@mfiels mfiels force-pushed the fix-ios-discovery branch from 482ac57 to 73f46b6 Compare June 30, 2018 23:42
@mfiels
Copy link
Contributor Author

mfiels commented Jun 30, 2018

Thanks for the review! Squashed and re-uploaded, PTAL.

Copy link
Contributor

@devoncarew devoncarew left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for the contribution.

@devoncarew devoncarew merged commit af5d4c6 into flutter:master Jul 1, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants