From 0220afdd3e1a09be387f6127cde344adb9287e4d Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Tue, 20 Dec 2022 12:06:24 -0800 Subject: [PATCH] enable use_enums (#117376) --- analysis_options.yaml | 2 +- .../lib/src/services/hardware_keyboard.dart | 23 ++++++------- .../lib/src/commands/daemon.dart | 11 +++--- packages/flutter_tools/lib/src/device.dart | 34 +++++++++---------- 4 files changed, 33 insertions(+), 37 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index f97380712d89..796d663a4f67 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -223,7 +223,7 @@ linter: - use_build_context_synchronously # - use_colored_box # not yet tested # - use_decorated_box # leads to bugs: DecoratedBox and Container are not equivalent (Container inserts extra padding) - # - use_enums # not yet tested + - use_enums - use_full_hex_values_for_flutter_colors - use_function_type_syntax_for_parameters - use_if_null_to_convert_nulls_to_bools diff --git a/packages/flutter/lib/src/services/hardware_keyboard.dart b/packages/flutter/lib/src/services/hardware_keyboard.dart index 4cf04b30ce06..953ac10bc16f 100644 --- a/packages/flutter/lib/src/services/hardware_keyboard.dart +++ b/packages/flutter/lib/src/services/hardware_keyboard.dart @@ -26,34 +26,33 @@ export 'raw_keyboard.dart' show RawKeyEvent, RawKeyboard; /// Only a limited number of modes are supported, which are enumerated as /// static members of this class. Manual constructing of this class is /// prohibited. -@immutable -class KeyboardLockMode { - // KeyboardLockMode has a fixed pool of supported keys, enumerated as static - // members of this class, therefore constructing is prohibited. - const KeyboardLockMode._(this.logicalKey); - - /// The logical key that triggers this lock mode. - final LogicalKeyboardKey logicalKey; - +enum KeyboardLockMode { /// Represents the number lock mode on the keyboard. /// /// On supporting systems, enabling number lock mode usually allows key /// presses of the number pad to input numbers, instead of acting as up, down, /// left, right, page up, end, etc. - static const KeyboardLockMode numLock = KeyboardLockMode._(LogicalKeyboardKey.numLock); + numLock._(LogicalKeyboardKey.numLock), /// Represents the scrolling lock mode on the keyboard. /// /// On supporting systems and applications (such as a spreadsheet), enabling /// scrolling lock mode usually allows key presses of the cursor keys to /// scroll the document instead of the cursor. - static const KeyboardLockMode scrollLock = KeyboardLockMode._(LogicalKeyboardKey.scrollLock); + scrollLock._(LogicalKeyboardKey.scrollLock), /// Represents the capital letters lock mode on the keyboard. /// /// On supporting systems, enabling capital lock mode allows key presses of /// the letter keys to input uppercase letters instead of lowercase. - static const KeyboardLockMode capsLock = KeyboardLockMode._(LogicalKeyboardKey.capsLock); + capsLock._(LogicalKeyboardKey.capsLock); + + // KeyboardLockMode has a fixed pool of supported keys, enumerated as static + // members of this class, therefore constructing is prohibited. + const KeyboardLockMode._(this.logicalKey); + + /// The logical key that triggers this lock mode. + final LogicalKeyboardKey logicalKey; static final Map _knownLockModes = { numLock.logicalKey.keyId: numLock, diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index 11fb279f459c..7ddc7e3b5ae8 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -1565,14 +1565,11 @@ class LogMessage { } /// The method by which the Flutter app was launched. -class LaunchMode { - const LaunchMode._(this._value); - - /// The app was launched via `flutter run`. - static const LaunchMode run = LaunchMode._('run'); +enum LaunchMode { + run._('run'), + attach._('attach'); - /// The app was launched via `flutter attach`. - static const LaunchMode attach = LaunchMode._('attach'); + const LaunchMode._(this._value); final String _value; diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 31b19234bf66..80161152bb60 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -23,12 +23,12 @@ import 'vmservice.dart'; DeviceManager? get deviceManager => context.get(); /// A description of the kind of workflow the device supports. -class Category { - const Category._(this.value); +enum Category { + web._('web'), + desktop._('desktop'), + mobile._('mobile'); - static const Category web = Category._('web'); - static const Category desktop = Category._('desktop'); - static const Category mobile = Category._('mobile'); + const Category._(this.value); final String value; @@ -36,7 +36,7 @@ class Category { String toString() => value; static Category? fromString(String category) { - return { + return const { 'web': web, 'desktop': desktop, 'mobile': mobile, @@ -45,17 +45,17 @@ class Category { } /// The platform sub-folder that a device type supports. -class PlatformType { - const PlatformType._(this.value); +enum PlatformType { + web._('web'), + android._('android'), + ios._('ios'), + linux._('linux'), + macos._('macos'), + windows._('windows'), + fuchsia._('fuchsia'), + custom._('custom'); - static const PlatformType web = PlatformType._('web'); - static const PlatformType android = PlatformType._('android'); - static const PlatformType ios = PlatformType._('ios'); - static const PlatformType linux = PlatformType._('linux'); - static const PlatformType macos = PlatformType._('macos'); - static const PlatformType windows = PlatformType._('windows'); - static const PlatformType fuchsia = PlatformType._('fuchsia'); - static const PlatformType custom = PlatformType._('custom'); + const PlatformType._(this.value); final String value; @@ -63,7 +63,7 @@ class PlatformType { String toString() => value; static PlatformType? fromString(String platformType) { - return { + return const { 'web': web, 'android': android, 'ios': ios,