Add onSubmitted
property to SearchBar
(#129365)
Fixes #126551 This PR is to add `onSubmitted` property to `SearchBar`.
This commit is contained in:
parent
042c0366c9
commit
5140b0f0c6
@ -996,6 +996,7 @@ class SearchBar extends StatefulWidget {
|
||||
this.trailing,
|
||||
this.onTap,
|
||||
this.onChanged,
|
||||
this.onSubmitted,
|
||||
this.constraints,
|
||||
this.elevation,
|
||||
this.backgroundColor,
|
||||
@ -1044,6 +1045,10 @@ class SearchBar extends StatefulWidget {
|
||||
/// Invoked upon user input.
|
||||
final ValueChanged<String>? onChanged;
|
||||
|
||||
/// Called when the user indicates that they are done editing the text in the
|
||||
/// field.
|
||||
final ValueChanged<String>? onSubmitted;
|
||||
|
||||
/// Optional size constraints for the search bar.
|
||||
///
|
||||
/// If null, the value of [SearchBarThemeData.constraints] will be used. If
|
||||
@ -1236,6 +1241,7 @@ class _SearchBarState extends State<SearchBar> {
|
||||
child: TextField(
|
||||
focusNode: _focusNode,
|
||||
onChanged: widget.onChanged,
|
||||
onSubmitted: widget.onSubmitted,
|
||||
controller: widget.controller,
|
||||
style: effectiveTextStyle,
|
||||
decoration: InputDecoration(
|
||||
|
@ -270,6 +270,26 @@ void main() {
|
||||
expect(changeCount, 2);
|
||||
});
|
||||
|
||||
testWidgets('SearchBar respects onSubmitted property', (WidgetTester tester) async {
|
||||
String submittedQuery = '';
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Material(
|
||||
child: SearchBar(
|
||||
onSubmitted: (String text) {
|
||||
submittedQuery = text;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.enterText(find.byType(SearchBar), 'query');
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
|
||||
expect(submittedQuery, equals('query'));
|
||||
});
|
||||
|
||||
testWidgets('SearchBar respects constraints property', (WidgetTester tester) async {
|
||||
const BoxConstraints constraints = BoxConstraints(maxWidth: 350.0, minHeight: 80);
|
||||
await tester.pumpWidget(
|
||||
|
Loading…
x
Reference in New Issue
Block a user