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 { ...@@ -277,8 +277,8 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// {@template flutter.material.appbar.automaticallyImplyLeading} /// {@template flutter.material.appbar.automaticallyImplyLeading}
/// Controls whether we should try to imply the leading widget if null. /// 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 /// If true and [AppBar.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]. /// 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. /// If leading widget is not null, this parameter has no effect.
/// {@endtemplate} /// {@endtemplate}
final bool automaticallyImplyLeading; final bool automaticallyImplyLeading;
...@@ -642,9 +642,9 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget { ...@@ -642,9 +642,9 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
final double? toolbarHeight; final double? toolbarHeight;
/// {@template flutter.material.appbar.leadingWidth} /// {@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} /// {@endtemplate}
final double? leadingWidth; final double? leadingWidth;
......
...@@ -188,6 +188,12 @@ abstract class SearchDelegate<T> { ...@@ -188,6 +188,12 @@ abstract class SearchDelegate<T> {
/// * [AppBar.leading], the intended use for the return value of this method. /// * [AppBar.leading], the intended use for the return value of this method.
Widget? buildLeading(BuildContext context); 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]. /// Widgets to display after the search query in the [AppBar].
/// ///
/// If the [query] is not empty, this should typically contain a button to /// If the [query] is not empty, this should typically contain a button to
...@@ -592,6 +598,8 @@ class _SearchPageState<T> extends State<_SearchPage<T>> { ...@@ -592,6 +598,8 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
data: theme, data: theme,
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
leadingWidth: widget.delegate.leadingWidth,
automaticallyImplyLeading: widget.delegate.automaticallyImplyLeading ?? true,
leading: widget.delegate.buildLeading(context), leading: widget.delegate.buildLeading(context),
title: TextField( title: TextField(
controller: widget.delegate._queryTextController, controller: widget.delegate._queryTextController,
......
...@@ -1025,6 +1025,30 @@ void main() { ...@@ -1025,6 +1025,30 @@ void main() {
expect(selectedResults, <String>['Result']); expect(selectedResults, <String>['Result']);
}); });
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 { testWidgetsWithLeakTracking('showSearch with useRootNavigator', (WidgetTester tester) async {
final _MyNavigatorObserver rootObserver = _MyNavigatorObserver(); final _MyNavigatorObserver rootObserver = _MyNavigatorObserver();
final _MyNavigatorObserver localObserver = _MyNavigatorObserver(); final _MyNavigatorObserver localObserver = _MyNavigatorObserver();
...@@ -1066,20 +1090,33 @@ void main() { ...@@ -1066,20 +1090,33 @@ void main() {
expect(rootObserver.pushCount, 0); expect(rootObserver.pushCount, 0);
expect(localObserver.pushCount, 0); expect(localObserver.pushCount, 0);
// showSearch normal and back // showSearch normal and back.
await tester.tap(find.text('showSearchLocalNavigator')); await tester.tap(find.text('showSearchLocalNavigator'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final Finder backButtonFinder = find.byType(BackButton);
expect(backButtonFinder, findsWidgets);
await tester.tap(find.byTooltip('Close')); await tester.tap(find.byTooltip('Close'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(rootObserver.pushCount, 0); expect(rootObserver.pushCount, 0);
expect(localObserver.pushCount, 1); 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.tap(find.text('showSearchRootNavigator'));
await tester.pumpAndSettle(); 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.tap(find.byTooltip('Close'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(rootObserver.pushCount, 1); expect(rootObserver.pushCount, 2);
expect(localObserver.pushCount, 1); 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