Unverified Commit c5328650 authored by Veli Bacik's avatar Veli Bacik Committed by GitHub

implemented leadingWidth and automaticallyImplyLeading options (#136165)

Before:
![Screenshot 2023-10-09 at 01 32 33](https://github.com/flutter/flutter/assets/17102578/cb90423c-8d8d-40d5-afd0-5aab23b9930b)

After:

![Screenshot 2023-10-09 at 01 33 01](https://github.com/flutter/flutter/assets/17102578/3ba84243-42b8-4e02-b064-70618e21a305)

![Screenshot 2023-10-09 at 01 32 49](https://github.com/flutter/flutter/assets/17102578/4f311d74-f6a8-4f32-9974-109bd7f55812)

Fixed #136164
parent 178130b1
......@@ -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();
// 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, 1);
expect(rootObserver.pushCount, 2);
expect(localObserver.pushCount, 1);
});
......
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