Unverified Commit cc36608f authored by Darren Austin's avatar Darren Austin Committed by GitHub

Keyboard navigation for the Material Date Picker grid (#59586)

parent dd6dd7ae
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import '../button_bar.dart'; import '../button_bar.dart';
...@@ -357,6 +357,11 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { ...@@ -357,6 +357,11 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
return null; return null;
} }
static final Map<LogicalKeySet, Intent> _formShortcutMap = <LogicalKeySet, Intent>{
// Pressing enter on the field will move focus to the next field or control.
LogicalKeySet(LogicalKeyboardKey.enter): const NextFocusIntent(),
};
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context);
...@@ -419,6 +424,8 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { ...@@ -419,6 +424,8 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
child: Container( child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24), padding: const EdgeInsets.symmetric(horizontal: 24),
height: orientation == Orientation.portrait ? _inputFormPortraitHeight : _inputFormLandscapeHeight, height: orientation == Orientation.portrait ? _inputFormPortraitHeight : _inputFormLandscapeHeight,
child: Shortcuts(
shortcuts: _formShortcutMap,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
const Spacer(), const Spacer(),
...@@ -439,6 +446,7 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { ...@@ -439,6 +446,7 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
], ],
), ),
), ),
),
); );
entryModeIcon = Icons.calendar_today; entryModeIcon = Icons.calendar_today;
entryModeTooltip = localizations.calendarModeButtonLabel; entryModeTooltip = localizations.calendarModeButtonLabel;
......
...@@ -26,12 +26,20 @@ DateTimeRange datesOnly(DateTimeRange range) { ...@@ -26,12 +26,20 @@ DateTimeRange datesOnly(DateTimeRange range) {
} }
/// Returns true if the two [DateTime] objects have the same day, month, and /// Returns true if the two [DateTime] objects have the same day, month, and
/// year. /// year, or are both null.
bool isSameDay(DateTime dateA, DateTime dateB) { bool isSameDay(DateTime dateA, DateTime dateB) {
return return
dateA.year == dateB.year && dateA?.year == dateB?.year &&
dateA.month == dateB.month && dateA?.month == dateB?.month &&
dateA.day == dateB.day; dateA?.day == dateB?.day;
}
/// Returns true if the two [DateTime] objects have the same month, and
/// year, or are both null.
bool isSameMonth(DateTime dateA, DateTime dateB) {
return
dateA?.year == dateB?.year &&
dateA?.month == dateB?.month;
} }
/// Determines the number of months between two [DateTime] objects. /// Determines the number of months between two [DateTime] objects.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment