Skip to content

Commit

Permalink
enable use_enums (#117376)
Browse files Browse the repository at this point in the history
  • Loading branch information
goderbauer committed Dec 20, 2022
1 parent e0742eb commit 0220afd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 37 deletions.
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 11 additions & 12 deletions packages/flutter/lib/src/services/hardware_keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, KeyboardLockMode> _knownLockModes = <int, KeyboardLockMode>{
numLock.logicalKey.keyId: numLock,
Expand Down
11 changes: 4 additions & 7 deletions packages/flutter_tools/lib/src/commands/daemon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
34 changes: 17 additions & 17 deletions packages/flutter_tools/lib/src/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ import 'vmservice.dart';
DeviceManager? get deviceManager => context.get<DeviceManager>();

/// 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;

@override
String toString() => value;

static Category? fromString(String category) {
return <String, Category>{
return const <String, Category>{
'web': web,
'desktop': desktop,
'mobile': mobile,
Expand All @@ -45,25 +45,25 @@ 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;

@override
String toString() => value;

static PlatformType? fromString(String platformType) {
return <String, PlatformType>{
return const <String, PlatformType>{
'web': web,
'android': android,
'ios': ios,
Expand Down

0 comments on commit 0220afd

Please sign in to comment.