From cd45eb63ea57490ef125d8a9d970a18016660dca Mon Sep 17 00:00:00 2001 From: Mohellebi Abdessalem <116356835+AbdeMohlbi@users.noreply.github.com> Date: Fri, 6 Feb 2026 05:25:30 +0100 Subject: [PATCH] `flutter_tool` : Remove redundant enum types inside the enum definition scope (#181910) see https://discord.com/channels/608014603317936148/1468007948637831220 ## 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 listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [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 --- packages/flutter_tools/lib/src/base/os.dart | 14 +-- .../flutter_tools/lib/src/build_info.dart | 114 +++++++++--------- .../flutter_tools/lib/src/darwin/darwin.dart | 20 ++- .../lib/src/drive/web_driver_service.dart | 14 +-- .../flutter_service_worker_js.dart | 4 +- 5 files changed, 81 insertions(+), 85 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/os.dart b/packages/flutter_tools/lib/src/base/os.dart index 297bf10159c..1a12f4d69a0 100644 --- a/packages/flutter_tools/lib/src/base/os.dart +++ b/packages/flutter_tools/lib/src/base/os.dart @@ -618,13 +618,13 @@ enum HostPlatform { windows_arm64; String get platformName => switch (this) { - HostPlatform.darwin_x64 => 'x64', - HostPlatform.darwin_arm64 => 'arm64', - HostPlatform.linux_x64 => 'x64', - HostPlatform.linux_arm64 => 'arm64', - HostPlatform.linux_riscv64 => 'riscv64', - HostPlatform.windows_x64 => 'x64', - HostPlatform.windows_arm64 => 'arm64', + darwin_x64 => 'x64', + darwin_arm64 => 'arm64', + linux_x64 => 'x64', + linux_arm64 => 'arm64', + linux_riscv64 => 'riscv64', + windows_x64 => 'x64', + windows_arm64 => 'arm64', }; } diff --git a/packages/flutter_tools/lib/src/build_info.dart b/packages/flutter_tools/lib/src/build_info.dart index f2cf1321e58..e24464c4da9 100644 --- a/packages/flutter_tools/lib/src/build_info.dart +++ b/packages/flutter_tools/lib/src/build_info.dart @@ -644,79 +644,79 @@ enum TargetPlatform { String get fuchsiaArchForTargetPlatform { switch (this) { - case TargetPlatform.fuchsia_arm64: + case fuchsia_arm64: return 'arm64'; - case TargetPlatform.fuchsia_x64: + case fuchsia_x64: return 'x64'; - case TargetPlatform.android: - case TargetPlatform.android_arm: - case TargetPlatform.android_arm64: - case TargetPlatform.android_x64: - case TargetPlatform.darwin: - case TargetPlatform.ios: - case TargetPlatform.linux_arm64: - case TargetPlatform.linux_riscv64: - case TargetPlatform.linux_x64: - case TargetPlatform.tester: - case TargetPlatform.web_javascript: - case TargetPlatform.windows_x64: - case TargetPlatform.windows_arm64: - case TargetPlatform.unsupported: + case android: + case android_arm: + case android_arm64: + case android_x64: + case darwin: + case ios: + case linux_arm64: + case linux_riscv64: + case linux_x64: + case tester: + case web_javascript: + case windows_x64: + case windows_arm64: + case unsupported: throw UnsupportedError('Unexpected Fuchsia platform $this'); } } String get osName { switch (this) { - case TargetPlatform.linux_x64: - case TargetPlatform.linux_arm64: - case TargetPlatform.linux_riscv64: + case linux_x64: + case linux_arm64: + case linux_riscv64: return 'linux'; - case TargetPlatform.darwin: + case darwin: return 'macos'; - case TargetPlatform.windows_x64: - case TargetPlatform.windows_arm64: + case windows_x64: + case windows_arm64: return 'windows'; - case TargetPlatform.android: - case TargetPlatform.android_arm: - case TargetPlatform.android_arm64: - case TargetPlatform.android_x64: + case android: + case android_arm: + case android_arm64: + case android_x64: return 'android'; - case TargetPlatform.fuchsia_arm64: - case TargetPlatform.fuchsia_x64: + case fuchsia_arm64: + case fuchsia_x64: return 'fuchsia'; - case TargetPlatform.ios: + case ios: return 'ios'; - case TargetPlatform.tester: + case tester: return 'flutter-tester'; - case TargetPlatform.web_javascript: + case web_javascript: return 'web'; - case TargetPlatform.unsupported: + case unsupported: throw UnsupportedError('Unexpected target platform $this'); } } String get simpleName { switch (this) { - case TargetPlatform.linux_x64: - case TargetPlatform.darwin: - case TargetPlatform.windows_x64: + case linux_x64: + case darwin: + case windows_x64: return 'x64'; - case TargetPlatform.linux_arm64: - case TargetPlatform.windows_arm64: + case linux_arm64: + case windows_arm64: return 'arm64'; - case TargetPlatform.linux_riscv64: + case linux_riscv64: return 'riscv64'; - case TargetPlatform.android: - case TargetPlatform.android_arm: - case TargetPlatform.android_arm64: - case TargetPlatform.android_x64: - case TargetPlatform.fuchsia_arm64: - case TargetPlatform.fuchsia_x64: - case TargetPlatform.ios: - case TargetPlatform.tester: - case TargetPlatform.web_javascript: - case TargetPlatform.unsupported: + case android: + case android_arm: + case android_arm64: + case android_x64: + case fuchsia_arm64: + case fuchsia_x64: + case ios: + case tester: + case web_javascript: + case unsupported: throw UnsupportedError('Unexpected target platform $this'); } } @@ -741,9 +741,9 @@ enum DarwinArch { /// merged into a universal binary using the `lipo` tool. String get dartName { return switch (this) { - DarwinArch.armv7 => 'armv7', - DarwinArch.arm64 => 'arm64', - DarwinArch.x86_64 => 'x64', + armv7 => 'armv7', + arm64 => 'arm64', + x86_64 => 'x64', }; } } @@ -755,15 +755,15 @@ enum AndroidArch { x86_64; String get archName => switch (this) { - AndroidArch.armeabi_v7a => 'armeabi-v7a', - AndroidArch.arm64_v8a => 'arm64-v8a', - AndroidArch.x86_64 => 'x86_64', + armeabi_v7a => 'armeabi-v7a', + arm64_v8a => 'arm64-v8a', + x86_64 => 'x86_64', }; String get platformName => switch (this) { - AndroidArch.armeabi_v7a => 'android-arm', - AndroidArch.arm64_v8a => 'android-arm64', - AndroidArch.x86_64 => 'android-x64', + armeabi_v7a => 'android-arm', + arm64_v8a => 'android-arm64', + x86_64 => 'android-x64', }; } diff --git a/packages/flutter_tools/lib/src/darwin/darwin.dart b/packages/flutter_tools/lib/src/darwin/darwin.dart index 1c0cb8e6d0d..1a2da7ddbbc 100644 --- a/packages/flutter_tools/lib/src/darwin/darwin.dart +++ b/packages/flutter_tools/lib/src/darwin/darwin.dart @@ -71,12 +71,10 @@ enum FlutterDarwinPlatform { /// Minimum supported version for the platform. Version deploymentTarget() { - switch (this) { - case FlutterDarwinPlatform.ios: - return Version(13, 0, null); - case FlutterDarwinPlatform.macos: - return Version(10, 15, null); - } + return switch (this) { + ios => Version(13, 0, null), + macos => Version(10, 15, null), + }; } /// Artifact name for the platform and [mode]. @@ -117,11 +115,9 @@ enum FlutterDarwinPlatform { /// Returns corresponding [XcodeBasedProject] for the platform. XcodeBasedProject xcodeProject(FlutterProject project) { - switch (this) { - case FlutterDarwinPlatform.ios: - return project.ios; - case FlutterDarwinPlatform.macos: - return project.macos; - } + return switch (this) { + ios => project.ios, + macos => project.macos, + }; } } diff --git a/packages/flutter_tools/lib/src/drive/web_driver_service.dart b/packages/flutter_tools/lib/src/drive/web_driver_service.dart index 75e7e088431..ef736c51712 100644 --- a/packages/flutter_tools/lib/src/drive/web_driver_service.dart +++ b/packages/flutter_tools/lib/src/drive/web_driver_service.dart @@ -297,18 +297,18 @@ enum Browser implements CliEnum { @override String get helpText => switch (this) { - Browser.androidChrome => 'Chrome on Android (see also "--android-emulator").', - Browser.chrome => 'Google Chrome on this computer (see also "--chrome-binary").', - Browser.edge => 'Microsoft Edge on this computer (Windows only).', - Browser.firefox => 'Mozilla Firefox on this computer.', - Browser.iosSafari => 'Apple Safari on an iOS device.', - Browser.safari => 'Apple Safari on this computer (macOS only).', + androidChrome => 'Chrome on Android (see also "--android-emulator").', + chrome => 'Google Chrome on this computer (see also "--chrome-binary").', + edge => 'Microsoft Edge on this computer (Windows only).', + firefox => 'Mozilla Firefox on this computer.', + iosSafari => 'Apple Safari on an iOS device.', + safari => 'Apple Safari on this computer (macOS only).', }; @override String get cliName => kebabCase(name); - static Browser fromCliName(String? value) => Browser.values.singleWhere( + static Browser fromCliName(String? value) => values.singleWhere( (Browser element) => element.cliName == value, orElse: () => throw UnsupportedError('Browser $value not supported'), ); diff --git a/packages/flutter_tools/lib/src/web/file_generators/flutter_service_worker_js.dart b/packages/flutter_tools/lib/src/web/file_generators/flutter_service_worker_js.dart index 2769efbaed0..fe1d42cf739 100644 --- a/packages/flutter_tools/lib/src/web/file_generators/flutter_service_worker_js.dart +++ b/packages/flutter_tools/lib/src/web/file_generators/flutter_service_worker_js.dart @@ -26,12 +26,12 @@ enum ServiceWorkerStrategy implements CliEnum { @override String get helpText => switch (this) { - ServiceWorkerStrategy.offlineFirst => + offlineFirst => 'Attempt to cache the application shell eagerly and then lazily ' 'cache all subsequent assets as they are loaded. When making a ' 'network request for an asset, the offline cache will be ' 'preferred.', - ServiceWorkerStrategy.none => + none => 'Generate a service worker with no body. This is useful for local ' 'testing or in cases where the service worker caching ' 'functionality is not desirable',