[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
This commit is contained in:
Marijua ރ 2026-01-27 11:38:29 +03:00 committed by GitHub
parent c150d75032
commit 248bc79d48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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(