From 248bc79d4862284e2107ca5e62f258b0bb6e000c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijua=20=DE=83?= <120639059+Enderjua@users.noreply.github.com> Date: Tue, 27 Jan 2026 11:38:29 +0300 Subject: [PATCH] [Material] modernize time picker components with Dart 3 switch expressions (#181356) 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 - [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 --- .../flutter/lib/src/material/time_picker.dart | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/packages/flutter/lib/src/material/time_picker.dart b/packages/flutter/lib/src/material/time_picker.dart index a76d19fe523..8e10025e1cf 100644 --- a/packages/flutter/lib/src/material/time_picker.dart +++ b/packages/flutter/lib/src/material/time_picker.dart @@ -469,19 +469,14 @@ class _TimeSelectorSeparator extends StatelessWidget { final TimeOfDayFormat timeOfDayFormat; - String _timeSelectorSeparatorValue(TimeOfDayFormat timeOfDayFormat) { - switch (timeOfDayFormat) { - case TimeOfDayFormat.h_colon_mm_space_a: - case TimeOfDayFormat.a_space_h_colon_mm: - case TimeOfDayFormat.H_colon_mm: - case TimeOfDayFormat.HH_colon_mm: - return ':'; - case TimeOfDayFormat.HH_dot_mm: - return '.'; - case TimeOfDayFormat.frenchCanadian: - return 'h'; - } - } + String _timeSelectorSeparatorValue(TimeOfDayFormat timeOfDayFormat) => switch (timeOfDayFormat) { + TimeOfDayFormat.h_colon_mm_space_a || + TimeOfDayFormat.a_space_h_colon_mm || + TimeOfDayFormat.H_colon_mm || + TimeOfDayFormat.HH_colon_mm => ':', + TimeOfDayFormat.HH_dot_mm => '.', + TimeOfDayFormat.frenchCanadian => 'h', + }; @override Widget build(BuildContext context) { @@ -507,15 +502,12 @@ class _TimeSelectorSeparator extends StatelessWidget { states, ).copyWith(color: effectiveTextColor, height: 1.0); - final double height; - switch (_TimePickerModel.entryModeOf(context)) { - case TimePickerEntryMode.dial: - case TimePickerEntryMode.dialOnly: - height = defaultTheme.hourMinuteSize.height; - case TimePickerEntryMode.input: - case TimePickerEntryMode.inputOnly: - height = defaultTheme.hourMinuteInputSize.height; - } + final double height = switch (_TimePickerModel.entryModeOf(context)) { + TimePickerEntryMode.dial || + TimePickerEntryMode.dialOnly => defaultTheme.hourMinuteSize.height, + TimePickerEntryMode.input || + TimePickerEntryMode.inputOnly => defaultTheme.hourMinuteInputSize.height, + }; return ExcludeSemantics( child: SizedBox(