refactor: navigation/offline handling
and other improvments
This commit is contained in:
@@ -1,54 +1,55 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// Shared sets for keyboard key categories.
|
||||
final _dpadDirectionKeys = {
|
||||
LogicalKeyboardKey.arrowUp,
|
||||
LogicalKeyboardKey.arrowDown,
|
||||
LogicalKeyboardKey.arrowLeft,
|
||||
LogicalKeyboardKey.arrowRight,
|
||||
};
|
||||
|
||||
final _selectKeys = {
|
||||
LogicalKeyboardKey.select,
|
||||
LogicalKeyboardKey.enter,
|
||||
LogicalKeyboardKey.numpadEnter,
|
||||
LogicalKeyboardKey.gameButtonA,
|
||||
};
|
||||
|
||||
final _backKeys = {
|
||||
LogicalKeyboardKey.escape,
|
||||
LogicalKeyboardKey.goBack,
|
||||
LogicalKeyboardKey.browserBack,
|
||||
LogicalKeyboardKey.gameButtonB,
|
||||
};
|
||||
|
||||
final _contextMenuKeys = {
|
||||
LogicalKeyboardKey.contextMenu,
|
||||
LogicalKeyboardKey.gameButtonX,
|
||||
};
|
||||
|
||||
/// Extension methods for checking D-pad related keys.
|
||||
extension DpadKeyExtension on LogicalKeyboardKey {
|
||||
/// Whether this key is a D-pad directional key.
|
||||
bool get isDpadDirection {
|
||||
return this == LogicalKeyboardKey.arrowUp ||
|
||||
this == LogicalKeyboardKey.arrowDown ||
|
||||
this == LogicalKeyboardKey.arrowLeft ||
|
||||
this == LogicalKeyboardKey.arrowRight;
|
||||
}
|
||||
bool get isDpadDirection => _dpadDirectionKeys.contains(this);
|
||||
|
||||
/// Whether this key is a select/activate key.
|
||||
bool get isSelectKey {
|
||||
return this == LogicalKeyboardKey.select ||
|
||||
this == LogicalKeyboardKey.enter ||
|
||||
this == LogicalKeyboardKey.numpadEnter ||
|
||||
this == LogicalKeyboardKey.gameButtonA;
|
||||
}
|
||||
bool get isSelectKey => _selectKeys.contains(this);
|
||||
|
||||
/// Whether this key is a back/cancel key.
|
||||
bool get isBackKey {
|
||||
return this == LogicalKeyboardKey.escape ||
|
||||
this == LogicalKeyboardKey.goBack ||
|
||||
this == LogicalKeyboardKey.browserBack ||
|
||||
this == LogicalKeyboardKey.gameButtonB;
|
||||
}
|
||||
bool get isBackKey => _backKeys.contains(this);
|
||||
|
||||
/// Whether this key is a context menu key.
|
||||
bool get isContextMenuKey {
|
||||
return this == LogicalKeyboardKey.contextMenu ||
|
||||
this == LogicalKeyboardKey.gameButtonX;
|
||||
}
|
||||
bool get isContextMenuKey => _contextMenuKeys.contains(this);
|
||||
|
||||
/// Whether this key moves focus left.
|
||||
bool get isLeftKey {
|
||||
return this == LogicalKeyboardKey.arrowLeft;
|
||||
}
|
||||
bool get isLeftKey => this == LogicalKeyboardKey.arrowLeft;
|
||||
|
||||
/// Whether this key moves focus right.
|
||||
bool get isRightKey {
|
||||
return this == LogicalKeyboardKey.arrowRight;
|
||||
}
|
||||
bool get isRightKey => this == LogicalKeyboardKey.arrowRight;
|
||||
|
||||
/// Whether this key moves focus up.
|
||||
bool get isUpKey {
|
||||
return this == LogicalKeyboardKey.arrowUp;
|
||||
}
|
||||
bool get isUpKey => this == LogicalKeyboardKey.arrowUp;
|
||||
|
||||
/// Whether this key moves focus down.
|
||||
bool get isDownKey {
|
||||
return this == LogicalKeyboardKey.arrowDown;
|
||||
}
|
||||
bool get isDownKey => this == LogicalKeyboardKey.arrowDown;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user