Skip to content

Add ability to disable CupertinoSegmentedControl#152813

Merged
auto-submit[bot] merged 8 commits intoflutter:masterfrom
huycozy:toggle-cupertino-segmentedcontrol-52105
Oct 24, 2024
Merged

Add ability to disable CupertinoSegmentedControl#152813
auto-submit[bot] merged 8 commits intoflutter:masterfrom
huycozy:toggle-cupertino-segmentedcontrol-52105

Conversation

@huycozy
Copy link
Member

@huycozy huycozy commented Aug 3, 2024

Summary

Add the ability to configure enabled or disabled segments in CupertinoSegmentedControl. The idea is to pass a segmentStates map, where the user can set the state according to segment key. User can also set background and text colors when the segment is disabled.

Demo

demo.fix.video.mov

Related issue

Fixes #52105

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@huycozy huycozy self-assigned this Aug 3, 2024
@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: cupertino flutter/packages/flutter/cupertino repository d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos labels Aug 3, 2024
@huycozy huycozy requested a review from QuncCccccc August 5, 2024 03:41
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 so much for the fix! Just left 2 questions below:)

@QuncCccccc QuncCccccc self-requested a review August 14, 2024 18:09
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 so much for the contribution! One comment I left is about the api type, I think a Set of disabled children might be better than a map, based on the comment that I received from SlidingSegmentedControl PR.

@huycozy huycozy force-pushed the toggle-cupertino-segmentedcontrol-52105 branch from f3a77d8 to b07088c Compare August 27, 2024 08:20
@huycozy
Copy link
Member Author

huycozy commented Aug 27, 2024

Thank you for the suggestion! It looks better with Set type. I pushed the update.

@QuncCccccc QuncCccccc self-requested a review September 4, 2024 18:12
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.

Sorry for the late response! Left some comments. Please let me know if there's anything that doesn't make sense:)

_toggleAll = false;
_disabledChildren = <Sky>{Sky.midnight};
} else {
_toggleAll = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why _toggleAll is set to true if _toggleOne is false? This part looks a little confusing. Seems if toggleOne is true, it disables the first segment, but if toggleAll is true, it enables all segments.🤔

Since this example looks similar with cupertino_segmented_control.0.dart, maybe we can just add the Switches in that example instead of creating a new one:)

Copy link
Member Author

Choose a reason for hiding this comment

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

Why _toggleAll is set to true if _toggleOne is false? This part looks a little confusing. Seems if toggleOne is true, it disables the first segment, but if toggleAll is true, it enables all segments.🤔

In this example, my purpose is to create clear cases, please also watch the demo video in the original comment

  1. User can disable one segment (1st segment for eg)
  2. User can disable/enable all segments

So, when user toggles one Switch, it will also reset the remaining Switch.

Since this example looks similar with cupertino_segmented_control.0.dart, maybe we can just add the Switches in that example instead of creating a new one:)

My initial purpose is to create separate examples for disabled segments. But I can do this if it's cleaner :)

@huynguyennovem huynguyennovem force-pushed the toggle-cupertino-segmentedcontrol-52105 branch from b07088c to b5ea236 Compare September 24, 2024 11:53
@huycozy
Copy link
Member Author

huycozy commented Sep 24, 2024

@QuncCccccc Thank you so much for your thorough review and sorry for the delayed response, I've just come back from travel :). I've updated the code based on most of your suggestions, except for those concerning example and disabledColor, I'm eager to hear back from you again. Here is the updated demo video for the example:

Screen.Recording.2024-09-24.at.18.16.45.mov

@Piinks Piinks requested a review from QuncCccccc October 2, 2024 18:13
@huycozy huycozy force-pushed the toggle-cupertino-segmentedcontrol-52105 branch from aee89ef to e82773c Compare October 17, 2024 04:05
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 the contribution!

@Piinks Piinks force-pushed the toggle-cupertino-segmentedcontrol-52105 branch from e82773c to 366aa0e Compare October 23, 2024 18:25
@huycozy huycozy added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 24, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 24, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 24, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 24, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 24, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 26, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 26, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Oct 26, 2024
Roll Flutter from 4faa4a4 to 5a11904 (67 revisions)

flutter/flutter@4faa4a4...5a11904

