-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
base: master
Are you sure you want to change the base?
Make chip.dart
use WidgetStatesController
#161487
Conversation
There was a problem hiding this 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
statesController.update(WidgetState.disabled, !canTap); | ||
statesController.update(WidgetState.selected, widget.selected); |
There was a problem hiding this comment.
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
if (_canRawChipTap(oldWidget) != _canRawChipTap(widget)) { | ||
setState(() { | ||
setMaterialState(MaterialState.disabled, !widget.isEnabled); | ||
statesController.update(WidgetState.disabled, !canTap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
child: RawChip( | ||
label: const Text('text'), | ||
backgroundColor: backgroundColor, | ||
shape: shape, | ||
onPressed: () {}, | ||
), |
There was a problem hiding this comment.
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
@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 |
Your are right, that it is probably to much of a breaking change. If I understand well, the problem is that Another way would to not share the |
As far as
I agree with the points @bleroux made. I'm leaning toward not sharing the |
174a7a3
to
7208482
Compare
Thank you for the feedbacks @bleroux and @nate-thegrate . I changed the code to not share the states controller with Also, I believe this PR can be exempted from tests? |
2de0a76
to
85704ba
Compare
There was a problem hiding this 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!
Yeah, I think you're right, since the goal here is to factor out |
558d1a7
to
b92cb74
Compare
Any feedback on this @Renzo-Olivares @QuncCccccc ? |
Sorry for the late response! I will take a look at this PR as soon as possible! |
1f59d27
to
f385523
Compare
f385523
to
d6b1ffd
Compare
There was a problem hiding this 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?
Yes, we prefer WidgetStatesController now. MaterialStateMixin has been semi-deprecated for a while. |
(cherry picked from commit 27dfa14192e045ff62c1f93e5d7e9f605341d4d2)
Co-authored-by: Qun Cheng <36861262+QuncCccccc@users.noreply.github.com>
9f1058f
to
722e032
Compare
@QuncCccccc It looks like a rebase did the trick :) |
There was a problem hiding this 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:)
@@ -1011,6 +1009,9 @@ class _RawChipState extends State<RawChip> | |||
late CurvedAnimation enableAnimation; | |||
late CurvedAnimation selectionFade; | |||
|
|||
late final WidgetStatesController statesController = | |||
WidgetStatesController()..addListener(() => setState(() {})); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MitchellGoodwin I made the changes in Add listener after updates
Fixes #128289
Follow up of #128507 and #159422
RawChip
useWidgetStatesController
instead ofMaterialStateMixin
MaterialState
to replace them withWidgetState
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.