Added optional parameter keyboardType to showDatePicker (#93439)
This commit is contained in:
parent
0277a46b80
commit
9dc9cf57f2
@ -151,6 +151,7 @@ Future<DateTime?> showDatePicker({
|
|||||||
String? errorInvalidText,
|
String? errorInvalidText,
|
||||||
String? fieldHintText,
|
String? fieldHintText,
|
||||||
String? fieldLabelText,
|
String? fieldLabelText,
|
||||||
|
TextInputType? keyboardType,
|
||||||
}) async {
|
}) async {
|
||||||
assert(context != null);
|
assert(context != null);
|
||||||
assert(initialDate != null);
|
assert(initialDate != null);
|
||||||
@ -195,6 +196,7 @@ Future<DateTime?> showDatePicker({
|
|||||||
errorInvalidText: errorInvalidText,
|
errorInvalidText: errorInvalidText,
|
||||||
fieldHintText: fieldHintText,
|
fieldHintText: fieldHintText,
|
||||||
fieldLabelText: fieldLabelText,
|
fieldLabelText: fieldLabelText,
|
||||||
|
keyboardType: keyboardType,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (textDirection != null) {
|
if (textDirection != null) {
|
||||||
@ -249,6 +251,7 @@ class DatePickerDialog extends StatefulWidget {
|
|||||||
this.errorInvalidText,
|
this.errorInvalidText,
|
||||||
this.fieldHintText,
|
this.fieldHintText,
|
||||||
this.fieldLabelText,
|
this.fieldLabelText,
|
||||||
|
this.keyboardType,
|
||||||
this.restorationId,
|
this.restorationId,
|
||||||
}) : assert(initialDate != null),
|
}) : assert(initialDate != null),
|
||||||
assert(firstDate != null),
|
assert(firstDate != null),
|
||||||
@ -334,6 +337,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;
|
||||||
|
|
||||||
|
/// 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].
|
/// Restoration ID to save and restore the state of the [DatePickerDialog].
|
||||||
///
|
///
|
||||||
/// If it is non-null, the date picker will persist and restore the
|
/// 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,
|
errorInvalidText: widget.errorInvalidText,
|
||||||
fieldHintText: widget.fieldHintText,
|
fieldHintText: widget.fieldHintText,
|
||||||
fieldLabelText: widget.fieldLabelText,
|
fieldLabelText: widget.fieldLabelText,
|
||||||
|
keyboardType: widget.keyboardType,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
|
@ -56,6 +56,7 @@ class InputDatePickerFormField extends StatefulWidget {
|
|||||||
this.errorInvalidText,
|
this.errorInvalidText,
|
||||||
this.fieldHintText,
|
this.fieldHintText,
|
||||||
this.fieldLabelText,
|
this.fieldLabelText,
|
||||||
|
this.keyboardType,
|
||||||
this.autofocus = false,
|
this.autofocus = false,
|
||||||
}) : assert(firstDate != null),
|
}) : assert(firstDate != null),
|
||||||
assert(lastDate != null),
|
assert(lastDate != null),
|
||||||
@ -125,6 +126,11 @@ class InputDatePickerFormField 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;
|
||||||
|
|
||||||
|
/// The keyboard type of the [TextField].
|
||||||
|
///
|
||||||
|
/// If this is null, it will default to [TextInputType.datetime]
|
||||||
|
final TextInputType? keyboardType;
|
||||||
|
|
||||||
/// {@macro flutter.widgets.editableText.autofocus}
|
/// {@macro flutter.widgets.editableText.autofocus}
|
||||||
final bool autofocus;
|
final bool autofocus;
|
||||||
|
|
||||||
@ -242,7 +248,7 @@ class _InputDatePickerFormFieldState extends State<InputDatePickerFormField> {
|
|||||||
labelText: widget.fieldLabelText ?? localizations.dateInputLabel,
|
labelText: widget.fieldLabelText ?? localizations.dateInputLabel,
|
||||||
),
|
),
|
||||||
validator: _validateDate,
|
validator: _validateDate,
|
||||||
keyboardType: TextInputType.datetime,
|
keyboardType: widget.keyboardType ?? TextInputType.datetime,
|
||||||
onSaved: _handleSaved,
|
onSaved: _handleSaved,
|
||||||
onFieldSubmitted: _handleSubmitted,
|
onFieldSubmitted: _handleSubmitted,
|
||||||
autofocus: widget.autofocus,
|
autofocus: widget.autofocus,
|
||||||
|
@ -26,6 +26,7 @@ void main() {
|
|||||||
String? fieldHintText;
|
String? fieldHintText;
|
||||||
String? fieldLabelText;
|
String? fieldLabelText;
|
||||||
String? helpText;
|
String? helpText;
|
||||||
|
TextInputType? keyboardType;
|
||||||
|
|
||||||
final Finder nextMonthIcon = find.byWidgetPredicate((Widget w) => w is IconButton && (w.tooltip?.startsWith('Next month') ?? false));
|
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));
|
final Finder previousMonthIcon = find.byWidgetPredicate((Widget w) => w is IconButton && (w.tooltip?.startsWith('Previous month') ?? false));
|
||||||
@ -52,6 +53,7 @@ void main() {
|
|||||||
fieldHintText = null;
|
fieldHintText = null;
|
||||||
fieldLabelText = null;
|
fieldLabelText = null;
|
||||||
helpText = null;
|
helpText = null;
|
||||||
|
keyboardType = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<void> prepareDatePicker(
|
Future<void> prepareDatePicker(
|
||||||
@ -94,6 +96,7 @@ void main() {
|
|||||||
fieldHintText: fieldHintText,
|
fieldHintText: fieldHintText,
|
||||||
fieldLabelText: fieldLabelText,
|
fieldLabelText: fieldLabelText,
|
||||||
helpText: helpText,
|
helpText: helpText,
|
||||||
|
keyboardType: keyboardType,
|
||||||
builder: (BuildContext context, Widget? child) {
|
builder: (BuildContext context, Widget? child) {
|
||||||
return Directionality(
|
return Directionality(
|
||||||
textDirection: textDirection,
|
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 {
|
testWidgets('Initial date is the default', (WidgetTester tester) async {
|
||||||
await prepareDatePicker(tester, (Future<DateTime?> date) async {
|
await prepareDatePicker(tester, (Future<DateTime?> date) async {
|
||||||
await tester.tap(find.text('OK'));
|
await tester.tap(find.text('OK'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user