Unverified Commit a4411b55 authored by Pedro Massango's avatar Pedro Massango Committed by GitHub

Add onTap and autocorrect into CupertinoSearchTextField (#79966)

parent f0c97104
...@@ -147,6 +147,9 @@ class CupertinoSearchTextField extends StatefulWidget { ...@@ -147,6 +147,9 @@ class CupertinoSearchTextField extends StatefulWidget {
this.onSuffixTap, this.onSuffixTap,
this.restorationId, this.restorationId,
this.focusNode, this.focusNode,
this.onTap,
this.autocorrect = true,
this.enabled,
}) : assert(padding != null), }) : assert(padding != null),
assert(itemColor != null), assert(itemColor != null),
assert(itemSize != null), assert(itemSize != null),
...@@ -275,6 +278,18 @@ class CupertinoSearchTextField extends StatefulWidget { ...@@ -275,6 +278,18 @@ class CupertinoSearchTextField extends StatefulWidget {
/// {@macro flutter.widgets.Focus.focusNode} /// {@macro flutter.widgets.Focus.focusNode}
final FocusNode? focusNode; final FocusNode? focusNode;
/// {@macro flutter.material.textfield.onTap}
final VoidCallback? onTap;
/// {@macro flutter.widgets.editableText.autocorrect}
final bool autocorrect;
/// Disables the text field when false.
///
/// Text fields in disabled states have a light grey background and don't
/// respond to touch events including the [suffixIcon] and the search button.
final bool? enabled;
@override @override
State<StatefulWidget> createState() => _CupertinoSearchTextFieldState(); State<StatefulWidget> createState() => _CupertinoSearchTextFieldState();
} }
...@@ -393,6 +408,8 @@ class _CupertinoSearchTextFieldState extends State<CupertinoSearchTextField> ...@@ -393,6 +408,8 @@ class _CupertinoSearchTextFieldState extends State<CupertinoSearchTextField>
style: widget.style, style: widget.style,
prefix: prefix, prefix: prefix,
suffix: suffix, suffix: suffix,
onTap: widget.onTap,
enabled: widget.enabled,
suffixMode: widget.suffixMode, suffixMode: widget.suffixMode,
placeholder: placeholder, placeholder: placeholder,
placeholderStyle: placeholderStyle, placeholderStyle: placeholderStyle,
...@@ -400,6 +417,7 @@ class _CupertinoSearchTextFieldState extends State<CupertinoSearchTextField> ...@@ -400,6 +417,7 @@ class _CupertinoSearchTextFieldState extends State<CupertinoSearchTextField>
onChanged: widget.onChanged, onChanged: widget.onChanged,
onSubmitted: widget.onSubmitted, onSubmitted: widget.onSubmitted,
focusNode: widget.focusNode, focusNode: widget.focusNode,
autocorrect: widget.autocorrect,
); );
} }
} }
...@@ -465,4 +465,69 @@ void main() { ...@@ -465,4 +465,69 @@ void main() {
expect(find.text('Text'), findsOneWidget); expect(find.text('Text'), findsOneWidget);
}, },
); );
testWidgets('onTap is properly forwarded to the inner text field',
(WidgetTester tester) async {
int onTapCallCount = 0;
// onTap can be null.
await tester.pumpWidget(
const CupertinoApp(
home: Center(
child: CupertinoSearchTextField(),
),
),
);
// onTap callback is called if not null.
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: CupertinoSearchTextField(
onTap: () {
onTapCallCount++;
},
),
),
),
);
expect(onTapCallCount, 0);
await tester.tap(find.byType(CupertinoTextField));
expect(onTapCallCount, 1);
});
testWidgets('autocorrect is properly forwarded to the inner text field',
(WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(
home: Center(
child: CupertinoSearchTextField(
autocorrect: false,
),
),
),
);
final CupertinoTextField textField = tester.widget(find.byType(CupertinoTextField));
expect(textField.autocorrect, false);
});
testWidgets('enabled is properly forwarded to the inner text field',
(WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(
home: Center(
child: CupertinoSearchTextField(
enabled: false,
),
),
),
);
final CupertinoTextField textField = tester.widget(find.byType(CupertinoTextField));
expect(textField.enabled, false);
});
} }
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