[Material] update hourFormat to use Dart 3 switch expression#181041
[Material] update hourFormat to use Dart 3 switch expression#181041auto-submit[bot] merged 9 commits intoflutter:masterfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request is a great improvement. It refactors the hourFormat function to use a more modern and concise Dart 3 switch expression, and importantly, adds previously missing unit tests for this logic. The changes improve code quality and maintainability. My feedback includes a couple of suggestions to make the new tests even more robust and easier to debug by adopting a data-driven approach.
| expect(hourFormat(of: TimeOfDayFormat.h_colon_mm_space_a), HourFormat.h); | ||
| expect(hourFormat(of: TimeOfDayFormat.a_space_h_colon_mm), HourFormat.h); |
There was a problem hiding this comment.
To improve maintainability and debugging, consider refactoring this test to be data-driven. Iterating over a list of test cases makes it easier to add new formats in the future and provides more specific failure messages if a test fails.
This aligns with the 'Writing Effective Tests' guide, which emphasizes that it should be easy to debug a failing test.
const formats = <TimeOfDayFormat>[
TimeOfDayFormat.h_colon_mm_space_a,
TimeOfDayFormat.a_space_h_colon_mm,
];
for (final format in formats) {
expect(hourFormat(of: format), HourFormat.h, reason: 'for $format');
}Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
@google-cla I have just signed the CLA. |
6702c59 to
e8be69d
Compare
e8be69d to
388bbff
Compare
huycozy
left a comment
There was a problem hiding this comment.
Overall, LGTM. Thank you for improving this!
(I don't see this was linked to any issues, though.)
|
hello! thanks for the review @huycozy to clarify the missing issue link, this PR was intended as a standalone refactor to modernize the |
Roll Flutter from 48c2475 to bfc9041eb118 (173 revisions) flutter/flutter@48c2475...bfc9041 2026-01-23 [email protected] No longer exiting the application when the RegularWindow is destroyed + resolving the window created promise after runWidget (flutter/flutter#181339) 2026-01-23 [email protected] Remove unnecessary Material import from dialog_test.dart (flutter/flutter#181249) 2026-01-23 [email protected] Roll Skia from 8e516fe6828f to db10db8bd55f (1 revision) (flutter/flutter#181379) 2026-01-23 [email protected] Reset TextFormField to initial value after state change (flutter/flutter#181199) 2026-01-23 [email protected] Roll Dart SDK from 980b2b41d36e to e82d7ad1855e (1 revision) (flutter/flutter#181375) 2026-01-23 [email protected] Roll Skia from 3e86f377d300 to 8e516fe6828f (4 revisions) (flutter/flutter#181370) 2026-01-23 [email protected] Remove unnecessary Material import from sliver_visibility_test (flutter/flutter#181248) 2026-01-23 [email protected] Add bottom navigation bar item semantics label (flutter/flutter#180577) 2026-01-23 [email protected] Make topGap not required for CupertinoSheetTransition (flutter/flutter#181269) 2026-01-23 [email protected] Roll Fuchsia Linux SDK from b4cLyhuxciUC-4zCJ... to n7NohL9DPpEuPjNt9... (flutter/flutter#181365) 2026-01-23 [email protected] Roll Dart SDK from 806f04638561 to 980b2b41d36e (1 revision) (flutter/flutter#181364) 2026-01-23 [email protected] Reland hybrid views test (flutter/flutter#181336) 2026-01-23 [email protected] Revert DropdownMenu non-nullable breaking change (flutter/flutter#181074) 2026-01-23 [email protected] Fix leaks in `flutter_test` tests (flutter/flutter#180879) 2026-01-23 [email protected] Re-enable fragment_shader_tests.dart 'Shader Compiler appropriately pads vec3 uniform arrays' test on Vulkan (flutter/flutter#181292) 2026-01-23 [email protected] [ Tool ] Fix `update-packages` failing due to mismatched dependencies between flutter_tools and the framework (flutter/flutter#181335) 2026-01-23 [email protected] [Impeller] Make dynamically created shader metadata for runtime effects consistent with metadata for built-in shaders (flutter/flutter#181201) 2026-01-23 [email protected] Broaden the applicability of `Color` fix_data rules from flutter/painting.dart (flutter/flutter#181093) 2026-01-23 [email protected] Fixes macOS App.framework not being codesigned or find framework (flutter/flutter#181348) 2026-01-22 [email protected] Roll Fuchsia GN SDK from NAEC5tfgSl8g94nwp... to JLBh4Z9PKsjIJcqDU... (flutter/flutter#181139) 2026-01-22 [email protected] Roll Dart SDK from ab4640ea82e9 to 806f04638561 (2 revisions) (flutter/flutter#181347) 2026-01-22 [email protected] Add ExpansibleController.toggle method. (flutter/flutter#181320) 2026-01-22 [email protected] Fixes Typo in codebase (flutter/flutter#181256) 2026-01-22 [email protected] Roll Skia from 4766615bcc96 to 3e86f377d300 (3 revisions) (flutter/flutter#181346) 2026-01-22 [email protected] Make sure that a Hero doesn't crash in 0x0 environment (flutter/flutter#180954) 2026-01-22 [email protected] Reland "Fix capitalization of the path to FlutterWindowControllerTest.mm in the macOS platform build script" (flutter/flutter#181200) 2026-01-22 [email protected] Roll Skia from 6e9746be8c4a to 4766615bcc96 (3 revisions) (flutter/flutter#181331) 2026-01-22 [email protected] Fix remove material import textfield (flutter/flutter#181254) 2026-01-22 [email protected] Add FlutterFramework as an Xcode SwiftPM local package override (flutter/flutter#179512) 2026-01-22 [email protected] Roll Dart SDK from 7bd4c68b625c to ab4640ea82e9 (1 revision) (flutter/flutter#181324) 2026-01-22 [email protected] Roll Packages from d80c60e to 9010299 (9 revisions) (flutter/flutter#181323) 2026-01-22 [email protected] Roll Dart SDK from 2d53a77adc5d to 7bd4c68b625c (2 revisions) (flutter/flutter#181316) 2026-01-22 [email protected] Roll Skia from 3f6949bc5780 to 6e9746be8c4a (2 revisions) (flutter/flutter#181311) 2026-01-22 [email protected] Roll Skia from ef6efc358b4a to 3f6949bc5780 (2 revisions) (flutter/flutter#181307) 2026-01-22 [email protected] Roll Dart SDK from 5d7c8faf2e41 to 2d53a77adc5d (1 revision) (flutter/flutter#181305) 2026-01-22 [email protected] [Material] update hourFormat to use Dart 3 switch expression (flutter/flutter#181041) 2026-01-22 [email protected] Use null-aware elements in cupertino/nav_bar.dart (flutter/flutter#181237) 2026-01-22 [email protected] Roll Fuchsia Linux SDK from b2KIEXVAlEqImQ9VO... to b4cLyhuxciUC-4zCJ... (flutter/flutter#181297) 2026-01-22 [email protected] Roll pub packages (flutter/flutter#181295) 2026-01-22 [email protected] Enables fragment shader test for impeller (fixes mat2 on vulkan) (flutter/flutter#181013) 2026-01-21 [email protected] Roll Dart SDK from 366200db1aa1 to 5d7c8faf2e41 (4 revisions) (flutter/flutter#181290) 2026-01-21 [email protected] Roll Skia from b5ec89e31f59 to ef6efc358b4a (19 revisions) (flutter/flutter#181289) 2026-01-21 [email protected] fix description for semantics finders (flutter/flutter#181214) 2026-01-21 [email protected] Make sure that an Icon doesn't crash in 0x0 environment (flutter/flutter#181021) 2026-01-21 [email protected] Make sure that a GridPaper doesn't crash in 0x0 environment (flutter/flutter#180906) 2026-01-21 [email protected] Bring Linux coverage out of bringup (flutter/flutter#181280) ...
…sions (#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
…#181041) While I was looking through `time.dart`, I noticed that `hourFormat` was still using the old switch-case style with a lot of boilerplate. Since we are moving towards Dart 3 patterns, I thought it'd be a good idea to swap this out for a switch expression. It's much cleaner now and handles the `TimeOfDayFormat` mapping in just a few lines. I also realized there weren't any direct tests for this specific function (it was mostly covered by larger integration tests), so I added a small test group in `time_test.dart` to make sure every enum value maps to the right `HourFormat` correctly. This is a trivial internal refactor and does not fix a specific bug report, so no issue is linked. ## 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 --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…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
While I was looking through
time.dart, I noticed thathourFormatwas still using the old switch-case style with a lot of boilerplate. Since we are moving towards Dart 3 patterns, I thought it'd be a good idea to swap this out for a switch expression. It's much cleaner now and handles theTimeOfDayFormatmapping in just a few lines.I also realized there weren't any direct tests for this specific function (it was mostly covered by larger integration tests), so I added a small test group in
time_test.dartto make sure every enum value maps to the rightHourFormatcorrectly.This is a trivial internal refactor and does not fix a specific bug report, so no issue is linked.
Pre-launch Checklist
///).