Add autocorrect and enableSuggestions to SearchDelegate (#154932)
Add `autocorrect` and `enableSuggestions` to `SearchDelegate`, so that autocompletion can be disabled in search. *List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.* * https://github.com/flutter/flutter/issues/98241 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
This commit is contained in:
parent
c8c2f4651a
commit
91eb8d226d
@ -155,6 +155,8 @@ abstract class SearchDelegate<T> {
|
|||||||
this.searchFieldDecorationTheme,
|
this.searchFieldDecorationTheme,
|
||||||
this.keyboardType,
|
this.keyboardType,
|
||||||
this.textInputAction = TextInputAction.search,
|
this.textInputAction = TextInputAction.search,
|
||||||
|
this.autocorrect = true,
|
||||||
|
this.enableSuggestions = true,
|
||||||
}) : assert(searchFieldStyle == null || searchFieldDecorationTheme == null);
|
}) : assert(searchFieldStyle == null || searchFieldDecorationTheme == null);
|
||||||
|
|
||||||
/// Suggestions shown in the body of the search page while the user types a
|
/// Suggestions shown in the body of the search page while the user types a
|
||||||
@ -365,6 +367,12 @@ abstract class SearchDelegate<T> {
|
|||||||
/// Defaults to the default value specified in [TextField].
|
/// Defaults to the default value specified in [TextField].
|
||||||
final TextInputType? keyboardType;
|
final TextInputType? keyboardType;
|
||||||
|
|
||||||
|
/// {@macro flutter.widgets.editableText.autocorrect}
|
||||||
|
final bool autocorrect;
|
||||||
|
|
||||||
|
/// {@macro flutter.services.TextInputConfiguration.enableSuggestions}
|
||||||
|
final bool enableSuggestions;
|
||||||
|
|
||||||
/// The text input action configuring the soft keyboard to a particular action
|
/// The text input action configuring the soft keyboard to a particular action
|
||||||
/// button.
|
/// button.
|
||||||
///
|
///
|
||||||
@ -619,6 +627,8 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
|
|||||||
focusNode: focusNode,
|
focusNode: focusNode,
|
||||||
style: widget.delegate.searchFieldStyle ?? theme.textTheme.titleLarge,
|
style: widget.delegate.searchFieldStyle ?? theme.textTheme.titleLarge,
|
||||||
textInputAction: widget.delegate.textInputAction,
|
textInputAction: widget.delegate.textInputAction,
|
||||||
|
autocorrect: widget.delegate.autocorrect,
|
||||||
|
enableSuggestions: widget.delegate.enableSuggestions,
|
||||||
keyboardType: widget.delegate.keyboardType,
|
keyboardType: widget.delegate.keyboardType,
|
||||||
onSubmitted: (String _) => widget.delegate.showResults(context),
|
onSubmitted: (String _) => widget.delegate.showResults(context),
|
||||||
decoration: InputDecoration(hintText: searchFieldLabel),
|
decoration: InputDecoration(hintText: searchFieldLabel),
|
||||||
|
@ -579,10 +579,50 @@ void main() {
|
|||||||
expect(hintText.style?.fontSize, delegate.searchFieldStyle?.fontSize);
|
expect(hintText.style?.fontSize, delegate.searchFieldStyle?.fontSize);
|
||||||
expect(textField.style?.color, delegate.searchFieldStyle?.color);
|
expect(textField.style?.color, delegate.searchFieldStyle?.color);
|
||||||
expect(textField.style?.fontSize, delegate.searchFieldStyle?.fontSize);
|
expect(textField.style?.fontSize, delegate.searchFieldStyle?.fontSize);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('keyboard show search button by default', (WidgetTester tester) async {
|
testWidgets('Default autocorrect and enableSuggestions value', (WidgetTester tester) async {
|
||||||
|
final _TestSearchDelegate delegate = _TestSearchDelegate();
|
||||||
|
addTearDown(() => delegate.dispose());
|
||||||
|
|
||||||
|
await tester.pumpWidget(TestHomePage(delegate: delegate));
|
||||||
|
await tester.tap(find.byTooltip('Search'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final TextField textField = tester.widget<TextField>(find.byType(TextField));
|
||||||
|
|
||||||
|
expect(textField.autocorrect, isTrue);
|
||||||
|
expect(textField.enableSuggestions, isTrue);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Custom autocorrect value', (WidgetTester tester) async {
|
||||||
|
final _TestSearchDelegate delegate = _TestSearchDelegate(autocorrect: false);
|
||||||
|
addTearDown(() => delegate.dispose());
|
||||||
|
|
||||||
|
await tester.pumpWidget(TestHomePage(delegate: delegate));
|
||||||
|
await tester.tap(find.byTooltip('Search'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final TextField textField = tester.widget<TextField>(find.byType(TextField));
|
||||||
|
|
||||||
|
expect(textField.autocorrect, isFalse);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Custom enableSuggestions value', (WidgetTester tester) async {
|
||||||
|
final _TestSearchDelegate delegate = _TestSearchDelegate(enableSuggestions: false);
|
||||||
|
addTearDown(() => delegate.dispose());
|
||||||
|
|
||||||
|
await tester.pumpWidget(TestHomePage(delegate: delegate));
|
||||||
|
await tester.tap(find.byTooltip('Search'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final TextField textField = tester.widget<TextField>(find.byType(TextField));
|
||||||
|
|
||||||
|
expect(textField.enableSuggestions, isFalse);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('keyboard show search button by default',
|
||||||
|
(WidgetTester tester) async {
|
||||||
final _TestSearchDelegate delegate = _TestSearchDelegate();
|
final _TestSearchDelegate delegate = _TestSearchDelegate();
|
||||||
addTearDown(() => delegate.dispose());
|
addTearDown(() => delegate.dispose());
|
||||||
|
|
||||||
@ -1299,6 +1339,8 @@ class _TestSearchDelegate extends SearchDelegate<String> {
|
|||||||
super.searchFieldStyle,
|
super.searchFieldStyle,
|
||||||
String? searchHint,
|
String? searchHint,
|
||||||
super.textInputAction,
|
super.textInputAction,
|
||||||
|
super.autocorrect,
|
||||||
|
super.enableSuggestions,
|
||||||
}) : super(
|
}) : super(
|
||||||
searchFieldLabel: searchHint,
|
searchFieldLabel: searchHint,
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user