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,24 +424,27 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { ...@@ -419,24 +424,27 @@ 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: Column( child: Shortcuts(
children: <Widget>[ shortcuts: _formShortcutMap,
const Spacer(), child: Column(
InputDatePickerFormField( children: <Widget>[
initialDate: _selectedDate, const Spacer(),
firstDate: widget.firstDate, InputDatePickerFormField(
lastDate: widget.lastDate, initialDate: _selectedDate,
onDateSubmitted: _handleDateChanged, firstDate: widget.firstDate,
onDateSaved: _handleDateChanged, lastDate: widget.lastDate,
selectableDayPredicate: widget.selectableDayPredicate, onDateSubmitted: _handleDateChanged,
errorFormatText: widget.errorFormatText, onDateSaved: _handleDateChanged,
errorInvalidText: widget.errorInvalidText, selectableDayPredicate: widget.selectableDayPredicate,
fieldHintText: widget.fieldHintText, errorFormatText: widget.errorFormatText,
fieldLabelText: widget.fieldLabelText, errorInvalidText: widget.errorInvalidText,
autofocus: true, fieldHintText: widget.fieldHintText,
), fieldLabelText: widget.fieldLabelText,
const Spacer(), autofocus: true,
], ),
const Spacer(),
],
),
), ),
), ),
); );
......
...@@ -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