Skip to content

Conversation

sigurdm
Copy link
Contributor

@sigurdm sigurdm commented Jun 12, 2025

Fixes #161927

@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jun 12, 2025
@sigurdm sigurdm requested review from matanlurey and bkonyi June 12, 2025 13:10
if (list == null) {
return <String>[];
}
if (list is! List<Object?>) {
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 this function can just be if section not being present is an error:

if (map case {section: final List<String>? list when map.containsKey(section)) {
  return list ?? <String>[];
}
throw FormatException('Expected `$section` to be `List<String>?`, got `${map[section]}');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When trying that i get: Key expressions in map patterns must be constants.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh that's annoying... Honestly, I'd remove this helper and just use the pattern above in its place with the constant keys. This helper function is doing a lot of unnecessary checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One more thing. When you read json the List doesn't become a List<String> it is a List<Object?>, and you need to validate each item separately and cast the list. I don't think that can be done with pattern matching...

Copy link
Contributor

Choose a reason for hiding this comment

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

This definitely works with pattern matching:

final json = <String, Object?>{
  'foo': <String>['bar', 'baz'],
};

final jsonWithNull = <String, Object?>{
  'foo': <String?>['bar', 'baz', null],
};
void main() {
  if (json case {'foo': final List<String> list}) {
    print('Destructured JSON list: $list Runtime type: ${list.runtimeType}');
  } else {
    print('Failed to destructure $json');
  }

  if (jsonWithNull case {'foo': final List<String> list}) {
    print('Destructured JSON list: $list Runtime type: ${list.runtimeType}');
  } else {
    print('Failed to destructure $jsonWithNull');
  }

  if (jsonWithNull case {'foo': final List<String?> list}) {
    print('Destructured JSON list: $list Runtime type: ${list.runtimeType}');
  } else {
    print('Failed to destructure $jsonWithNull');
  }
}

Outputs:

Destructured JSON list: [bar, baz] Runtime type: List<String>
Failed to destructure {foo: [bar, baz, null]}
Destructured JSON list: [bar, baz, null] Runtime type: List<String?>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but when you read json, it doesn't type the lists as <String>[]. but List<dynamic> (which matches List<Object?>).

import 'dart:convert';

main() {
  switch (jsonDecode('["A", "B", "C"]')) {
    case final List<String> a:
      print('List of String');
    case final List<Object?> a:
      print('List of Object');
    case final a:
      print('Something else ${a.runtimeType}');
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, good point... that's really annoying behavior since map patterns are supposed to be most useful for JSON destructuring...

Anyway, this approach would be less verbose than the current one:

List<String> _parseList(Map<String, Object?> map, String section) {
  final Object? result = map[section];
  try {
    return (result as List<Object?>?)?.cast<String>() ?? <String>[];
  } on TypeError {
    throw FormatException(
      'Expected `$section` to be `List<String>`, got ${result.runtimeType}',
    );
  }
}

Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

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

LGTM, but defer final approval to Ben.

@bkonyi
Copy link
Contributor

bkonyi commented Jun 16, 2025

Once we remove _parseList, this will LGTM.

Copy link
Contributor

@bkonyi bkonyi left a comment

Choose a reason for hiding this comment

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

Thanks for humoring me 😅 LGTM!

@sigurdm sigurdm added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 23, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Jun 23, 2025
Merged via the queue into flutter:master with commit a0e30bf Jun 23, 2025
138 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 23, 2025
@sigurdm
Copy link
Contributor Author

sigurdm commented Jun 23, 2025

@bkonyi thanks! Yeah - async code review is tough sometimes. But thanks for being insistent on code quality!

auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jun 23, 2025
flutter/flutter@0ab008a...d733bea

2025-06-23 mdebbar@google.com Add `--no-web-resources-cdn` to all web integration tests (flutter/flutter#171013)
2025-06-23 bkonyi@google.com [ Tool ] Roll package:dds 5.0.4 (flutter/flutter#171007)
2025-06-23 jessiewong401@gmail.com Update Docs to Warn Users Edge-To-Edge opt out is being deprecated for Android 16+ (API 36+) (flutter/flutter#170816)
2025-06-23 30870216+gaaclarke@users.noreply.github.com License cpp jun20 (flutter/flutter#170948)
2025-06-23 mdebbar@google.com Un-bringup `Linux web_tool_tests` (flutter/flutter#171004)
2025-06-23 engine-flutter-autoroll@skia.org Roll Packages from 7f41e75 to 02770da (5 revisions) (flutter/flutter#171006)
2025-06-23 engine-flutter-autoroll@skia.org Roll Dart SDK from bb16990911b5 to a09de0d3556c (2 revisions) (flutter/flutter#171000)
2025-06-23 bruno.leroux@gmail.com Reland: Fix InputDecoration.floatingLabelBehavior is not inherited (flutter/flutter#170995)
2025-06-23 engine-flutter-autoroll@skia.org Roll Skia from aef4081157f0 to 0311837abe86 (1 revision) (flutter/flutter#170992)
2025-06-23 sigurdm@google.com Run pub get post-processing for each package in workspace (flutter/flutter#170517)
2025-06-23 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fix InputDecoration.floatingLabelBehavior is not inherited (#170905)" (flutter/flutter#170994)
2025-06-23 bruno.leroux@gmail.com Fix InputDecoration.floatingLabelBehavior is not inherited (flutter/flutter#170905)
2025-06-23 engine-flutter-autoroll@skia.org Roll Skia from fcd1c55da9cc to aef4081157f0 (1 revision) (flutter/flutter#170990)
2025-06-22 robert.ancell@canonical.com Clear background in the GTK layer, instead of OpenGL (flutter/flutter#170840)
2025-06-22 robert.ancell@canonical.com Show window on first frame on Linux (flutter/flutter#170844)
2025-06-22 engine-flutter-autoroll@skia.org Roll Dart SDK from 98db1db5ff65 to bb16990911b5 (1 revision) (flutter/flutter#170988)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC muhatashim@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Ortes pushed a commit to Ortes/packages that referenced this pull request Jun 25, 2025
…r#9478)

flutter/flutter@0ab008a...d733bea

2025-06-23 mdebbar@google.com Add `--no-web-resources-cdn` to all web integration tests (flutter/flutter#171013)
2025-06-23 bkonyi@google.com [ Tool ] Roll package:dds 5.0.4 (flutter/flutter#171007)
2025-06-23 jessiewong401@gmail.com Update Docs to Warn Users Edge-To-Edge opt out is being deprecated for Android 16+ (API 36+) (flutter/flutter#170816)
2025-06-23 30870216+gaaclarke@users.noreply.github.com License cpp jun20 (flutter/flutter#170948)
2025-06-23 mdebbar@google.com Un-bringup `Linux web_tool_tests` (flutter/flutter#171004)
2025-06-23 engine-flutter-autoroll@skia.org Roll Packages from 7f41e75 to 02770da (5 revisions) (flutter/flutter#171006)
2025-06-23 engine-flutter-autoroll@skia.org Roll Dart SDK from bb16990911b5 to a09de0d3556c (2 revisions) (flutter/flutter#171000)
2025-06-23 bruno.leroux@gmail.com Reland: Fix InputDecoration.floatingLabelBehavior is not inherited (flutter/flutter#170995)
2025-06-23 engine-flutter-autoroll@skia.org Roll Skia from aef4081157f0 to 0311837abe86 (1 revision) (flutter/flutter#170992)
2025-06-23 sigurdm@google.com Run pub get post-processing for each package in workspace (flutter/flutter#170517)
2025-06-23 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fix InputDecoration.floatingLabelBehavior is not inherited (#170905)" (flutter/flutter#170994)
2025-06-23 bruno.leroux@gmail.com Fix InputDecoration.floatingLabelBehavior is not inherited (flutter/flutter#170905)
2025-06-23 engine-flutter-autoroll@skia.org Roll Skia from fcd1c55da9cc to aef4081157f0 (1 revision) (flutter/flutter#170990)
2025-06-22 robert.ancell@canonical.com Clear background in the GTK layer, instead of OpenGL (flutter/flutter#170840)
2025-06-22 robert.ancell@canonical.com Show window on first frame on Linux (flutter/flutter#170844)
2025-06-22 engine-flutter-autoroll@skia.org Roll Dart SDK from 98db1db5ff65 to bb16990911b5 (1 revision) (flutter/flutter#170988)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC muhatashim@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
mboetger pushed a commit to mboetger/flutter that referenced this pull request Jul 21, 2025
vashworth pushed a commit to vashworth/packages that referenced this pull request Jul 30, 2025
…r#9478)

flutter/flutter@0ab008a...d733bea

2025-06-23 mdebbar@google.com Add `--no-web-resources-cdn` to all web integration tests (flutter/flutter#171013)
2025-06-23 bkonyi@google.com [ Tool ] Roll package:dds 5.0.4 (flutter/flutter#171007)
2025-06-23 jessiewong401@gmail.com Update Docs to Warn Users Edge-To-Edge opt out is being deprecated for Android 16+ (API 36+) (flutter/flutter#170816)
2025-06-23 30870216+gaaclarke@users.noreply.github.com License cpp jun20 (flutter/flutter#170948)
2025-06-23 mdebbar@google.com Un-bringup `Linux web_tool_tests` (flutter/flutter#171004)
2025-06-23 engine-flutter-autoroll@skia.org Roll Packages from 7f41e75 to 02770da (5 revisions) (flutter/flutter#171006)
2025-06-23 engine-flutter-autoroll@skia.org Roll Dart SDK from bb16990911b5 to a09de0d3556c (2 revisions) (flutter/flutter#171000)
2025-06-23 bruno.leroux@gmail.com Reland: Fix InputDecoration.floatingLabelBehavior is not inherited (flutter/flutter#170995)
2025-06-23 engine-flutter-autoroll@skia.org Roll Skia from aef4081157f0 to 0311837abe86 (1 revision) (flutter/flutter#170992)
2025-06-23 sigurdm@google.com Run pub get post-processing for each package in workspace (flutter/flutter#170517)
2025-06-23 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fix InputDecoration.floatingLabelBehavior is not inherited (#170905)" (flutter/flutter#170994)
2025-06-23 bruno.leroux@gmail.com Fix InputDecoration.floatingLabelBehavior is not inherited (flutter/flutter#170905)
2025-06-23 engine-flutter-autoroll@skia.org Roll Skia from fcd1c55da9cc to aef4081157f0 (1 revision) (flutter/flutter#170990)
2025-06-22 robert.ancell@canonical.com Clear background in the GTK layer, instead of OpenGL (flutter/flutter#170840)
2025-06-22 robert.ancell@canonical.com Show window on first frame on Linux (flutter/flutter#170844)
2025-06-22 engine-flutter-autoroll@skia.org Roll Dart SDK from 98db1db5ff65 to bb16990911b5 (1 revision) (flutter/flutter#170988)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC muhatashim@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Native folders (.android, .ios, etc.) are not created for add-to-app module when run "pub get" in workspace
3 participants