Skip to content

[Material] modernize time picker components with Dart 3 switch expressions#181356

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
Enderjua:switch-refactor-material
Jan 27, 2026
Merged

[Material] modernize time picker components with Dart 3 switch expressions#181356
auto-submit[bot] merged 5 commits into
flutter:masterfrom
Enderjua:switch-refactor-material

Conversation

@Enderjua

@Enderjua Enderjua commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

Following up on #181041, I took another look at time_picker.dart for any remaining switch statements that could be modernized.

I found that _timeSelectorSeparatorValue and the height calculation in _TimeSelectorSeparator were great candidates. By using logical OR patterns and inlining the assignments, I was able to convert them into clean switch expressions. The logic remains exactly the same, but the boilerplate is gone.

Pre-launch Checklist

@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Jan 23, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors two switch statements in packages/flutter/lib/src/material/time_picker.dart to use Dart 3's switch expressions, improving code conciseness. The changes are in the _timeSelectorSeparatorValue method and the height calculation within the _TimeSelectorSeparator widget.

The pull request title and description indicate that the hoursFromSelected method was to be modernized. However, this method was not modified in the diff. To maintain clarity in the repository's history, please consider updating the PR's title and description to match the actual changes.

@Enderjua Enderjua changed the title [Material] modernize hoursFromSelected with Dart 3 switch expression Material] modernize time picker components with Dart 3 switch expressions Jan 23, 2026
@Enderjua

Copy link
Copy Markdown
Contributor Author

I'm quite skeptical about the change in the hoursFromSelected method. I'd really appreciate it if the reviewer who looks at this could comment on it. I thought changing it would make the code even harder to read, so I changed it but haven't committed yet. I can't decide.

@Enderjua Enderjua changed the title Material] modernize time picker components with Dart 3 switch expressions [Material] modernize time picker components with Dart 3 switch expressions Jan 23, 2026

@victorsanni victorsanni left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, can you also request a test exemption for this PR as well?

@victorsanni victorsanni requested a review from huycozy January 23, 2026 20:05
@Enderjua

Copy link
Copy Markdown
Contributor Author

hello @victorsanni, thank you for the review. I've just requested the test exemptions on Discord for both this and my other related PR as you suggested.

@stuartmorgan-g

Copy link
Copy Markdown
Contributor

test-exempt: code refactor with no semantic change

@victorsanni victorsanni requested a review from dkwingsmt January 26, 2026 22:42

@huycozy huycozy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM
Thanks!

@huycozy huycozy added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 27, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jan 27, 2026
Merged via the queue into flutter:master with commit 248bc79 Jan 27, 2026
70 of 71 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 27, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 27, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 27, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 27, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 27, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 27, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jan 27, 2026
flutter/flutter@7165649...dfd92b7

