Skip to content

Commit 0b65723

Browse files
authored
Cleans up appbar imply leading logic (#125315)
fixes flutter/flutter#80256
1 parent b00f1c4 commit 0b65723

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

packages/flutter/lib/src/material/app_bar.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,6 @@ class _AppBarState extends State<AppBar> {
827827

828828
final bool hasDrawer = scaffold?.hasDrawer ?? false;
829829
final bool hasEndDrawer = scaffold?.hasEndDrawer ?? false;
830-
final bool canPop = parentRoute?.canPop ?? false;
831830
final bool useCloseButton = parentRoute is PageRoute<dynamic> && parentRoute.fullscreenDialog;
832831

833832
final double toolbarHeight = widget.toolbarHeight ?? appBarTheme.toolbarHeight ?? kToolbarHeight;
@@ -897,10 +896,7 @@ class _AppBarState extends State<AppBar> {
897896
leading = DrawerButton(
898897
style: IconButton.styleFrom(iconSize: overallIconTheme.size ?? 24),
899898
);
900-
// TODO(chunhtai): remove (!hasEndDrawer && canPop) once internal tests
901-
// are migrated.
902-
// https://github.com/flutter/flutter/issues/80256.
903-
} else if ((!hasEndDrawer && canPop) || (parentRoute?.impliesAppBarDismissal ?? false)) {
899+
} else if (parentRoute?.impliesAppBarDismissal ?? false) {
904900
leading = useCloseButton ? const CloseButton() : const BackButton();
905901
}
906902
}

packages/flutter/test/material/app_bar_test.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,6 +3946,33 @@ void main() {
39463946
);
39473947
});
39483948

3949+
testWidgets('Only local entries that imply app bar dismissal will introduce an back button', (WidgetTester tester) async {
3950+
final GlobalKey key = GlobalKey();
3951+
await tester.pumpWidget(
3952+
MaterialApp(
3953+
home: Scaffold(
3954+
key: key,
3955+
appBar: AppBar(),
3956+
),
3957+
),
3958+
);
3959+
expect(find.byType(BackButton), findsNothing);
3960+
3961+
// Push one entry that doesn't imply app bar dismissal.
3962+
ModalRoute.of(key.currentContext!)!.addLocalHistoryEntry(
3963+
LocalHistoryEntry(onRemove: () {}, impliesAppBarDismissal: false),
3964+
);
3965+
await tester.pump();
3966+
expect(find.byType(BackButton), findsNothing);
3967+
3968+
// Push one entry that implies app bar dismissal.
3969+
ModalRoute.of(key.currentContext!)!.addLocalHistoryEntry(
3970+
LocalHistoryEntry(onRemove: () {}),
3971+
);
3972+
await tester.pump();
3973+
expect(find.byType(BackButton), findsOneWidget);
3974+
});
3975+
39493976
testWidgets('AppBar.preferredHeightFor', (WidgetTester tester) async {
39503977
late double preferredHeight;
39513978
late Size preferredSize;

0 commit comments

Comments
 (0)