Skip to content

Conversation

@nate-thegrate
Copy link
Contributor

Currently, there are 21 .resolveWith() calls in example files.

This pull request changes 11 of them to use the new .fromMap() constructor. (Seven of them are now const!)

ListTile(
  iconColor: WidgetStateColor.fromMap(<WidgetStatesConstraint, Color>{
    WidgetState.disabled: Colors.red,
    WidgetState.selected: Colors.green,
    WidgetState.any:      Colors.black,
  }),
  // The same can be achieved using the .resolveWith() constructor.
  // The text color will be identical to the icon color above.
  textColor: WidgetStateColor.resolveWith((Set<WidgetState> states) {
    if (states.contains(WidgetState.disabled)) {
      return Colors.red;
    }
    if (states.contains(WidgetState.selected)) {
      return Colors.green;
    }
    return Colors.black;
  }),
),

@nate-thegrate nate-thegrate added the refactor Improving readability/efficiency without behavioral changes label Jul 30, 2024
@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: focus Focus traversal, gaining or losing focus labels Jul 30, 2024
@nate-thegrate nate-thegrate marked this pull request as ready for review July 30, 2024 03:39
@justinmc justinmc requested a review from victorsanni August 1, 2024 21:47
@victorsanni
Copy link
Contributor

Linking the original PR: #146043

@victorsanni
Copy link
Contributor

LGTM! Thanks for the PR.

@nate-thegrate nate-thegrate added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 1, 2024
@auto-submit auto-submit bot merged commit 6ff806d into flutter:master Aug 1, 2024
@nate-thegrate nate-thegrate deleted the example-widgetstate-maps branch August 1, 2024 22:28
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 2, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 2, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 2, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 2, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 3, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Aug 3, 2024
Manual roll requested by [email protected]

flutter/flutter@4ff9462...f10a497

2024-08-02 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Shift Linux_build_test tests from MotoG4 to mokey (#152750)" (flutter/flutter#152755)
2024-08-02 [email protected] Shift Linux_build_test tests from MotoG4 to mokey (flutter/flutter#152750)
2024-08-02 [email protected] Roll Flutter Engine from b408111b976c to 077b6f057b69 (1 revision) (flutter/flutter#152745)
2024-08-02 [email protected] Add test for scaffold_state.show_bottom_sheet.0.dart (flutter/flutter#152731)
2024-08-02 [email protected] Roll Flutter Engine from fe39ed980e74 to b408111b976c (6 revisions) (flutter/flutter#152739)
2024-08-02 [email protected] Roll Flutter Engine from ab3f177fb61d to fe39ed980e74 (1 revision) (flutter/flutter#152721)
2024-08-02 [email protected] Roll Flutter Engine from 1cbe88e8115e to ab3f177fb61d (4 revisions) (flutter/flutter#152718)
2024-08-01 [email protected] Roll Flutter Engine from 17e3c7d520e7 to 1cbe88e8115e (5 revisions) (flutter/flutter#152707)
2024-08-01 [email protected] Use `.fromMap()` constructors in example code (flutter/flutter#152535)
2024-08-01 [email protected] Add more widgets to a11y assessment app (flutter/flutter#152662)
2024-08-01 [email protected] Roll Flutter Engine from 230879c7936e to 17e3c7d520e7 (1 revision) (flutter/flutter#152703)
2024-08-01 [email protected] Explain that predictive back doesn't work with WillPopScope (flutter/flutter#152116)
2024-08-01 [email protected] SearchBar.scrollPadding (flutter/flutter#152635)
2024-08-01 [email protected] Quick docs grammar fixes (flutter/flutter#152700)
2024-08-01 [email protected] Roll Flutter Engine from bbb2fcad4808 to 230879c7936e (1 revision) (flutter/flutter#152701)
2024-08-01 [email protected] Disable DDS and Dart profiling for Android driver tests. (flutter/flutter#152696)
2024-08-01 [email protected] Remove one set of parens that wrap a single String literal (flutter/flutter#152031)
2024-08-01 [email protected] Roll Flutter Engine from 7c4a44611abe to bbb2fcad4808 (3 revisions) (flutter/flutter#152694)
2024-08-01 [email protected] Fix bad pattern matching in DDS exception parsing (flutter/flutter#152685)
2024-08-01 [email protected] Roll Packages from 46a712f to 27896d1 (7 revisions) (flutter/flutter#152693)
2024-08-01 [email protected] [CupertinoActionSheet & AlertDialog] Improve documentation and type for `scrollController` parameters (flutter/flutter#152647)
2024-08-01 [email protected] Fix typo in CHANGELOG.md (flutter/flutter#152543)

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 [email protected],[email protected] 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
TytaniumDev pushed a commit to TytaniumDev/flutter that referenced this pull request Aug 7, 2024
Currently, there are 21 `.resolveWith()` calls in example files.

This pull request changes 11 of them to use the new `.fromMap()` constructor. (Seven of them are now `const`!)

```dart
ListTile(
  iconColor: WidgetStateColor.fromMap(<WidgetStatesConstraint, Color>{
    WidgetState.disabled: Colors.red,
    WidgetState.selected: Colors.green,
    WidgetState.any:      Colors.black,
  }),
  // The same can be achieved using the .resolveWith() constructor.
  // The text color will be identical to the icon color above.
  textColor: WidgetStateColor.resolveWith((Set<WidgetState> states) {
    if (states.contains(WidgetState.disabled)) {
      return Colors.red;
    }
    if (states.contains(WidgetState.selected)) {
      return Colors.green;
    }
    return Colors.black;
  }),
),
```
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
Currently, there are 21 `.resolveWith()` calls in example files.

This pull request changes 11 of them to use the new `.fromMap()` constructor. (Seven of them are now `const`!)

```dart
ListTile(
  iconColor: WidgetStateColor.fromMap(<WidgetStatesConstraint, Color>{
    WidgetState.disabled: Colors.red,
    WidgetState.selected: Colors.green,
    WidgetState.any:      Colors.black,
  }),
  // The same can be achieved using the .resolveWith() constructor.
  // The text color will be identical to the icon color above.
  textColor: WidgetStateColor.resolveWith((Set<WidgetState> states) {
    if (states.contains(WidgetState.disabled)) {
      return Colors.red;
    }
    if (states.contains(WidgetState.selected)) {
      return Colors.green;
    }
    return Colors.black;
  }),
),
```
@bleroux
Copy link
Contributor

bleroux commented Nov 21, 2024

@nate-thegrate The new syntax is shorter and the main benefit turned out to be the equality problem it solved.

Nonetheless, while working with it those days, I found it difficult to work with it when debugging is involved.
I mainly work on fixing particular issues, and some are related to wrong states being propagated.
With the old syntax, one can simply add a print statement or a breakpoint to :

  1. Know the states provided for the resolution.
  2. Understand the resolution.

With the new syntax, I did not find a convenient way (other than adding breakpoint into WidgetStateMapper.resolve which is not very friendly when debugging issues with dozen of resolved colors or other properties).

Any idea to mitigate this is welcomed.

@nate-thegrate
Copy link
Contributor Author

Fair point! I agree that there's a tradeoff between using a callback vs. a map in terms of verbosity/performance/debugging.

I bet there are a lot of different ways we could go about improving the debugging experience. Currently there's a way to conveniently convert from stateless → stateful widget; perhaps the same could be done for map → callback.

convert to StatefulWidget

I'll keep this in mind and will try to come up with some alternatives too.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: focus Focus traversal, gaining or losing focus framework flutter/packages/flutter repository. See also f: labels. refactor Improving readability/efficiency without behavioral changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants