Skip to content

Conversation

@rkishan516
Copy link
Contributor

@rkishan516 rkishan516 commented Feb 27, 2025

This PR introduces a new boolean flag, isMomentary, to the CupertinoSlidingSegmentedControl widget.

When isMomentary is set to true, the segmented control behaves like a momentary switch. Selecting a segment triggers its associated action (e.g., via onValueChanged), 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 is false (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 a UISegmentedControl can be configured on iOS with isMomentary = 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

  • 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 this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: cupertino flutter/packages/flutter/cupertino repository labels Feb 27, 2025
@rkishan516 rkishan516 force-pushed the sliding-segmented-control-momentary branch from 1d13bdb to 77e7ded Compare February 28, 2025 16:41
@rkishan516
Copy link
Contributor Author

@QuncCccccc Can you please review this PR ?

@QuncCccccc QuncCccccc self-requested a review March 12, 2025 03:51
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 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:)

@rkishan516
Copy link
Contributor Author

rkishan516 commented Mar 14, 2025

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.

@rkishan516 rkishan516 force-pushed the sliding-segmented-control-momentary branch 4 times, most recently from 01e0257 to df72eb9 Compare March 15, 2025 05:06
@rkishan516 rkishan516 requested a review from QuncCccccc March 15, 2025 05:09
@dkwingsmt dkwingsmt requested a review from Piinks April 2, 2025 18:27
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.

Thanks for sending another PR! Can you add a dartpad sample to the docs that demonstrates this?

expect(onValueChangedCalled, 0);
});

