-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Feat: Add momentary varient of CupertinoSlidingSegmentedControl #164262
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
base: master
Are you sure you want to change the base?
Feat: Add momentary varient of CupertinoSlidingSegmentedControl #164262
Conversation
packages/flutter/lib/src/cupertino/sliding_segmented_control.dart
Outdated
Show resolved
Hide resolved
1d13bdb
to
77e7ded
Compare
@QuncCccccc Can you please review this PR ? |
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 contribution!
I compared the native SegmentedControl behavior with the newly added behavior here, and they look quite different.
For native component, when momentary is turned on and we tap/press a segment, the text would animate a little and go back to the original size, and onValueChanged is still get called when we tap one of the segments.
Screen.Recording.2025-03-14.at.3.17.01.PM.mov
I'm not sure what would be the use case of momentary flag, but if we really need this feature, we might want to match the native behavior as much as possible:)
Sure, I'll try to match as much as possible. Edit :- Have allowed onValueChanged onTap and also Updated onTap animation. |
01e0257
to
df72eb9
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 sending another PR! Can you add a dartpad sample to the docs that demonstrates this?
@@ -2126,4 +2126,30 @@ void main() { | |||
|
|||
expect(onValueChangedCalled, 0); | |||
}); | |||
|
|||
testWidgets('CupertinoSlidingSegmentedControl can be momentary', (WidgetTester tester) async { |
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.
There should also be a test to verify the scale was applied correctly.
Also, looking at all the conditionals around this, are each tested?
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.
@Piinks All conditions are added such that it doesn't highlight any item. But yes I can add a test for scale.
Sure, I can add dartpad sample. |
df72eb9
to
9b72c30
Compare
aee2513
to
748d8fa
Compare
This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
Hey @rkishan516, this is the type of change we want to make sure has high fidelity with the native feature. Can you update the PR description with visuals to demonstrate the native behavior and what you are adding here? I see some of the earlier feedback here found some issues when trying to compare. In general, it's preferred to provide a more detailed explanation of your change in PR descriptions. Thank you! |
Sure @Piinks, I will update description. |
748d8fa
to
4a376e5
Compare
4a376e5
to
4b1a806
Compare
This PR introduces a new boolean flag,
isMomentary
, to theCupertinoSlidingSegmentedControl
widget.When
isMomentary
is set totrue
, the segmented control behaves like a momentary switch. Selecting a segment triggers its associated action (e.g., viaonValueChanged
), but the segment doesn't stay visually selected after the interaction ends. The control visually returns to its previous state or a default state (often no segment selected).When
isMomentary
isfalse
(the default behavior), the control maintains the selection state visually, highlighting the last chosen segment.Motivation
Currently,
CupertinoSlidingSegmentedControl
always maintains a selected state. There are use cases where developers might want to use the segmented control purely for triggering actions without persisting a visual selection state, similar to how aUISegmentedControl
can be configured on iOS withisMomentary = true
. This provides more flexibility and aligns the Flutter widget closer to its native counterpart's capabilities.For example, this could be useful for triggering sorting actions, view changes, or other immediate operations where maintaining a persistent "selected" state isn't desired or meaningful.
Related Issues
fixes: #164077
Videos
UISegmentedControl behaviour when
isMomentary
flag is set to true.https://github.com/user-attachments/assets/84d00312-4530-4b7a-9696-142f60ad89c0
CupertinoSlidingSegmentedControl behaviour when
isMomentary
flag is set to true.https://github.com/user-attachments/assets/b308b4fa-e641-417a-a518-4e0908876eed
Pre-launch Checklist
///
).