DateRangePicker keyboardType (#122353)
DateRangePicker now has a keyboardType parameter, same as DatePicker.
This commit is contained in:
parent
313b01658a
commit
ffed0d57ef
@ -340,9 +340,11 @@ class DatePickerDialog extends StatefulWidget {
|
|||||||
/// string. For example, 'Month, Day, Year' for en_US.
|
/// string. For example, 'Month, Day, Year' for en_US.
|
||||||
final String? fieldLabelText;
|
final String? fieldLabelText;
|
||||||
|
|
||||||
|
/// {@template flutter.material.datePickerDialog}
|
||||||
/// The keyboard type of the [TextField].
|
/// The keyboard type of the [TextField].
|
||||||
///
|
///
|
||||||
/// If this is null, it will default to [TextInputType.datetime]
|
/// If this is null, it will default to [TextInputType.datetime]
|
||||||
|
/// {@endtemplate}
|
||||||
final TextInputType? keyboardType;
|
final TextInputType? keyboardType;
|
||||||
|
|
||||||
/// Restoration ID to save and restore the state of the [DatePickerDialog].
|
/// Restoration ID to save and restore the state of the [DatePickerDialog].
|
||||||
@ -991,6 +993,7 @@ Future<DateTimeRange?> showDateRangePicker({
|
|||||||
TextDirection? textDirection,
|
TextDirection? textDirection,
|
||||||
TransitionBuilder? builder,
|
TransitionBuilder? builder,
|
||||||
Offset? anchorPoint,
|
Offset? anchorPoint,
|
||||||
|
TextInputType keyboardType = TextInputType.datetime,
|
||||||
}) async {
|
}) async {
|
||||||
assert(
|
assert(
|
||||||
initialDateRange == null || !initialDateRange.start.isAfter(initialDateRange.end),
|
initialDateRange == null || !initialDateRange.start.isAfter(initialDateRange.end),
|
||||||
@ -1039,6 +1042,7 @@ Future<DateTimeRange?> showDateRangePicker({
|
|||||||
fieldEndHintText: fieldEndHintText,
|
fieldEndHintText: fieldEndHintText,
|
||||||
fieldStartLabelText: fieldStartLabelText,
|
fieldStartLabelText: fieldStartLabelText,
|
||||||
fieldEndLabelText: fieldEndLabelText,
|
fieldEndLabelText: fieldEndLabelText,
|
||||||
|
keyboardType: keyboardType,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (textDirection != null) {
|
if (textDirection != null) {
|
||||||
@ -1125,6 +1129,7 @@ class DateRangePickerDialog extends StatefulWidget {
|
|||||||
this.fieldEndHintText,
|
this.fieldEndHintText,
|
||||||
this.fieldStartLabelText,
|
this.fieldStartLabelText,
|
||||||
this.fieldEndLabelText,
|
this.fieldEndLabelText,
|
||||||
|
this.keyboardType = TextInputType.datetime,
|
||||||
this.restorationId,
|
this.restorationId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1231,6 +1236,9 @@ class DateRangePickerDialog extends StatefulWidget {
|
|||||||
/// is used.
|
/// is used.
|
||||||
final String? fieldEndLabelText;
|
final String? fieldEndLabelText;
|
||||||
|
|
||||||
|
/// {@macro flutter.material.datePickerDialog}
|
||||||
|
final TextInputType keyboardType;
|
||||||
|
|
||||||
/// Restoration ID to save and restore the state of the [DateRangePickerDialog].
|
/// 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
|
/// 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,
|
fieldEndHintText: widget.fieldEndHintText,
|
||||||
fieldStartLabelText: widget.fieldStartLabelText,
|
fieldStartLabelText: widget.fieldStartLabelText,
|
||||||
fieldEndLabelText: widget.fieldEndLabelText,
|
fieldEndLabelText: widget.fieldEndLabelText,
|
||||||
|
keyboardType: widget.keyboardType,
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
],
|
],
|
||||||
@ -2773,6 +2782,7 @@ class _InputDateRangePicker extends StatefulWidget {
|
|||||||
this.fieldEndLabelText,
|
this.fieldEndLabelText,
|
||||||
this.autofocus = false,
|
this.autofocus = false,
|
||||||
this.autovalidate = false,
|
this.autovalidate = false,
|
||||||
|
this.keyboardType = TextInputType.datetime,
|
||||||
}) : initialStartDate = initialStartDate == null ? null : DateUtils.dateOnly(initialStartDate),
|
}) : initialStartDate = initialStartDate == null ? null : DateUtils.dateOnly(initialStartDate),
|
||||||
initialEndDate = initialEndDate == null ? null : DateUtils.dateOnly(initialEndDate),
|
initialEndDate = initialEndDate == null ? null : DateUtils.dateOnly(initialEndDate),
|
||||||
firstDate = DateUtils.dateOnly(firstDate),
|
firstDate = DateUtils.dateOnly(firstDate),
|
||||||
@ -2832,6 +2842,9 @@ class _InputDateRangePicker extends StatefulWidget {
|
|||||||
/// [_InputDateRangePickerState.validate] to validate.
|
/// [_InputDateRangePickerState.validate] to validate.
|
||||||
final bool autovalidate;
|
final bool autovalidate;
|
||||||
|
|
||||||
|
/// {@macro flutter.material.datePickerDialog}
|
||||||
|
final TextInputType keyboardType;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_InputDateRangePickerState createState() => _InputDateRangePickerState();
|
_InputDateRangePickerState createState() => _InputDateRangePickerState();
|
||||||
}
|
}
|
||||||
@ -2972,7 +2985,7 @@ class _InputDateRangePickerState extends State<_InputDateRangePicker> {
|
|||||||
labelText: widget.fieldStartLabelText ?? localizations.dateRangeStartLabel,
|
labelText: widget.fieldStartLabelText ?? localizations.dateRangeStartLabel,
|
||||||
errorText: _startErrorText,
|
errorText: _startErrorText,
|
||||||
),
|
),
|
||||||
keyboardType: TextInputType.datetime,
|
keyboardType: widget.keyboardType,
|
||||||
onChanged: _handleStartChanged,
|
onChanged: _handleStartChanged,
|
||||||
autofocus: widget.autofocus,
|
autofocus: widget.autofocus,
|
||||||
),
|
),
|
||||||
@ -2988,7 +3001,7 @@ class _InputDateRangePickerState extends State<_InputDateRangePicker> {
|
|||||||
labelText: widget.fieldEndLabelText ?? localizations.dateRangeEndLabel,
|
labelText: widget.fieldEndLabelText ?? localizations.dateRangeEndLabel,
|
||||||
errorText: _endErrorText,
|
errorText: _endErrorText,
|
||||||
),
|
),
|
||||||
keyboardType: TextInputType.datetime,
|
keyboardType: widget.keyboardType,
|
||||||
onChanged: _handleEndChanged,
|
onChanged: _handleEndChanged,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -1103,6 +1103,60 @@ void main() {
|
|||||||
semantics.dispose();
|
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 {
|
class _RestorableDateRangePickerDialogTestWidget extends StatefulWidget {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user