implemented leadingWidth and automaticallyImplyLeading options (#136165)
Before:  After:   Fixed #136164
This commit is contained in:
parent
178130b169
commit
c5328650f1
@ -277,8 +277,8 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
|
||||
/// {@template flutter.material.appbar.automaticallyImplyLeading}
|
||||
/// Controls whether we should try to imply the leading widget if null.
|
||||
///
|
||||
/// If true and [leading] is null, automatically try to deduce what the leading
|
||||
/// widget should be. If false and [leading] is null, leading space is given to [title].
|
||||
/// If true and [AppBar.leading] is null, automatically try to deduce what the leading
|
||||
/// widget should be. If false and [AppBar.leading] is null, leading space is given to [AppBar.title].
|
||||
/// If leading widget is not null, this parameter has no effect.
|
||||
/// {@endtemplate}
|
||||
final bool automaticallyImplyLeading;
|
||||
@ -642,9 +642,9 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
|
||||
final double? toolbarHeight;
|
||||
|
||||
/// {@template flutter.material.appbar.leadingWidth}
|
||||
/// Defines the width of [leading] widget.
|
||||
/// Defines the width of [AppBar.leading] widget.
|
||||
///
|
||||
/// By default, the value of [leadingWidth] is 56.0.
|
||||
/// By default, the value of [AppBar.leadingWidth] is 56.0.
|
||||
/// {@endtemplate}
|
||||
final double? leadingWidth;
|
||||
|
||||
|
@ -188,6 +188,12 @@ abstract class SearchDelegate<T> {
|
||||
/// * [AppBar.leading], the intended use for the return value of this method.
|
||||
Widget? buildLeading(BuildContext context);
|
||||
|
||||
/// {@macro flutter.material.appbar.automaticallyImplyLeading}
|
||||
bool? automaticallyImplyLeading;
|
||||
|
||||
/// {@macro flutter.material.appbar.leadingWidth}
|
||||
double? leadingWidth;
|
||||
|
||||
/// Widgets to display after the search query in the [AppBar].
|
||||
///
|
||||
/// If the [query] is not empty, this should typically contain a button to
|
||||
@ -592,6 +598,8 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
|
||||
data: theme,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
leadingWidth: widget.delegate.leadingWidth,
|
||||
automaticallyImplyLeading: widget.delegate.automaticallyImplyLeading ?? true,
|
||||
leading: widget.delegate.buildLeading(context),
|
||||
title: TextField(
|
||||
controller: widget.delegate._queryTextController,
|
||||
|
@ -1025,7 +1025,31 @@ void main() {
|
||||
expect(selectedResults, <String>['Result']);
|
||||
});
|
||||
|
||||
testWidgetsWithLeakTracking('showSearch with useRootNavigator', (WidgetTester tester) async {
|
||||
testWidgets('Leading width size is 16', (WidgetTester tester) async {
|
||||
final _TestSearchDelegate delegate = _TestSearchDelegate();
|
||||
final List<String> selectedResults = <String>[];
|
||||
delegate.leadingWidth = 16;
|
||||
|
||||
await tester.pumpWidget(TestHomePage(
|
||||
delegate: delegate,
|
||||
results: selectedResults,
|
||||
));
|
||||
|
||||
// Open the search page with check leading width smaller than 16.
|
||||
await tester.tap(find.byTooltip('Search'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tapAt(const Offset(16, 16));
|
||||
expect(find.text('Suggestions'), findsOneWidget);
|
||||
final Finder appBarFinder = find.byType(AppBar);
|
||||
final AppBar appBar = tester.widget<AppBar>(appBarFinder);
|
||||
expect(appBar.leadingWidth, 16);
|
||||
await tester.tapAt(const Offset(8, 16));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Suggestions'), findsNothing);
|
||||
expect(find.text('HomeBody'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgetsWithLeakTracking('showSearch with useRootNavigator', (WidgetTester tester) async {
|
||||
final _MyNavigatorObserver rootObserver = _MyNavigatorObserver();
|
||||
final _MyNavigatorObserver localObserver = _MyNavigatorObserver();
|
||||
|
||||
@ -1066,20 +1090,33 @@ void main() {
|
||||
expect(rootObserver.pushCount, 0);
|
||||
expect(localObserver.pushCount, 0);
|
||||
|
||||
// showSearch normal and back
|
||||
// showSearch normal and back.
|
||||
await tester.tap(find.text('showSearchLocalNavigator'));
|
||||
await tester.pumpAndSettle();
|
||||
final Finder backButtonFinder = find.byType(BackButton);
|
||||
expect(backButtonFinder, findsWidgets);
|
||||
await tester.tap(find.byTooltip('Close'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(rootObserver.pushCount, 0);
|
||||
expect(localObserver.pushCount, 1);
|
||||
|
||||
// showSearch with rootNavigator
|
||||
// showSearch with rootNavigator.
|
||||
await tester.tap(find.text('showSearchRootNavigator'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip('Close'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(rootObserver.pushCount, 1);
|
||||
|
||||
// showSearch without back button.
|
||||
delegate.automaticallyImplyLeading = false;
|
||||
await tester.tap(find.text('showSearchRootNavigator'));
|
||||
await tester.pumpAndSettle();
|
||||
final Finder appBarFinder = find.byType(AppBar);
|
||||
final AppBar appBar = tester.widget<AppBar>(appBarFinder);
|
||||
expect(appBar.automaticallyImplyLeading, false);
|
||||
expect(find.byTooltip('Back'), findsNothing);
|
||||
await tester.tap(find.byTooltip('Close'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(rootObserver.pushCount, 2);
|
||||
expect(localObserver.pushCount, 1);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user