Cleans up appbar imply leading logic (#125315)
fixes https://github.com/flutter/flutter/issues/80256
This commit is contained in:
parent
b00f1c4599
commit
0b657236ca
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user