Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate LogicalKeySet to SingleActivator #80756

Merged
merged 8 commits into from Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions dev/manual_tests/lib/actions.dart
Expand Up @@ -406,9 +406,9 @@ class _FocusDemoState extends State<FocusDemo> {
child: FocusTraversalGroup(
policy: ReadingOrderTraversalPolicy(),
child: Shortcuts(
shortcuts: <LogicalKeySet, Intent>{
LogicalKeySet(Platform.isMacOS ? LogicalKeyboardKey.meta : LogicalKeyboardKey.control, LogicalKeyboardKey.shift, LogicalKeyboardKey.keyZ): const RedoIntent(),
LogicalKeySet(Platform.isMacOS ? LogicalKeyboardKey.meta : LogicalKeyboardKey.control, LogicalKeyboardKey.keyZ): const UndoIntent(),
shortcuts: <ShortcutActivator, Intent>{
SingleActivator(LogicalKeyboardKey.keyZ, meta: Platform.isMacOS, control: !Platform.isMacOS, shift: true): const RedoIntent(),
SingleActivator(LogicalKeyboardKey.keyZ, meta: Platform.isMacOS, control: !Platform.isMacOS): const UndoIntent(),
},
child: FocusScope(
key: FocusDemo.appKey,
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/lib/src/cupertino/app.dart
Expand Up @@ -346,9 +346,9 @@ class CupertinoApp extends StatefulWidget {
/// ```dart
/// Widget build(BuildContext context) {
/// return WidgetsApp(
/// shortcuts: <LogicalKeySet, Intent>{
/// shortcuts: <ShortcutActivator, Intent>{
/// ... WidgetsApp.defaultShortcuts,
/// LogicalKeySet(LogicalKeyboardKey.select): const ActivateIntent(),
/// const SingleActivator(LogicalKeyboardKey.select): const ActivateIntent(),
/// },
/// color: const Color(0xFFFF0000),
/// builder: (BuildContext context, Widget? child) {
Expand All @@ -359,7 +359,7 @@ class CupertinoApp extends StatefulWidget {
/// ```
/// {@end-tool}
/// {@macro flutter.widgets.widgetsApp.shortcuts.seeAlso}
final Map<LogicalKeySet, Intent>? shortcuts;
final Map<ShortcutActivator, Intent>? shortcuts;

/// {@macro flutter.widgets.widgetsApp.actions}
/// {@tool snippet}
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/lib/src/material/app.dart
Expand Up @@ -584,9 +584,9 @@ class MaterialApp extends StatefulWidget {
/// ```dart
/// Widget build(BuildContext context) {
/// return WidgetsApp(
/// shortcuts: <LogicalKeySet, Intent>{
/// shortcuts: <ShortcutActivator, Intent>{
/// ... WidgetsApp.defaultShortcuts,
/// LogicalKeySet(LogicalKeyboardKey.select): const ActivateIntent(),
/// const SingleActivator(LogicalKeyboardKey.select): const ActivateIntent(),
/// },
/// color: const Color(0xFFFF0000),
/// builder: (BuildContext context, Widget? child) {
Expand All @@ -597,7 +597,7 @@ class MaterialApp extends StatefulWidget {
/// ```
/// {@end-tool}
/// {@macro flutter.widgets.widgetsApp.shortcuts.seeAlso}
final Map<LogicalKeySet, Intent>? shortcuts;
final Map<ShortcutActivator, Intent>? shortcuts;

/// {@macro flutter.widgets.widgetsApp.actions}
/// {@tool snippet}
Expand Down
12 changes: 6 additions & 6 deletions packages/flutter/lib/src/material/calendar_date_picker.dart
Expand Up @@ -495,7 +495,7 @@ class _MonthPickerState extends State<_MonthPicker> {
late PageController _pageController;
late MaterialLocalizations _localizations;
late TextDirection _textDirection;
Map<LogicalKeySet, Intent>? _shortcutMap;
Map<ShortcutActivator, Intent>? _shortcutMap;
Map<Type, Action<Intent>>? _actionMap;
late FocusNode _dayGridFocus;
DateTime? _focusedDay;
Expand All @@ -507,11 +507,11 @@ class _MonthPickerState extends State<_MonthPicker> {
_previousMonthDate = DateUtils.addMonthsToMonthDate(_currentMonth, -1);
_nextMonthDate = DateUtils.addMonthsToMonthDate(_currentMonth, 1);
_pageController = PageController(initialPage: DateUtils.monthDelta(widget.firstDate, _currentMonth));
_shortcutMap = <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.arrowLeft): const DirectionalFocusIntent(TraversalDirection.left),
LogicalKeySet(LogicalKeyboardKey.arrowRight): const DirectionalFocusIntent(TraversalDirection.right),
LogicalKeySet(LogicalKeyboardKey.arrowDown): const DirectionalFocusIntent(TraversalDirection.down),
LogicalKeySet(LogicalKeyboardKey.arrowUp): const DirectionalFocusIntent(TraversalDirection.up),
_shortcutMap = const <ShortcutActivator, Intent>{
SingleActivator(LogicalKeyboardKey.arrowLeft): DirectionalFocusIntent(TraversalDirection.left),
SingleActivator(LogicalKeyboardKey.arrowRight): DirectionalFocusIntent(TraversalDirection.right),
SingleActivator(LogicalKeyboardKey.arrowDown): DirectionalFocusIntent(TraversalDirection.down),
SingleActivator(LogicalKeyboardKey.arrowUp): DirectionalFocusIntent(TraversalDirection.up),
};
_actionMap = <Type, Action<Intent>>{
NextFocusIntent: CallbackAction<NextFocusIntent>(onInvoke: _handleGridNextFocus),
Expand Down
17 changes: 8 additions & 9 deletions packages/flutter/lib/src/material/date_picker.dart
Expand Up @@ -496,9 +496,9 @@ class _DatePickerDialogState extends State<DatePickerDialog> with RestorationMix
}
}

static final Map<LogicalKeySet, Intent> _formShortcutMap = <LogicalKeySet, Intent>{
static const Map<ShortcutActivator, Intent> _formShortcutMap = <ShortcutActivator, Intent>{
// Pressing enter on the field will move focus to the next field or control.
LogicalKeySet(LogicalKeyboardKey.enter): const NextFocusIntent(),
SingleActivator(LogicalKeyboardKey.enter): NextFocusIntent(),
};

@override
Expand Down Expand Up @@ -1902,7 +1902,12 @@ class _CalendarKeyboardNavigator extends StatefulWidget {

class _CalendarKeyboardNavigatorState extends State<_CalendarKeyboardNavigator> {

late Map<LogicalKeySet, Intent> _shortcutMap;
final Map<ShortcutActivator, Intent> _shortcutMap = const <ShortcutActivator, Intent>{
SingleActivator(LogicalKeyboardKey.arrowLeft): DirectionalFocusIntent(TraversalDirection.left),
SingleActivator(LogicalKeyboardKey.arrowRight): DirectionalFocusIntent(TraversalDirection.right),
SingleActivator(LogicalKeyboardKey.arrowDown): DirectionalFocusIntent(TraversalDirection.down),
SingleActivator(LogicalKeyboardKey.arrowUp): DirectionalFocusIntent(TraversalDirection.up),
};
late Map<Type, Action<Intent>> _actionMap;
late FocusNode _dayGridFocus;
TraversalDirection? _dayTraversalDirection;
Expand All @@ -1912,12 +1917,6 @@ class _CalendarKeyboardNavigatorState extends State<_CalendarKeyboardNavigator>
void initState() {
super.initState();

_shortcutMap = <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.arrowLeft): const DirectionalFocusIntent(TraversalDirection.left),
LogicalKeySet(LogicalKeyboardKey.arrowRight): const DirectionalFocusIntent(TraversalDirection.right),
LogicalKeySet(LogicalKeyboardKey.arrowDown): const DirectionalFocusIntent(TraversalDirection.down),
LogicalKeySet(LogicalKeyboardKey.arrowUp): const DirectionalFocusIntent(TraversalDirection.up),
};
_actionMap = <Type, Action<Intent>>{
NextFocusIntent: CallbackAction<NextFocusIntent>(onInvoke: _handleGridNextFocus),
PreviousFocusIntent: CallbackAction<PreviousFocusIntent>(onInvoke: _handleGridPreviousFocus),
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/lib/src/material/dropdown.dart
Expand Up @@ -148,11 +148,11 @@ class _DropdownMenuItemButtonState<T> extends State<_DropdownMenuItemButton<T>>
);
}

static final Map<LogicalKeySet, Intent> _webShortcuts =<LogicalKeySet, Intent>{
static const Map<ShortcutActivator, Intent> _webShortcuts = <ShortcutActivator, Intent>{
// On the web, up/down don't change focus, *except* in a <select>
// element, which is what a dropdown emulates.
LogicalKeySet(LogicalKeyboardKey.arrowDown): const DirectionalFocusIntent(TraversalDirection.down),
LogicalKeySet(LogicalKeyboardKey.arrowUp): const DirectionalFocusIntent(TraversalDirection.up),
SingleActivator(LogicalKeyboardKey.arrowDown): DirectionalFocusIntent(TraversalDirection.down),
SingleActivator(LogicalKeyboardKey.arrowUp): DirectionalFocusIntent(TraversalDirection.up),
};

@override
Expand Down
13 changes: 6 additions & 7 deletions packages/flutter/lib/src/material/slider.dart
Expand Up @@ -477,7 +477,12 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {

final GlobalKey _renderObjectKey = GlobalKey();
// Keyboard mapping for a focused slider.
late Map<LogicalKeySet, Intent> _shortcutMap;
final Map<ShortcutActivator, Intent> _shortcutMap = const <ShortcutActivator, Intent>{
SingleActivator(LogicalKeyboardKey.arrowUp): _AdjustSliderIntent.up(),
SingleActivator(LogicalKeyboardKey.arrowDown): _AdjustSliderIntent.down(),
SingleActivator(LogicalKeyboardKey.arrowLeft): _AdjustSliderIntent.left(),
SingleActivator(LogicalKeyboardKey.arrowRight): _AdjustSliderIntent.right(),
};
// Action mapping for a focused slider.
late Map<Type, Action<Intent>> _actionMap;

Expand Down Expand Up @@ -506,12 +511,6 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
);
enableController.value = widget.onChanged != null ? 1.0 : 0.0;
positionController.value = _unlerp(widget.value);
_shortcutMap = <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.arrowUp): const _AdjustSliderIntent.up(),
LogicalKeySet(LogicalKeyboardKey.arrowDown): const _AdjustSliderIntent.down(),
LogicalKeySet(LogicalKeyboardKey.arrowLeft): const _AdjustSliderIntent.left(),
LogicalKeySet(LogicalKeyboardKey.arrowRight): const _AdjustSliderIntent.right(),
};
_actionMap = <Type, Action<Intent>>{
_AdjustSliderIntent: CallbackAction<_AdjustSliderIntent>(
onInvoke: _actionHandler,
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/material/text_form_field.dart
Expand Up @@ -81,9 +81,9 @@ export 'package:flutter/services.dart' show SmartQuotesType, SmartDashesType;
/// return Material(
/// child: Center(
/// child: Shortcuts(
/// shortcuts: <LogicalKeySet, Intent>{
/// shortcuts: const <ShortcutActivator, Intent>{
/// // Pressing space in the field will now move to the next field.
/// LogicalKeySet(LogicalKeyboardKey.space): const NextFocusIntent(),
/// SingleActivator(LogicalKeyboardKey.space): NextFocusIntent(),
/// },
/// child: FocusTraversalGroup(
/// child: Form(
Expand Down
11 changes: 5 additions & 6 deletions packages/flutter/lib/src/widgets/actions.dart
Expand Up @@ -1136,8 +1136,10 @@ class _ActionsMarker extends InheritedWidget {
/// bool _focused = false;
/// bool _hovering = false;
/// bool _on = false;
/// late Map<Type, Action<Intent>> _actionMap;
/// late Map<LogicalKeySet, Intent> _shortcutMap;
/// late final Map<Type, Action<Intent>> _actionMap;
/// final Map<ShortcutActivator, Intent> _shortcutMap = const <ShortcutActivator, Intent>{
/// SingleActivator(LogicalKeyboardKey.keyX): ActivateIntent(),
/// };
///
/// @override
/// void initState() {
Expand All @@ -1147,9 +1149,6 @@ class _ActionsMarker extends InheritedWidget {
/// onInvoke: (Intent intent) => _toggleState(),
/// ),
/// };
/// _shortcutMap = <LogicalKeySet, Intent>{
/// LogicalKeySet(LogicalKeyboardKey.keyX): const ActivateIntent(),
/// };
/// }
///
/// Color get color {
Expand Down Expand Up @@ -1287,7 +1286,7 @@ class FocusableActionDetector extends StatefulWidget {
final Map<Type, Action<Intent>>? actions;

/// {@macro flutter.widgets.shortcuts.shortcuts}
final Map<LogicalKeySet, Intent>? shortcuts;
final Map<ShortcutActivator, Intent>? shortcuts;

/// A function that will be called when the focus highlight should be shown or
/// hidden.
Expand Down