2026-01-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fixes metal vec3 uniform padding (#181340)" (flutter/flutter#181552)
2026-01-27 1063596+reidbaker@users.noreply.github.com Change update_engine_version documenation (flutter/flutter#181508)
2026-01-27 engine-flutter-autoroll@skia.org Roll Packages from e712bfa to e37af11 (7 revisions) (flutter/flutter#181544)
2026-01-27 jason-simmons@users.noreply.github.com Roll FreeType to 2.14.1 (flutter/flutter#181428)
2026-01-27 engine-flutter-autoroll@skia.org Roll Skia from 566d202962d3 to c2754838b077 (3 revisions) (flutter/flutter#181536)
2026-01-27 120639059+Enderjua@users.noreply.github.com [Material] modernize time picker components with Dart 3 switch expressions (flutter/flutter#181356)
2026-01-27 engine-flutter-autoroll@skia.org Roll Skia from 55a87b50a368 to 566d202962d3 (1 revision) (flutter/flutter#181528)
2026-01-27 engine-flutter-autoroll@skia.org Roll Dart SDK from f55d4538469a to 4c7cb0a1d07d (2 revisions) (flutter/flutter#181526)
2026-01-27 sigurdm@google.com Replace `pub run` mentions with `dart run` (flutter/flutter#181317)
2026-01-27 engine-flutter-autoroll@skia.org Roll Skia from 1a15ed6b17f2 to 55a87b50a368 (1 revision) (flutter/flutter#181523)
2026-01-27 magder@google.com Marks linux_chrome_dev_mode to be unflaky (flutter/flutter#181352)
2026-01-27 engine-flutter-autoroll@skia.org Roll Skia from f2c1aa140b79 to 1a15ed6b17f2 (2 revisions) (flutter/flutter#181514)
2026-01-27 snakept@icloud.com Fix Range Slider issue where indescrete ranges lead to out of range r… (flutter/flutter#181082)
2026-01-26 engine-flutter-autoroll@skia.org Roll Dart SDK from ba23b5ed0a97 to f55d4538469a (2 revisions) (flutter/flutter#181512)
2026-01-26 mariaivoneiradjaja@gmail.com Add `alignment` to `SizeTransition` (flutter/flutter#177895)
2026-01-26 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from T4qTEa3T5CCSCIoJY... to akraNGn2lw4T1msgZ... (flutter/flutter#181509)
2026-01-26 engine-flutter-autoroll@skia.org Roll Skia from be280d242a60 to f2c1aa140b79 (3 revisions) (flutter/flutter#181504)
2026-01-26 30870216+gaaclarke@users.noreply.github.com Fixes metal vec3 uniform padding (flutter/flutter#181340)
2026-01-26 47866232+chunhtai@users.noreply.github.com Fixes duplicated import in accessibility test library (flutter/flutter#181506)
2026-01-26 34871572+gmackall@users.noreply.github.com [Reland] Don't strip symbols from `libapp.so` on android by default (flutter/flutter#181275)
2026-01-26 sokolovskyi.konstantin@gmail.com Fix Gradle path in Android Platform Embedder README. (flutter/flutter#181501)
2026-01-26 116356835+AbdeMohlbi@users.noreply.github.com Remove unused `ActivityLifecycleListener` class (flutter/flutter#181406)

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 bmparr@google.com,stuartmorgan@google.com 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
flutter-zl pushed a commit to flutter-zl/flutter that referenced this pull request Feb 10, 2026
…sions (flutter#181356)

Following up on flutter#181041, I took another look at `time_picker.dart` for
any remaining switch statements that could be modernized.

I found that `_timeSelectorSeparatorValue` and the `height` calculation
in `_TimeSelectorSeparator` were great candidates. By using logical OR
patterns and inlining the assignments, I was able to convert them into
clean switch expressions. The logic remains exactly the same, but the
boilerplate is gone.

## 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]. (I will sign it once the bot prompts me)
- [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] All existing and new tests are passing.

[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…r#10914)

flutter/flutter@7165649...dfd92b7

2026-01-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fixes metal vec3 uniform padding (#181340)" (flutter/flutter#181552)
2026-01-27 1063596+reidbaker@users.noreply.github.com Change update_engine_version documenation (flutter/flutter#181508)
2026-01-27 engine-flutter-autoroll@skia.org Roll Packages from e712bfa to e37af11 (7 revisions) (flutter/flutter#181544)
2026-01-27 jason-simmons@users.noreply.github.com Roll FreeType to 2.14.1 (flutter/flutter#181428)
2026-01-27 engine-flutter-autoroll@skia.org Roll Skia from 566d202962d3 to c2754838b077 (3 revisions) (flutter/flutter#181536)
2026-01-27 120639059+Enderjua@users.noreply.github.com [Material] modernize time picker components with Dart 3 switch expressions (flutter/flutter#181356)
2026-01-27 engine-flutter-autoroll@skia.org Roll Skia from 55a87b50a368 to 566d202962d3 (1 revision) (flutter/flutter#181528)
2026-01-27 engine-flutter-autoroll@skia.org Roll Dart SDK from f55d4538469a to 4c7cb0a1d07d (2 revisions) (flutter/flutter#181526)
2026-01-27 sigurdm@google.com Replace `pub run` mentions with `dart run` (flutter/flutter#181317)
2026-01-27 engine-flutter-autoroll@skia.org Roll Skia from 1a15ed6b17f2 to 55a87b50a368 (1 revision) (flutter/flutter#181523)
2026-01-27 magder@google.com Marks linux_chrome_dev_mode to be unflaky (flutter/flutter#181352)
2026-01-27 engine-flutter-autoroll@skia.org Roll Skia from f2c1aa140b79 to 1a15ed6b17f2 (2 revisions) (flutter/flutter#181514)
2026-01-27 snakept@icloud.com Fix Range Slider issue where indescrete ranges lead to out of range r… (flutter/flutter#181082)
2026-01-26 engine-flutter-autoroll@skia.org Roll Dart SDK from ba23b5ed0a97 to f55d4538469a (2 revisions) (flutter/flutter#181512)
2026-01-26 mariaivoneiradjaja@gmail.com Add `alignment` to `SizeTransition` (flutter/flutter#177895)
2026-01-26 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from T4qTEa3T5CCSCIoJY... to akraNGn2lw4T1msgZ... (flutter/flutter#181509)
2026-01-26 engine-flutter-autoroll@skia.org Roll Skia from be280d242a60 to f2c1aa140b79 (3 revisions) (flutter/flutter#181504)
2026-01-26 30870216+gaaclarke@users.noreply.github.com Fixes metal vec3 uniform padding (flutter/flutter#181340)
2026-01-26 47866232+chunhtai@users.noreply.github.com Fixes duplicated import in accessibility test library (flutter/flutter#181506)
2026-01-26 34871572+gmackall@users.noreply.github.com [Reland] Don't strip symbols from `libapp.so` on android by default (flutter/flutter#181275)
2026-01-26 sokolovskyi.konstantin@gmail.com Fix Gradle path in Android Platform Embedder README. (flutter/flutter#181501)
2026-01-26 116356835+AbdeMohlbi@users.noreply.github.com Remove unused `ActivityLifecycleListener` class (flutter/flutter#181406)

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 bmparr@google.com,stuartmorgan@google.com 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants