Skip to content

Commit

Permalink
Cleans up appbar imply leading logic (flutter#125315)
Browse files Browse the repository at this point in the history
  • Loading branch information
chunhtai authored May 4, 2023
1 parent b00f1c4 commit 0b65723
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
6 changes: 1 addition & 5 deletions packages/flutter/lib/src/material/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@ class _AppBarState extends State<AppBar> {

final bool hasDrawer = scaffold?.hasDrawer ?? false;
final bool hasEndDrawer = scaffold?.hasEndDrawer ?? false;
final bool canPop = parentRoute?.canPop ?? false;
final bool useCloseButton = parentRoute is PageRoute<dynamic> && parentRoute.fullscreenDialog;

final double toolbarHeight = widget.toolbarHeight ?? appBarTheme.toolbarHeight ?? kToolbarHeight;
Expand Down Expand Up @@ -897,10 +896,7 @@ class _AppBarState extends State<AppBar> {
leading = DrawerButton(
style: IconButton.styleFrom(iconSize: overallIconTheme.size ?? 24),
);
// TODO(chunhtai): remove (!hasEndDrawer && canPop) once internal tests
// are migrated.
// https://github.com/flutter/flutter/issues/80256.
} else if ((!hasEndDrawer && canPop) || (parentRoute?.impliesAppBarDismissal ?? false)) {
} else if (parentRoute?.impliesAppBarDismissal ?? false) {
leading = useCloseButton ? const CloseButton() : const BackButton();
}
}
Expand Down
27 changes: 27 additions & 0 deletions packages/flutter/test/material/app_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3946,6 +3946,33 @@ void main() {
);
});

testWidgets('Only local entries that imply app bar dismissal will introduce an back button', (WidgetTester tester) async {
final GlobalKey key = GlobalKey();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
key: key,
appBar: AppBar(),
),
),
);
expect(find.byType(BackButton), findsNothing);

// Push one entry that doesn't imply app bar dismissal.
ModalRoute.of(key.currentContext!)!.addLocalHistoryEntry(
LocalHistoryEntry(onRemove: () {}, impliesAppBarDismissal: false),
);
await tester.pump();
expect(find.byType(BackButton), findsNothing);

// Push one entry that implies app bar dismissal.
ModalRoute.of(key.currentContext!)!.addLocalHistoryEntry(
LocalHistoryEntry(onRemove: () {}),
);
await tester.pump();
expect(find.byType(BackButton), findsOneWidget);
});

testWidgets('AppBar.preferredHeightFor', (WidgetTester tester) async {
late double preferredHeight;
late Size preferredSize;
Expand Down

0 comments on commit 0b65723

Please sign in to comment.