File tree 2 files changed +26
-0
lines changed 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -996,6 +996,7 @@ class SearchBar extends StatefulWidget {
996
996
this .trailing,
997
997
this .onTap,
998
998
this .onChanged,
999
+ this .onSubmitted,
999
1000
this .constraints,
1000
1001
this .elevation,
1001
1002
this .backgroundColor,
@@ -1044,6 +1045,10 @@ class SearchBar extends StatefulWidget {
1044
1045
/// Invoked upon user input.
1045
1046
final ValueChanged <String >? onChanged;
1046
1047
1048
+ /// Called when the user indicates that they are done editing the text in the
1049
+ /// field.
1050
+ final ValueChanged <String >? onSubmitted;
1051
+
1047
1052
/// Optional size constraints for the search bar.
1048
1053
///
1049
1054
/// If null, the value of [SearchBarThemeData.constraints] will be used. If
@@ -1236,6 +1241,7 @@ class _SearchBarState extends State<SearchBar> {
1236
1241
child: TextField (
1237
1242
focusNode: _focusNode,
1238
1243
onChanged: widget.onChanged,
1244
+ onSubmitted: widget.onSubmitted,
1239
1245
controller: widget.controller,
1240
1246
style: effectiveTextStyle,
1241
1247
decoration: InputDecoration (
Original file line number Diff line number Diff line change @@ -270,6 +270,26 @@ void main() {
270
270
expect (changeCount, 2 );
271
271
});
272
272
273
+ testWidgets ('SearchBar respects onSubmitted property' , (WidgetTester tester) async {
274
+ String submittedQuery = '' ;
275
+ await tester.pumpWidget (
276
+ MaterialApp (
277
+ home: Material (
278
+ child: SearchBar (
279
+ onSubmitted: (String text) {
280
+ submittedQuery = text;
281
+ },
282
+ ),
283
+ ),
284
+ ),
285
+ );
286
+
287
+ await tester.enterText (find.byType (SearchBar ), 'query' );
288
+ await tester.testTextInput.receiveAction (TextInputAction .done);
289
+
290
+ expect (submittedQuery, equals ('query' ));
291
+ });
292
+
273
293
testWidgets ('SearchBar respects constraints property' , (WidgetTester tester) async {
274
294
const BoxConstraints constraints = BoxConstraints (maxWidth: 350.0 , minHeight: 80 );
275
295
await tester.pumpWidget (
You can’t perform that action at this time.
0 commit comments