update SearchDelegate's leading and actions widgets can be null (#80006)
This commit is contained in:
@@ -180,7 +180,7 @@ abstract class SearchDelegate<T> {
|
||||
/// See also:
|
||||
///
|
||||
/// * [AppBar.leading], the intended use for the return value of this method.
|
||||
Widget buildLeading(BuildContext context);
|
||||
Widget? buildLeading(BuildContext context);
|
||||
|
||||
/// Widgets to display after the search query in the [AppBar].
|
||||
///
|
||||
@@ -193,7 +193,7 @@ abstract class SearchDelegate<T> {
|
||||
/// See also:
|
||||
///
|
||||
/// * [AppBar.actions], the intended use for the return value of this method.
|
||||
List<Widget> buildActions(BuildContext context);
|
||||
List<Widget>? buildActions(BuildContext context);
|
||||
|
||||
/// Widget to display across the bottom of the [AppBar].
|
||||
///
|
||||
|
||||
@@ -771,6 +771,48 @@ void main() {
|
||||
expect(textField.style!.color, themeData.textTheme.bodyText1!.color);
|
||||
expect(textField.style!.color, isNot(equals(themeData.primaryColor)));
|
||||
});
|
||||
|
||||
// Regression test for: https://github.com/flutter/flutter/issues/78144
|
||||
testWidgets('`Leading` and `Actions` nullable test', (WidgetTester tester) async {
|
||||
// The search delegate page is displayed with no issues
|
||||
// even with a null return values for [buildLeading] and [buildActions].
|
||||
final _TestEmptySearchDelegate delegate = _TestEmptySearchDelegate(
|
||||
result: 'Result',
|
||||
suggestions: 'Suggestions',
|
||||
);
|
||||
final List<String> selectedResults = <String>[];
|
||||
|
||||
await tester.pumpWidget(TestHomePage(
|
||||
delegate: delegate,
|
||||
results: selectedResults,
|
||||
));
|
||||
|
||||
// We are on the homepage.
|
||||
expect(find.text('HomeBody'), findsOneWidget);
|
||||
expect(find.text('HomeTitle'), findsOneWidget);
|
||||
expect(find.text('Suggestions'), findsNothing);
|
||||
|
||||
// Open the search page.
|
||||
await tester.tap(find.byTooltip('Search'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('HomeBody'), findsNothing);
|
||||
expect(find.text('HomeTitle'), findsNothing);
|
||||
expect(find.text('Suggestions'), findsOneWidget);
|
||||
expect(selectedResults, hasLength(0));
|
||||
|
||||
final TextField textField = tester.widget(find.byType(TextField));
|
||||
expect(textField.focusNode!.hasFocus, isTrue);
|
||||
|
||||
// Close the search page.
|
||||
await tester.tap(find.byTooltip('Close'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('HomeBody'), findsOneWidget);
|
||||
expect(find.text('HomeTitle'), findsOneWidget);
|
||||
expect(find.text('Suggestions'), findsNothing);
|
||||
expect(selectedResults, <String>['Result']);
|
||||
});
|
||||
}
|
||||
|
||||
class TestHomePage extends StatelessWidget {
|
||||
@@ -911,3 +953,48 @@ class _TestSearchDelegate extends SearchDelegate<String> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TestEmptySearchDelegate extends SearchDelegate<String> {
|
||||
_TestEmptySearchDelegate({
|
||||
this.suggestions = 'Suggestions',
|
||||
this.result = 'Result',
|
||||
}) : super();
|
||||
|
||||
final String suggestions;
|
||||
final String result;
|
||||
|
||||
@override
|
||||
Widget? buildLeading(BuildContext context) => null;
|
||||
|
||||
@override
|
||||
List<Widget>? buildActions(BuildContext context) => null;
|
||||
|
||||
@override
|
||||
Widget buildSuggestions(BuildContext context) {
|
||||
return MaterialButton(
|
||||
onPressed: () {
|
||||
showResults(context);
|
||||
},
|
||||
child: Text(suggestions),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildResults(BuildContext context) {
|
||||
return const Text('Results');
|
||||
}
|
||||
|
||||
@override
|
||||
PreferredSizeWidget buildBottom(BuildContext context) {
|
||||
return PreferredSize(
|
||||
preferredSize: const Size.fromHeight(56.0),
|
||||
child: IconButton(
|
||||
tooltip: 'Close',
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () {
|
||||
close(context, result);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user