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 - [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.
Flutter Examples
This directory contains several examples of using Flutter. To run an example,
use flutter run inside that example's directory. See the getting started
guide to install the flutter tool.
For additional samples, see the
flutter/samples repo.
Available examples include:
-
Hello, world The hello world app is a minimal Flutter app that shows the text "Hello, world!"
-
Flutter gallery The flutter gallery app no longer lives in this repo. Please see the gallery repo.
-
Layers The layers vignettes show how to use the various layers in the Flutter framework. For details, see the layers README.
-
Platform Channel The platform channel app demonstrates how to connect a Flutter app to platform-specific APIs. For documentation, see https://flutter.dev/to/platform-channels/.
-
Platform Channel Swift The platform channel swift app is the same as platform channel but the iOS version is in Swift and there is no Android version.
Notes
Note on Gradle wrapper files in .gitignore:
Gradle wrapper files should normally be checked into source control. The example projects don't do that to avoid having several copies of the wrapper binary in the Flutter repo. Instead, the Gradle wrapper is injected by Flutter tooling, and the wrapper files are .gitignore'd to avoid making the Flutter repository dirty as a side effect of running the examples.