Skip to content

Commit b86bde3

Browse files
goderbauergspencergoog
authored andcommitted
enable use_enums (flutter#117376)
1 parent 4677280 commit b86bde3

File tree

4 files changed

+33
-37
lines changed

4 files changed

+33
-37
lines changed

analysis_options.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ linter:
223223
- use_build_context_synchronously
224224
# - use_colored_box # not yet tested
225225
# - use_decorated_box # leads to bugs: DecoratedBox and Container are not equivalent (Container inserts extra padding)
226-
# - use_enums # not yet tested
226+
- use_enums
227227
- use_full_hex_values_for_flutter_colors
228228
- use_function_type_syntax_for_parameters
229229
- use_if_null_to_convert_nulls_to_bools

packages/flutter/lib/src/services/hardware_keyboard.dart

+11-12
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,33 @@ export 'raw_keyboard.dart' show RawKeyEvent, RawKeyboard;
2626
/// Only a limited number of modes are supported, which are enumerated as
2727
/// static members of this class. Manual constructing of this class is
2828
/// prohibited.
29-
@immutable
30-
class KeyboardLockMode {
31-
// KeyboardLockMode has a fixed pool of supported keys, enumerated as static
32-
// members of this class, therefore constructing is prohibited.
33-
const KeyboardLockMode._(this.logicalKey);
34-
35-
/// The logical key that triggers this lock mode.
36-
final LogicalKeyboardKey logicalKey;
37-
29+
enum KeyboardLockMode {
3830
/// Represents the number lock mode on the keyboard.
3931
///
4032
/// On supporting systems, enabling number lock mode usually allows key
4133
/// presses of the number pad to input numbers, instead of acting as up, down,
4234
/// left, right, page up, end, etc.
43-
static const KeyboardLockMode numLock = KeyboardLockMode._(LogicalKeyboardKey.numLock);
35+
numLock._(LogicalKeyboardKey.numLock),
4436

4537
/// Represents the scrolling lock mode on the keyboard.
4638
///
4739
/// On supporting systems and applications (such as a spreadsheet), enabling
4840
/// scrolling lock mode usually allows key presses of the cursor keys to
4941
/// scroll the document instead of the cursor.
50-
static const KeyboardLockMode scrollLock = KeyboardLockMode._(LogicalKeyboardKey.scrollLock);
42+
scrollLock._(LogicalKeyboardKey.scrollLock),
5143

5244
/// Represents the capital letters lock mode on the keyboard.
5345
///
5446
/// On supporting systems, enabling capital lock mode allows key presses of
5547
/// the letter keys to input uppercase letters instead of lowercase.
56-
static const KeyboardLockMode capsLock = KeyboardLockMode._(LogicalKeyboardKey.capsLock);
48+
capsLock._(LogicalKeyboardKey.capsLock);
49+
50+
// KeyboardLockMode has a fixed pool of supported keys, enumerated as static
51+
// members of this class, therefore constructing is prohibited.
52+
const KeyboardLockMode._(this.logicalKey);
53+
54+
/// The logical key that triggers this lock mode.
55+
final LogicalKeyboardKey logicalKey;
5756

5857
static final Map<int, KeyboardLockMode> _knownLockModes = <int, KeyboardLockMode>{
5958
numLock.logicalKey.keyId: numLock,

packages/flutter_tools/lib/src/commands/daemon.dart

+4-7
Original file line numberDiff line numberDiff line change
@@ -1565,14 +1565,11 @@ class LogMessage {
15651565
}
15661566

15671567
/// The method by which the Flutter app was launched.
1568-
class LaunchMode {
1569-
const LaunchMode._(this._value);
1570-
1571-
/// The app was launched via `flutter run`.
1572-
static const LaunchMode run = LaunchMode._('run');
1568+
enum LaunchMode {
1569+
run._('run'),
1570+
attach._('attach');
15731571

1574-
/// The app was launched via `flutter attach`.
1575-
static const LaunchMode attach = LaunchMode._('attach');
1572+
const LaunchMode._(this._value);
15761573

15771574
final String _value;
15781575

packages/flutter_tools/lib/src/device.dart

+17-17
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ import 'vmservice.dart';
2323
DeviceManager? get deviceManager => context.get<DeviceManager>();
2424

2525
/// A description of the kind of workflow the device supports.
26-
class Category {
27-
const Category._(this.value);
26+
enum Category {
27+
web._('web'),
28+
desktop._('desktop'),
29+
mobile._('mobile');
2830

29-
static const Category web = Category._('web');
30-
static const Category desktop = Category._('desktop');
31-
static const Category mobile = Category._('mobile');
31+
const Category._(this.value);
3232

3333
final String value;
3434

3535
@override
3636
String toString() => value;
3737

3838
static Category? fromString(String category) {
39-
return <String, Category>{
39+
return const <String, Category>{
4040
'web': web,
4141
'desktop': desktop,
4242
'mobile': mobile,
@@ -45,25 +45,25 @@ class Category {
4545
}
4646

4747
/// The platform sub-folder that a device type supports.
48-
class PlatformType {
49-
const PlatformType._(this.value);
48+
enum PlatformType {
49+
web._('web'),
50+
android._('android'),
51+
ios._('ios'),
52+
linux._('linux'),
53+
macos._('macos'),
54+
windows._('windows'),
55+
fuchsia._('fuchsia'),
56+
custom._('custom');
5057

51-
static const PlatformType web = PlatformType._('web');
52-
static const PlatformType android = PlatformType._('android');
53-
static const PlatformType ios = PlatformType._('ios');
54-
static const PlatformType linux = PlatformType._('linux');
55-
static const PlatformType macos = PlatformType._('macos');
56-
static const PlatformType windows = PlatformType._('windows');
57-
static const PlatformType fuchsia = PlatformType._('fuchsia');
58-
static const PlatformType custom = PlatformType._('custom');
58+
const PlatformType._(this.value);
5959

6060
final String value;
6161

6262
@override
6363
String toString() => value;
6464

6565
static PlatformType? fromString(String platformType) {
66-
return <String, PlatformType>{
66+
return const <String, PlatformType>{
6767
'web': web,
6868
'android': android,
6969
'ios': ios,

0 commit comments

Comments
 (0)