Skip to content

Conversation

@craiglabenz
Copy link
Contributor

Refactors the task of tracking MaterialState values for given widgets into a dedicated MaterialStateMixin class. This is added to State<MyWidget> classes to enable simple monitoring of MaterialStates.

MaterialStateMixin was first imagined in the Flutter API Design meeting and is documented here.

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 feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels May 18, 2021
@google-cla google-cla bot added the cla: yes label May 18, 2021
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to invoke the callback even if this is true?

Copy link
Contributor Author

@craiglabenz craiglabenz May 25, 2021

Choose a reason for hiding this comment

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

This is a good question. My intuition was/is that we do not, but I obviously could be wrong. If an item is currently pressed or hovered, etc, re-entering that same state should both be uninteresting and, even worse, a bug.

If there are any known edge cases that imply re-entering a state is both intended and correct, then I think the answer to your question would change to a strong Yes.

Copy link
Member

Choose a reason for hiding this comment

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

If re-entering that same state is a bug, then we should assert here if that happens. I am not sure if it is, though. A button could be in the pressed state already (because a finger is touching it) and now a second finger comes down sending it again into the pressed state it is already in. I don't think this is a bug.

Maybe we can just document on the method that the callback only executes if a change in MaterialState occurs?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should rename it from callback to onChanged to make it clear when this fires.

@craiglabenz craiglabenz force-pushed the material-state-mixin branch from 5e8ad0e to 1e26ec3 Compare May 26, 2021 16:44
@craiglabenz craiglabenz requested a review from johnsonmh May 26, 2021 18:31
Copy link
Member

Choose a reason for hiding this comment

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

If re-entering that same state is a bug, then we should assert here if that happens. I am not sure if it is, though. A button could be in the pressed state already (because a finger is touching it) and now a second finger comes down sending it again into the pressed state it is already in. I don't think this is a bug.

Maybe we can just document on the method that the callback only executes if a change in MaterialState occurs?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should rename it from callback to onChanged to make it clear when this fires.

@craiglabenz craiglabenz force-pushed the material-state-mixin branch from c8aea93 to 4fd2ec2 Compare June 7, 2021 17:59
@craiglabenz craiglabenz requested a review from Hixie June 7, 2021 20:33
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

This is awesome! 🎉

Are there other places in the framework where it can be applied? If there are, you don't have to include them in this change, but it may be worthwhile to open a tracking issue for migrating the other classes that could benefit from this. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

@Piinks Piinks added a: quality A truly polished experience c: new feature Nothing broken; request for a new capability d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation labels Jun 9, 2021
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Flutter_LGTM

@fluttergithubbot fluttergithubbot merged commit 02b46b0 into flutter:master Jun 10, 2021
@craiglabenz craiglabenz deleted the material-state-mixin branch August 23, 2021 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: quality A truly polished experience c: new feature Nothing broken; request for a new capability 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.

5 participants