diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index ce3b9c4769..6cf5485864 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -827,7 +827,6 @@ class _AppBarState extends State { final bool hasDrawer = scaffold?.hasDrawer ?? false; final bool hasEndDrawer = scaffold?.hasEndDrawer ?? false; - final bool canPop = parentRoute?.canPop ?? false; final bool useCloseButton = parentRoute is PageRoute && parentRoute.fullscreenDialog; final double toolbarHeight = widget.toolbarHeight ?? appBarTheme.toolbarHeight ?? kToolbarHeight; @@ -897,10 +896,7 @@ class _AppBarState extends State { 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(); } } diff --git a/packages/flutter/test/material/app_bar_test.dart b/packages/flutter/test/material/app_bar_test.dart index 387ba51980..d59b46e0a8 100644 --- a/packages/flutter/test/material/app_bar_test.dart +++ b/packages/flutter/test/material/app_bar_test.dart @@ -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;