Unverified Commit 2de1af40 authored by Tirth's avatar Tirth Committed by GitHub

Add `InputDatePickerFormField.focusNode` prop (#136673)

Adds `focusNode` prop to `InputDatePickerFormField` widget.

Fixes #105881
parent aea56211
...@@ -57,6 +57,7 @@ class InputDatePickerFormField extends StatefulWidget { ...@@ -57,6 +57,7 @@ class InputDatePickerFormField extends StatefulWidget {
this.keyboardType, this.keyboardType,
this.autofocus = false, this.autofocus = false,
this.acceptEmptyDate = false, this.acceptEmptyDate = false,
this.focusNode,
}) : initialDate = initialDate != null ? DateUtils.dateOnly(initialDate) : null, }) : initialDate = initialDate != null ? DateUtils.dateOnly(initialDate) : null,
firstDate = DateUtils.dateOnly(firstDate), firstDate = DateUtils.dateOnly(firstDate),
lastDate = DateUtils.dateOnly(lastDate) { lastDate = DateUtils.dateOnly(lastDate) {
...@@ -136,6 +137,9 @@ class InputDatePickerFormField extends StatefulWidget { ...@@ -136,6 +137,9 @@ class InputDatePickerFormField extends StatefulWidget {
/// If true, [errorFormatText] is not shown when the date input field is empty. /// If true, [errorFormatText] is not shown when the date input field is empty.
final bool acceptEmptyDate; final bool acceptEmptyDate;
/// {@macro flutter.widgets.Focus.focusNode}
final FocusNode? focusNode;
@override @override
State<InputDatePickerFormField> createState() => _InputDatePickerFormFieldState(); State<InputDatePickerFormField> createState() => _InputDatePickerFormFieldState();
} }
...@@ -266,6 +270,7 @@ class _InputDatePickerFormFieldState extends State<InputDatePickerFormField> { ...@@ -266,6 +270,7 @@ class _InputDatePickerFormFieldState extends State<InputDatePickerFormField> {
onFieldSubmitted: _handleSubmitted, onFieldSubmitted: _handleSubmitted,
autofocus: widget.autofocus, autofocus: widget.autofocus,
controller: _controller, controller: _controller,
focusNode: widget.focusNode,
); );
} }
} }
...@@ -51,6 +51,7 @@ void main() { ...@@ -51,6 +51,7 @@ void main() {
ThemeData? theme, ThemeData? theme,
Iterable<LocalizationsDelegate<dynamic>>? localizationsDelegates, Iterable<LocalizationsDelegate<dynamic>>? localizationsDelegates,
bool acceptEmptyDate = false, bool acceptEmptyDate = false,
FocusNode? focusNode,
}) { }) {
return MaterialApp( return MaterialApp(
theme: theme ?? ThemeData.from(colorScheme: const ColorScheme.light()), theme: theme ?? ThemeData.from(colorScheme: const ColorScheme.light()),
...@@ -72,6 +73,7 @@ void main() { ...@@ -72,6 +73,7 @@ void main() {
fieldLabelText: fieldLabelText, fieldLabelText: fieldLabelText,
autofocus: autofocus, autofocus: autofocus,
acceptEmptyDate: acceptEmptyDate, acceptEmptyDate: acceptEmptyDate,
focusNode: focusNode,
), ),
), ),
), ),
...@@ -378,4 +380,19 @@ void main() { ...@@ -378,4 +380,19 @@ void main() {
expect(find.text(errorFormatText), findsOneWidget); expect(find.text(errorFormatText), findsOneWidget);
}); });
}); });
testWidgets('FocusNode can request focus', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode();
await tester.pumpWidget(inputDatePickerField(
focusNode: focusNode,
));
expect((tester.widget(find.byType(TextField)) as TextField).focusNode, focusNode);
expect(focusNode.hasFocus, isFalse);
focusNode.requestFocus();
await tester.pumpAndSettle();
expect(focusNode.hasFocus, isTrue);
focusNode.unfocus();
await tester.pumpAndSettle();
expect(focusNode.hasFocus, isFalse);
});
} }
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