Skip to content

Conversation

@darrenaustin
Copy link
Contributor

Currently if you want to create a MaterialStateProperty that always returns the same value regardless of the current states, you could use the .all static method:

final color = MaterialStateColor.all<Color>(Colors.blue);

However this can be a const value which makes it harder to use with const ButtonStyles and other structures that could be const otherwise.

This PR adds a new MaterialStatePropertyAll class that allows you to convert the above code to:

const color = MaterialStateColorAll<Color>(Colors.blue);

Which can then be used in other const structures.

We may deprecate MaterialStateProperty.all in the future, but didn't want to do this without a dart fix for it. As it turns out, this isn't a case that can be currently handled by dart fix. When it is, we will probably deprecate it.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. labels May 18, 2022
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

@darrenaustin darrenaustin merged commit 17e2fce into flutter:master May 19, 2022
@darrenaustin darrenaustin deleted the material_state_all branch May 19, 2022 16:35
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 19, 2022
@TahaTesser
Copy link
Member

@darrenaustin
This is great!

@darrenaustin
Copy link
Contributor Author

This is great!

Thanks, but all credit to @HansMuller for the idea.

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 c: contributor-productivity Team-specific productivity, code health, technical debt. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants