Skip to content

Conversation

@ValentinVignal
Copy link
Contributor

Fixes #128289

Follow up of #128507 and #159422

  • Makes RawChip use WidgetStatesController instead of MaterialStateMixin
  • Remove references of MaterialState to replace them with WidgetState

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Jan 12, 2025
Copy link
Contributor Author

@ValentinVignal ValentinVignal left a comment

Choose a reason for hiding this comment

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

I had to make the behavior of chips consistent with InkWell to not hit the issue:

The widget on which setState() or markNeedsBuild() was called was:
  RawChip
The widget which was currently being built when the offending call was made was:
  InkWell

Comment on lines 1030 to 1032
statesController.update(WidgetState.disabled, !canTap);
statesController.update(WidgetState.selected, widget.selected);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to use canTap instead of widget.isEnabled as InkWell does its logic on the provided callbacks

Comment on lines 1218 to 1220
if (_canRawChipTap(oldWidget) != _canRawChipTap(widget)) {
setState(() {
setMaterialState(MaterialState.disabled, !widget.isEnabled);
statesController.update(WidgetState.disabled, !canTap);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here

Comment on lines 4732 to 4737
child: RawChip(
label: const Text('text'),
backgroundColor: backgroundColor,
shape: shape,
onPressed: () {},
),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This also introduces this breaking change. A callback needs to be provided in order for the chip to be truly enabled

@ValentinVignal
Copy link
Contributor Author

@bleroux @nate-thegrate @victorsanni , here is the follow up of what we discussed #159422.

I put comments where there are some potential issues that could make this PR not mergeable. Tell me what you think about it

@bleroux
Copy link
Contributor

bleroux commented Jan 13, 2025

Your are right, that it is probably to much of a breaking change.

If I understand well, the problem is that InkWell will change the WidgetStatesController state to disabled when there is no callback and this collides with RawChip definition of the disabled state.
Can't we pass a non-empty callbalk directly to the InkWell created on line 1402 based on RawChip.isEnabled (that way both will be enabled or disabled at the same time, or maybe this is not enough because InkWell can be enabled due to other callbacks being defined?

Another way would to not share the WidgetStatesController between the RawChip and the InkWell, but in that case not sure it is worth using WidgetStatesController instead of MaterialStateMixin?

@TahaTesser TahaTesser removed their request for review January 13, 2025 10:27
@nate-thegrate
Copy link
Contributor

As far as MaterialStateMixin, I believe there are two ways forward:

  1. Deprecate & rename to WidgetStateMixin
  2. Use WidgetStatesController instead
    (the mixin could either be deprecated or moved out once we decide where the other legacy Material 2 things are going)

I agree with the points @bleroux made. I'm leaning toward not sharing the WidgetStatesController between the RawChip and the InkWell: it's true that this would reduce the benefit of the states controller over the mixin, but given that the mixin is only used by 2 classes in the framework, it might make the most sense to stop using it, so future maintainers would have one less thing to learn.

@ValentinVignal ValentinVignal force-pushed the flutter/make-chips-use-material-states-controller branch from 174a7a3 to 7208482 Compare January 25, 2025 14:42
@ValentinVignal
Copy link
Contributor Author

Thank you for the feedbacks @bleroux and @nate-thegrate . I changed the code to not share the states controller with InkWell.

Also, I believe this PR can be exempted from tests?

@ValentinVignal ValentinVignal force-pushed the flutter/make-chips-use-material-states-controller branch from 2de0a76 to 85704ba Compare January 26, 2025 05:36
Copy link
Contributor

@nate-thegrate nate-thegrate left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for following up here!

@nate-thegrate
Copy link
Contributor

I believe this PR can be exempted from tests?

Yeah, I think you're right, since the goal here is to factor out MaterialStateMixin without any changes to functionality. Feel free to reach out in hackers-💭 for an exemption :)

@nate-thegrate nate-thegrate added the refactor Improving readability/efficiency without behavioral changes label Jan 27, 2025
@victorsanni victorsanni removed their request for review January 30, 2025 17:47
@ValentinVignal ValentinVignal force-pushed the flutter/make-chips-use-material-states-controller branch from 558d1a7 to b92cb74 Compare February 7, 2025 08:31
@ValentinVignal
Copy link
Contributor Author

Any feedback on this @Renzo-Olivares @QuncCccccc ?

@QuncCccccc
Copy link
Contributor

Sorry for the late response! I will take a look at this PR as soon as possible!

@ValentinVignal ValentinVignal force-pushed the flutter/make-chips-use-material-states-controller branch 2 times, most recently from 1f59d27 to f385523 Compare February 26, 2025 08:51
@ValentinVignal ValentinVignal force-pushed the flutter/make-chips-use-material-states-controller branch from f385523 to d6b1ffd Compare March 10, 2025 10:57
Copy link
Contributor

@QuncCccccc QuncCccccc 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 your patience. Could you help fix the failed tests?

Just a question, do we want to use WidgetStatesController to replace MaterialStateMixin? I'm actually not super familiar with the context, maybe @MitchellGoodwin have any thoughts?

@MitchellGoodwin
Copy link
Contributor

Just a question, do we want to use WidgetStatesController to replace MaterialStateMixin?

Yes, we prefer WidgetStatesController now. MaterialStateMixin has been semi-deprecated for a while.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 29, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 29, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 21, 2025
zhangyuang pushed a commit to zhangyuang/flutter-fork that referenced this pull request Jun 9, 2025
Fixes flutter#128289

Follow up of flutter#128507 and
flutter#159422

- Makes `RawChip` use `WidgetStatesController` instead of
`MaterialStateMixin`
- Remove references of `MaterialState` to replace them with
`WidgetState`

## Pre-launch Checklist

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

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: Qun Cheng <[email protected]>
romanejaquez pushed a commit to romanejaquez/flutter that referenced this pull request Aug 14, 2025
Fixes flutter#128289

Follow up of flutter#128507 and
flutter#159422

- Makes `RawChip` use `WidgetStatesController` instead of
`MaterialStateMixin`
- Remove references of `MaterialState` to replace them with
`WidgetState`

## Pre-launch Checklist

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

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: Qun Cheng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. 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.

Update chip.dart to use set of MaterialState

5 participants