Unverified Commit ffed0d57 authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

DateRangePicker keyboardType (#122353)

DateRangePicker now has a keyboardType parameter, same as DatePicker.
parent 313b0165
......@@ -340,9 +340,11 @@ class DatePickerDialog extends StatefulWidget {
/// string. For example, 'Month, Day, Year' for en_US.
final String? fieldLabelText;
/// {@template flutter.material.datePickerDialog}
/// The keyboard type of the [TextField].
///
/// If this is null, it will default to [TextInputType.datetime]
/// {@endtemplate}
final TextInputType? keyboardType;
/// Restoration ID to save and restore the state of the [DatePickerDialog].
......@@ -991,6 +993,7 @@ Future<DateTimeRange?> showDateRangePicker({
TextDirection? textDirection,
TransitionBuilder? builder,
Offset? anchorPoint,
TextInputType keyboardType = TextInputType.datetime,
}) async {
assert(
initialDateRange == null || !initialDateRange.start.isAfter(initialDateRange.end),
......@@ -1039,6 +1042,7 @@ Future<DateTimeRange?> showDateRangePicker({
fieldEndHintText: fieldEndHintText,
fieldStartLabelText: fieldStartLabelText,
fieldEndLabelText: fieldEndLabelText,
keyboardType: keyboardType,
);
if (textDirection != null) {
......@@ -1125,6 +1129,7 @@ class DateRangePickerDialog extends StatefulWidget {
this.fieldEndHintText,
this.fieldStartLabelText,
this.fieldEndLabelText,
this.keyboardType = TextInputType.datetime,
this.restorationId,
});
......@@ -1231,6 +1236,9 @@ class DateRangePickerDialog extends StatefulWidget {
/// is used.
final String? fieldEndLabelText;
/// {@macro flutter.material.datePickerDialog}
final TextInputType keyboardType;
/// Restoration ID to save and restore the state of the [DateRangePickerDialog].
///
/// If it is non-null, the date range picker will persist and restore the
......@@ -1427,6 +1435,7 @@ class _DateRangePickerDialogState extends State<DateRangePickerDialog> with Rest
fieldEndHintText: widget.fieldEndHintText,
fieldStartLabelText: widget.fieldStartLabelText,
fieldEndLabelText: widget.fieldEndLabelText,
keyboardType: widget.keyboardType,
),
const Spacer(),
],
......@@ -2773,6 +2782,7 @@ class _InputDateRangePicker extends StatefulWidget {
this.fieldEndLabelText,
this.autofocus = false,
this.autovalidate = false,
this.keyboardType = TextInputType.datetime,
}) : initialStartDate = initialStartDate == null ? null : DateUtils.dateOnly(initialStartDate),
initialEndDate = initialEndDate == null ? null : DateUtils.dateOnly(initialEndDate),
firstDate = DateUtils.dateOnly(firstDate),
......@@ -2832,6 +2842,9 @@ class _InputDateRangePicker extends StatefulWidget {
/// [_InputDateRangePickerState.validate] to validate.
final bool autovalidate;
/// {@macro flutter.material.datePickerDialog}
final TextInputType keyboardType;
@override
_InputDateRangePickerState createState() => _InputDateRangePickerState();
}
......@@ -2972,7 +2985,7 @@ class _InputDateRangePickerState extends State<_InputDateRangePicker> {
labelText: widget.fieldStartLabelText ?? localizations.dateRangeStartLabel,
errorText: _startErrorText,
),
keyboardType: TextInputType.datetime,
keyboardType: widget.keyboardType,
onChanged: _handleStartChanged,
autofocus: widget.autofocus,
),
......@@ -2988,7 +3001,7 @@ class _InputDateRangePickerState extends State<_InputDateRangePicker> {
labelText: widget.fieldEndLabelText ?? localizations.dateRangeEndLabel,
errorText: _endErrorText,
),
keyboardType: TextInputType.datetime,
keyboardType: widget.keyboardType,
onChanged: _handleEndChanged,
),
),
......
......@@ -1103,6 +1103,60 @@ void main() {
semantics.dispose();
});
});
for (final TextInputType? keyboardType in <TextInputType?>[null, TextInputType.emailAddress]) {
testWidgets('DateRangePicker takes keyboardType $keyboardType', (WidgetTester tester) async {
late BuildContext buttonContext;
const InputBorder border = InputBorder.none;
await tester.pumpWidget(MaterialApp(
theme: ThemeData.light().copyWith(
inputDecorationTheme: const InputDecorationTheme(
border: border,
),
),
home: Material(
child: Builder(
builder: (BuildContext context) {
return ElevatedButton(
onPressed: () {
buttonContext = context;
},
child: const Text('Go'),
);
},
),
),
));
await tester.tap(find.text('Go'));
expect(buttonContext, isNotNull);
if (keyboardType == null) {
// If no keyboardType, expect the default.
showDateRangePicker(
context: buttonContext,
initialDateRange: initialDateRange,
firstDate: firstDate,
lastDate: lastDate,
initialEntryMode: DatePickerEntryMode.input,
);
} else {
// If there is a keyboardType, expect it to be passed through.
showDateRangePicker(
context: buttonContext,
initialDateRange: initialDateRange,
firstDate: firstDate,
lastDate: lastDate,
initialEntryMode: DatePickerEntryMode.input,
keyboardType: keyboardType,
);
}
await tester.pumpAndSettle();
final DateRangePickerDialog picker = tester.widget(find.byType(DateRangePickerDialog));
expect(picker.keyboardType, keyboardType ?? TextInputType.datetime);
});
}
}
class _RestorableDateRangePickerDialogTestWidget extends StatefulWidget {
......
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