2024-10-26 [email protected] Relands "Wide gamut framework gradient test (#153976)" (flutter/flutter#157643)
2024-10-26 [email protected] Roll Flutter Engine from 7c5c5fe5c84d to c9b8ac96f6ce (3 revisions) (flutter/flutter#157662)
2024-10-26 [email protected] Add test for `navigator_state.restorable_push_and_remove_until.0.dart` (flutter/flutter#157595)
2024-10-26 [email protected] Tighten up `throwToolExit`, explain when to use it. (flutter/flutter#157561)
2024-10-26 [email protected] Remove extraneous `throw`. (flutter/flutter#157658)
2024-10-26 [email protected] Add tests for `navigator.restorable_push.0.dart` (flutter/flutter#157492)
2024-10-25 [email protected] Roll Flutter Engine from 43e4d9a30666 to 7c5c5fe5c84d (1 revision) (flutter/flutter#157644)
2024-10-25 [email protected] Roll Flutter Engine from 5061358e255f to 43e4d9a30666 (1 revision) (flutter/flutter#157637)
2024-10-25 [email protected] Roll Flutter Engine from eb867e055790 to 5061358e255f (2 revisions) (flutter/flutter#157623)
2024-10-25 [email protected] Create flutter specific leak troubleshooting guidance. (flutter/flutter#157396)
2024-10-25 [email protected] Update CupertinoNavigationBar to support large layout (flutter/flutter#157133)
2024-10-25 [email protected] Roll Flutter Engine from 38e9be1f74fa to eb867e055790 (3 revisions) (flutter/flutter#157613)
2024-10-25 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Wide gamut framework gradient test (#153976)" (flutter/flutter#157615)
2024-10-25 [email protected] Wide gamut framework gradient test (flutter/flutter#153976)
2024-10-25 [email protected] Roll Flutter Engine from b413d9996c86 to 38e9be1f74fa (2 revisions) (flutter/flutter#157604)
2024-10-25 [email protected] Roll Packages from a556f0f to e0c4f55 (2 revisions) (flutter/flutter#157605)
2024-10-25 [email protected] Support backdrop key in flutter framework. (flutter/flutter#157278)
2024-10-25 [email protected] Add 3.24.4 changelog to master (flutter/flutter#157600)
2024-10-25 [email protected] Update flutter.groovy to catch unknown task exception when finding api task (flutter/flutter#157282)
2024-10-25 [email protected] Roll Flutter Engine from c4b0184c8783 to b413d9996c86 (1 revision) (flutter/flutter#157580)
2024-10-25 [email protected] Roll Flutter Engine from b1c2ba8c4d52 to c4b0184c8783 (1 revision) (flutter/flutter#157578)
2024-10-25 [email protected] Add test for `build_owner.0.dart` (flutter/flutter#157499)
2024-10-25 [email protected] Add tests  for `focusable_action_detector.0.dart` (flutter/flutter#157575)
2024-10-25 [email protected] Add test for `navigator.restorable_push_and_remove_until.0.dart` (flutter/flutter#157487)
2024-10-25 [email protected] Roll Flutter Engine from 29440ed1e225 to b1c2ba8c4d52 (1 revision) (flutter/flutter#157572)
2024-10-25 [email protected] Roll Flutter Engine from 88716d804aef to 29440ed1e225 (1 revision) (flutter/flutter#157569)
2024-10-25 [email protected] Roll Flutter Engine from b8b28c80a737 to 88716d804aef (2 revisions) (flutter/flutter#157567)
2024-10-24 [email protected] Roll Flutter Engine from 48ff670d256b to b8b28c80a737 (2 revisions) (flutter/flutter#157564)
2024-10-24 [email protected] Use discenrable characters (replace `' ð��� ð��� '` in error logs) (flutter/flutter#157548)
2024-10-24 [email protected] Remove unused `PubDependenciesProjectValidator`. (flutter/flutter#157516)
2024-10-24 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Upgrade tests to AGP 8.7/Gradle 8.10.2/Kotlin 1.8.10 (#157032)" (flutter/flutter#157559)
2024-10-24 [email protected] Mark mac impeller as bringup. (flutter/flutter#157551)
2024-10-24 [email protected] Deprecate `ThemeData.dialogBackgroundColor` in favor of `DialogThemeData.backgroundColor` (flutter/flutter#155072)
2024-10-24 [email protected] Upgrade tests to AGP 8.7/Gradle 8.10.2/Kotlin 1.8.10 (flutter/flutter#157032)
2024-10-24 [email protected] Roll Flutter Engine from 246344f26edc to 48ff670d256b (2 revisions) (flutter/flutter#157544)
2024-10-24 [email protected] Allow opting out of `.flutter-plugins`, opt-out in `refreshPluginsList`. (flutter/flutter#157527)
2024-10-24 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Reverts "Added a warning if `flutter.groovy` uses a `.flutter-plugins` file. (#157388)" (#157541)" (flutter/flutter#157549)
2024-10-24 [email protected] Changes the offset computation to first item for RenderSliverMainAxisGroup (flutter/flutter#154688)
2024-10-24 [email protected] Roll Packages from 5e03bb1 to a556f0f (7 revisions) (flutter/flutter#157539)
2024-10-24 [email protected] Add partial test for flutter build ios-framework on non-module (flutter/flutter#157482)
2024-10-24 [email protected] Add example to SafeArea docs (flutter/flutter#157228)
2024-10-24 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Added a warning if `flutter.groovy` uses a `.flutter-plugins` file. (#157388)" (flutter/flutter#157541)
2024-10-24 [email protected] Added a warning if `flutter.groovy` uses a `.flutter-plugins` file. (flutter/flutter#157388)
2024-10-24 [email protected] Roll Flutter Engine from be56084344d1 to 246344f26edc (2 revisions) (flutter/flutter#157504)
2024-10-24 [email protected] Add ability to disable CupertinoSegmentedControl (flutter/flutter#152813)
2024-10-24 [email protected] Update `Tab.height` parameter doc for tab height lower than default (flutter/flutter#157443)
...
M97Chahboun pushed a commit to M97Chahboun/flutter that referenced this pull request Oct 30, 2024
### Summary

Add the ability to configure enabled or disabled segments in CupertinoSegmentedControl. The idea is to pass a `segmentStates` map, where the user can set the state according to segment key. User can also set background and text colors when the segment is disabled.

### Demo

https://github.com/user-attachments/assets/4a02da02-a0fb-4ded-a271-033a8dc79ac3

### Related issue
Fixes flutter#52105
@huycozy huycozy deleted the toggle-cupertino-segmentedcontrol-52105 branch February 7, 2025 09:19
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App 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.

Option to disable CupertinoSegmentedControl

2 participants