Unverified Commit 5140b0f0 authored by Qun Cheng's avatar Qun Cheng Committed by GitHub

Add `onSubmitted` property to `SearchBar` (#129365)

Fixes #126551

This PR is to add `onSubmitted` property to `SearchBar`.
parent 042c0366
......@@ -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(
......
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