Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make chip.dart use WidgetStatesController #161487

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

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.

ValentinVignal and others added 5 commits March 19, 2025 16:24
(cherry picked from commit 27dfa14192e045ff62c1f93e5d7e9f605341d4d2)
Co-authored-by: Qun Cheng <36861262+QuncCccccc@users.noreply.github.com>
@ValentinVignal ValentinVignal force-pushed the flutter/make-chips-use-material-states-controller branch from 9f1058f to 722e032 Compare March 19, 2025 15:24
@dkwingsmt dkwingsmt requested a review from QuncCccccc March 19, 2025 18:41
@ValentinVignal
Copy link
Contributor Author

@QuncCccccc It looks like a rebase did the trick :)

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.

LGTM! Thanks for helping the update:)

@ValentinVignal ValentinVignal added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 21, 2025
@@ -1011,6 +1009,9 @@ class _RawChipState extends State<RawChip>
late CurvedAnimation enableAnimation;
late CurvedAnimation selectionFade;

late final WidgetStatesController statesController =
WidgetStatesController()..addListener(() => setState(() {}));
Copy link
Contributor

@MitchellGoodwin MitchellGoodwin Mar 21, 2025

Choose a reason for hiding this comment

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

Should the listener being added be moved after the .update calls in initState?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I can do that !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ValentinVignal ValentinVignal removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 22, 2025
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