Unverified Commit 0b657236 authored by chunhtai's avatar chunhtai Committed by GitHub

Cleans up appbar imply leading logic (#125315)

fixes https://github.com/flutter/flutter/issues/80256
parent b00f1c45
......@@ -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;
......@@ -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();
}
}
......
......@@ -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;
......
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