testWidgets('CupertinoSlidingSegmentedControl can be momentary', (WidgetTester tester) async {
Copy link
Contributor

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?

Copy link
Contributor Author

@rkishan516 rkishan516 Apr 8, 2025

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.

@rkishan516
Copy link
Contributor Author

Thanks for sending another PR! Can you add a dartpad sample to the docs that demonstrates this?

Sure, I can add dartpad sample.

@rkishan516 rkishan516 force-pushed the sliding-segmented-control-momentary branch from df72eb9 to 9b72c30 Compare April 8, 2025 04:01
@github-actions github-actions bot added d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos labels Apr 8, 2025
@rkishan516 rkishan516 force-pushed the sliding-segmented-control-momentary branch 2 times, most recently from aee2513 to 748d8fa Compare April 10, 2025 01:57
@flutter-dashboard
Copy link

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 package:flutter.

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

@Piinks Piinks self-requested a review April 30, 2025 02:32
@Piinks
Copy link
Contributor

Piinks commented May 1, 2025

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!

@rkishan516
Copy link
Contributor Author

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.

@rkishan516 rkishan516 force-pushed the sliding-segmented-control-momentary branch 2 times, most recently from 4a376e5 to 4b1a806 Compare May 2, 2025 02:48
Comment on lines 55 to 56
// The maximum scale factor of the thumb, when being pressed on for a sufficient
// amount of time.
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the sufficient amount of time this is referring to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its same as _kMinThumbScale i.e. duration of a press that triggers the thumb scaling animation.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this value is only used for the momentary variant, and the name doesn't make much sense otherwise, and definitely doesn't have a parallel meaning with _kMinThumbScale. Therefore I suggest:

Suggested change
// The maximum scale factor of the thumb, when being pressed on for a sufficient
// amount of time.
// The peak scale factor of the thumb during the pressing animation of a momentary variant.
const double _kMaxThumbScaleForMomentary = 1.05;

/// Defaults to `EdgeInsets.symmetric(vertical: 2, horizontal: 3)`.
final EdgeInsetsGeometry padding;

/// Determines whether segments in the segmented control show selected state.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should explain what showing selected state is, although it might be better described as temporary feedback when a segment is selected.

Comment on lines 496 to 497
/// If true, segments in the control don’t show selected state and
/// don’t update the value of selectedSegmentIndex after tracking ends.
Copy link
Contributor

Choose a reason for hiding this comment

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

Implementation details are not very helpful in public facing docs. What is this explaining to the user?

@rkishan516 rkishan516 force-pushed the sliding-segmented-control-momentary branch from 11be3e7 to cf86f93 Compare July 18, 2025 01:46
@QuncCccccc QuncCccccc added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 21, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Jul 21, 2025
Merged via the queue into flutter:master with commit 89b7248 Jul 21, 2025
73 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 21, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 22, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 22, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 22, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 22, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jul 22, 2025
flutter/flutter@70cdc0c...ee0cc66

2025-07-22 [email protected] Licenses cpp ignore whitespace (flutter/flutter#172512)
2025-07-22 [email protected] feat: start using the content aware hash for downloading artifacts (flutter/flutter#172552)
2025-07-22 [email protected] fix: correct typo in analysis_options.yaml comment (disabeling -> disabling) (flutter/flutter#170206)
2025-07-22 [email protected] Hide `flutter assemble` unless `--verbose` (flutter/flutter#172508)
2025-07-22 [email protected] Fix PopupMenuButton crashes when being hidden immediately (flutter/flutter#171970)
2025-07-22 [email protected] Add hitTestChildren to baseline-aligned stack (flutter/flutter#172485)
2025-07-22 [email protected] Roll Skia from 4aba494b8108 to eea1c33fbe84 (11 revisions) (flutter/flutter#172515)
2025-07-22 [email protected] Replaces legacy licenses check with licenses_cpp (flutter/flutter#172486)
2025-07-22 [email protected] Omit `w` (widget tree), `t` (render tree) from `flutter run --profile` `h` (flutter/flutter#172506)
2025-07-22 [email protected] Refactor checks for `--machine` (flutter/flutter#172504)
2025-07-22 [email protected] feat(IconButton): add property to specify a states controller (flutter/flutter#169821)
2025-07-21 98614782+auto-submit[bot]@users.noreply.github.com Reverts "feat: start using the content aware hash for downloading artifacts (#171927)" (flutter/flutter#172505)
2025-07-21 [email protected] Render Flutter in its own EGL context (flutter/flutter#172330)
2025-07-21 [email protected] Feat: Add momentary varient of CupertinoSlidingSegmentedControl (flutter/flutter#164262)
2025-07-21 [email protected] Roll Packages from cb8fef6 to 9c85e5e (10 revisions) (flutter/flutter#172479)
2025-07-21 [email protected] Wrap `ShutdownHook` calls to avoid crashing the tool (flutter/flutter#171917)
2025-07-21 [email protected] fix: macOS Mojave Crash on Flutter Desktop Startup (flutter/flutter#172282)
2025-07-21 [email protected] Roll Skia from 9587301e33bc to 4aba494b8108 (41 revisions) (flutter/flutter#172471)
2025-07-21 [email protected] Add CLA note to tree hygiene (flutter/flutter#172475)
2025-07-21 [email protected] Add `radioInnerRadius` to `RadioListTile` (flutter/flutter#171851)
2025-07-21 [email protected] Use baseUri always when doing a hot reload or hot restart (flutter/flutter#172271)
2025-07-21 [email protected] feat: start using the content aware hash for downloading artifacts (flutter/flutter#171927)
2025-07-21 [email protected] Add support for `/?` to alias to `--help` (flutter/flutter#172328)
2025-07-21 [email protected] Upgrade flutter_lints in project template pubspec.yaml files (flutter/flutter#172400)
2025-07-21 [email protected] Use `$dartSdkVersion` when creating "dummy" pubspec for `create_api_docs` (flutter/flutter#172327)
2025-07-21 [email protected] Adds `(defaults to ___)` when using `flutter config --help` (flutter/flutter#172329)
2025-07-21 [email protected] Add a warning on usage of `dartPluginClass: 'none'`. (flutter/flutter#172315)
2025-07-21 [email protected] Skip [tool] crash reporting on `--local-engine` (flutter/flutter#172326)
2025-07-21 [email protected] Remove IDE validation from `flutter doctor` (flutter/flutter#171924)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
azatech pushed a commit to azatech/flutter that referenced this pull request Jul 28, 2025
…ter#164262)

This PR introduces a new boolean flag, `isMomentary`, to the
`CupertinoSlidingSegmentedControl` widget.

When `isMomentary` is set to `true`, the segmented control behaves like
a momentary switch. Selecting a segment triggers its associated action
(e.g., via `onValueChanged`), 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` is `false` (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 a `UISegmentedControl` can be
configured on iOS with `isMomentary = 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: flutter#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

- [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.
vashworth pushed a commit to vashworth/packages that referenced this pull request Jul 30, 2025
…r#9662)

flutter/flutter@70cdc0c...ee0cc66

2025-07-22 [email protected] Licenses cpp ignore whitespace (flutter/flutter#172512)
2025-07-22 [email protected] feat: start using the content aware hash for downloading artifacts (flutter/flutter#172552)
2025-07-22 [email protected] fix: correct typo in analysis_options.yaml comment (disabeling -> disabling) (flutter/flutter#170206)
2025-07-22 [email protected] Hide `flutter assemble` unless `--verbose` (flutter/flutter#172508)
2025-07-22 [email protected] Fix PopupMenuButton crashes when being hidden immediately (flutter/flutter#171970)
2025-07-22 [email protected] Add hitTestChildren to baseline-aligned stack (flutter/flutter#172485)
2025-07-22 [email protected] Roll Skia from 4aba494b8108 to eea1c33fbe84 (11 revisions) (flutter/flutter#172515)
2025-07-22 [email protected] Replaces legacy licenses check with licenses_cpp (flutter/flutter#172486)
2025-07-22 [email protected] Omit `w` (widget tree), `t` (render tree) from `flutter run --profile` `h` (flutter/flutter#172506)
2025-07-22 [email protected] Refactor checks for `--machine` (flutter/flutter#172504)
2025-07-22 [email protected] feat(IconButton): add property to specify a states controller (flutter/flutter#169821)
2025-07-21 98614782+auto-submit[bot]@users.noreply.github.com Reverts "feat: start using the content aware hash for downloading artifacts (#171927)" (flutter/flutter#172505)
2025-07-21 [email protected] Render Flutter in its own EGL context (flutter/flutter#172330)
2025-07-21 [email protected] Feat: Add momentary varient of CupertinoSlidingSegmentedControl (flutter/flutter#164262)
2025-07-21 [email protected] Roll Packages from cb8fef6 to 9c85e5e (10 revisions) (flutter/flutter#172479)
2025-07-21 [email protected] Wrap `ShutdownHook` calls to avoid crashing the tool (flutter/flutter#171917)
2025-07-21 [email protected] fix: macOS Mojave Crash on Flutter Desktop Startup (flutter/flutter#172282)
2025-07-21 [email protected] Roll Skia from 9587301e33bc to 4aba494b8108 (41 revisions) (flutter/flutter#172471)
2025-07-21 [email protected] Add CLA note to tree hygiene (flutter/flutter#172475)
2025-07-21 [email protected] Add `radioInnerRadius` to `RadioListTile` (flutter/flutter#171851)
2025-07-21 [email protected] Use baseUri always when doing a hot reload or hot restart (flutter/flutter#172271)
2025-07-21 [email protected] feat: start using the content aware hash for downloading artifacts (flutter/flutter#171927)
2025-07-21 [email protected] Add support for `/?` to alias to `--help` (flutter/flutter#172328)
2025-07-21 [email protected] Upgrade flutter_lints in project template pubspec.yaml files (flutter/flutter#172400)
2025-07-21 [email protected] Use `$dartSdkVersion` when creating "dummy" pubspec for `create_api_docs` (flutter/flutter#172327)
2025-07-21 [email protected] Adds `(defaults to ___)` when using `flutter config --help` (flutter/flutter#172329)
2025-07-21 [email protected] Add a warning on usage of `dartPluginClass: 'none'`. (flutter/flutter#172315)
2025-07-21 [email protected] Skip [tool] crash reporting on `--local-engine` (flutter/flutter#172326)
2025-07-21 [email protected] Remove IDE validation from `flutter doctor` (flutter/flutter#171924)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
ksokolovskyi pushed a commit to ksokolovskyi/flutter that referenced this pull request Aug 19, 2025
…ter#164262)

This PR introduces a new boolean flag, `isMomentary`, to the
`CupertinoSlidingSegmentedControl` widget.

When `isMomentary` is set to `true`, the segmented control behaves like
a momentary switch. Selecting a segment triggers its associated action
(e.g., via `onValueChanged`), 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` is `false` (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 a `UISegmentedControl` can be
configured on iOS with `isMomentary = 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: flutter#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

- [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.
mboetger pushed a commit to mboetger/flutter that referenced this pull request Sep 18, 2025
…ter#164262)

This PR introduces a new boolean flag, `isMomentary`, to the
`CupertinoSlidingSegmentedControl` widget.

When `isMomentary` is set to `true`, the segmented control behaves like
a momentary switch. Selecting a segment triggers its associated action
(e.g., via `onValueChanged`), 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` is `false` (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 a `UISegmentedControl` can be
configured on iOS with `isMomentary = 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: flutter#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

- [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.
korca0220 pushed a commit to korca0220/flutter that referenced this pull request Sep 22, 2025
…ter#164262)

This PR introduces a new boolean flag, `isMomentary`, to the
`CupertinoSlidingSegmentedControl` widget.

When `isMomentary` is set to `true`, the segmented control behaves like
a momentary switch. Selecting a segment triggers its associated action
(e.g., via `onValueChanged`), 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` is `false` (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 a `UISegmentedControl` can be
configured on iOS with `isMomentary = 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: flutter#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

- [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.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 12, 2025
@guidezpl guidezpl changed the title Feat: Add momentary varient of CupertinoSlidingSegmentedControl Feat: Add momentary variant of CupertinoSlidingSegmentedControl Nov 12, 2025
lucaantonelli pushed a commit to lucaantonelli/flutter that referenced this pull request Nov 21, 2025
…ter#164262)

This PR introduces a new boolean flag, `isMomentary`, to the
`CupertinoSlidingSegmentedControl` widget.

When `isMomentary` is set to `true`, the segmented control behaves like
a momentary switch. Selecting a segment triggers its associated action
(e.g., via `onValueChanged`), 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` is `false` (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 a `UISegmentedControl` can be
configured on iOS with `isMomentary = 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: flutter#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

- [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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: cupertino flutter/packages/flutter/cupertino repository framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support isMomentary feature for CupertinoSlidingSegmentedControl

6 participants