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 {
this.keyboardType,
this.autofocus = false,
this.acceptEmptyDate = false,
this.focusNode,
}) : initialDate = initialDate != null ? DateUtils.dateOnly(initialDate) : null,
firstDate = DateUtils.dateOnly(firstDate),
lastDate = DateUtils.dateOnly(lastDate) {
......@@ -136,6 +137,9 @@ class InputDatePickerFormField extends StatefulWidget {
/// If true, [errorFormatText] is not shown when the date input field is empty.
final bool acceptEmptyDate;
/// {@macro flutter.widgets.Focus.focusNode}
final FocusNode? focusNode;
@override
State<InputDatePickerFormField> createState() => _InputDatePickerFormFieldState();
}
......@@ -266,6 +270,7 @@ class _InputDatePickerFormFieldState extends State<InputDatePickerFormField> {
onFieldSubmitted: _handleSubmitted,
autofocus: widget.autofocus,
controller: _controller,
focusNode: widget.focusNode,
);
}
}
......@@ -51,6 +51,7 @@ void main() {
ThemeData? theme,
Iterable<LocalizationsDelegate<dynamic>>? localizationsDelegates,
bool acceptEmptyDate = false,
FocusNode? focusNode,
}) {
return MaterialApp(
theme: theme ?? ThemeData.from(colorScheme: const ColorScheme.light()),
......@@ -72,6 +73,7 @@ void main() {
fieldLabelText: fieldLabelText,
autofocus: autofocus,
acceptEmptyDate: acceptEmptyDate,
focusNode: focusNode,
),
),
),
......@@ -378,4 +380,19 @@ void main() {
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