Unverified Commit 9dc9cf57 authored by Kirolous Nashaat's avatar Kirolous Nashaat Committed by GitHub

Added optional parameter keyboardType to showDatePicker (#93439)

parent 0277a46b
......@@ -151,6 +151,7 @@ Future<DateTime?> showDatePicker({
String? errorInvalidText,
String? fieldHintText,
String? fieldLabelText,
TextInputType? keyboardType,
}) async {
assert(context != null);
assert(initialDate != null);
......@@ -195,6 +196,7 @@ Future<DateTime?> showDatePicker({
errorInvalidText: errorInvalidText,
fieldHintText: fieldHintText,
fieldLabelText: fieldLabelText,
keyboardType: keyboardType,
);
if (textDirection != null) {
......@@ -249,6 +251,7 @@ class DatePickerDialog extends StatefulWidget {
this.errorInvalidText,
this.fieldHintText,
this.fieldLabelText,
this.keyboardType,
this.restorationId,
}) : assert(initialDate != null),
assert(firstDate != null),
......@@ -334,6 +337,11 @@ class DatePickerDialog extends StatefulWidget {
/// string. For example, 'Month, Day, Year' for en_US.
final String? fieldLabelText;
/// The keyboard type of the [TextField].
///
/// If this is null, it will default to [TextInputType.datetime]
final TextInputType? keyboardType;
/// Restoration ID to save and restore the state of the [DatePickerDialog].
///
/// If it is non-null, the date picker will persist and restore the
......@@ -512,6 +520,7 @@ class _DatePickerDialogState extends State<DatePickerDialog> with RestorationMix
errorInvalidText: widget.errorInvalidText,
fieldHintText: widget.fieldHintText,
fieldLabelText: widget.fieldLabelText,
keyboardType: widget.keyboardType,
autofocus: true,
),
const Spacer(),
......
......@@ -56,6 +56,7 @@ class InputDatePickerFormField extends StatefulWidget {
this.errorInvalidText,
this.fieldHintText,
this.fieldLabelText,
this.keyboardType,
this.autofocus = false,
}) : assert(firstDate != null),
assert(lastDate != null),
......@@ -125,6 +126,11 @@ class InputDatePickerFormField extends StatefulWidget {
/// string. For example, 'Month, Day, Year' for en_US.
final String? fieldLabelText;
/// The keyboard type of the [TextField].
///
/// If this is null, it will default to [TextInputType.datetime]
final TextInputType? keyboardType;
/// {@macro flutter.widgets.editableText.autofocus}
final bool autofocus;
......@@ -242,7 +248,7 @@ class _InputDatePickerFormFieldState extends State<InputDatePickerFormField> {
labelText: widget.fieldLabelText ?? localizations.dateInputLabel,
),
validator: _validateDate,
keyboardType: TextInputType.datetime,
keyboardType: widget.keyboardType ?? TextInputType.datetime,
onSaved: _handleSaved,
onFieldSubmitted: _handleSubmitted,
autofocus: widget.autofocus,
......
......@@ -26,6 +26,7 @@ void main() {
String? fieldHintText;
String? fieldLabelText;
String? helpText;
TextInputType? keyboardType;
final Finder nextMonthIcon = find.byWidgetPredicate((Widget w) => w is IconButton && (w.tooltip?.startsWith('Next month') ?? false));
final Finder previousMonthIcon = find.byWidgetPredicate((Widget w) => w is IconButton && (w.tooltip?.startsWith('Previous month') ?? false));
......@@ -52,6 +53,7 @@ void main() {
fieldHintText = null;
fieldLabelText = null;
helpText = null;
keyboardType = null;
});
Future<void> prepareDatePicker(
......@@ -94,6 +96,7 @@ void main() {
fieldHintText: fieldHintText,
fieldLabelText: fieldLabelText,
helpText: helpText,
keyboardType: keyboardType,
builder: (BuildContext context, Widget? child) {
return Directionality(
textDirection: textDirection,
......@@ -701,6 +704,14 @@ void main() {
});
});
testWidgets('KeyboardType is used', (WidgetTester tester) async {
keyboardType = TextInputType.text;
await prepareDatePicker(tester, (Future<DateTime?> date) async {
final TextField field = textField(tester);
expect(field.keyboardType, TextInputType.text);
});
});
testWidgets('Initial date is the default', (WidgetTester tester) async {
await prepareDatePicker(tester, (Future<DateTime?> date) async {
await tester.tap(find.text('OK'));
......
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