Skip to content

Commit e16dc44

Browse files
authored
Revert "Fix Backbutton is not displayed when there is a endDrawer (#101869)" (#101998)
This reverts commit e2d1206.
1 parent ec8289c commit e16dc44

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -807,9 +807,9 @@ class _AppBarState extends State<AppBar> {
807807

808808
final bool hasDrawer = scaffold?.hasDrawer ?? false;
809809
final bool hasEndDrawer = scaffold?.hasEndDrawer ?? false;
810+
final bool canPop = parentRoute?.canPop ?? false;
810811
final bool useCloseButton = parentRoute is PageRoute<dynamic> && parentRoute.fullscreenDialog;
811-
final bool requiresAppBarDismiss = scaffold?.requiresAppBarDismiss ?? false;
812-
final bool hasActiveRouteBelow = parentRoute?.hasActiveRouteBelow ?? false;
812+
813813
final double toolbarHeight = widget.toolbarHeight ?? appBarTheme.toolbarHeight ?? kToolbarHeight;
814814
final bool backwardsCompatibility = widget.backwardsCompatibility ?? appBarTheme.backwardsCompatibility ?? false;
815815

@@ -880,7 +880,7 @@ class _AppBarState extends State<AppBar> {
880880
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
881881
);
882882
} else {
883-
if (hasActiveRouteBelow || requiresAppBarDismiss)
883+
if (!hasEndDrawer && canPop)
884884
leading = useCloseButton ? const CloseButton() : const BackButton();
885885
}
886886
}

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,20 +1917,13 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
19171917

19181918
/// Whether this scaffold has a non-null [Scaffold.appBar].
19191919
bool get hasAppBar => widget.appBar != null;
1920-
19211920
/// Whether this scaffold has a non-null [Scaffold.drawer].
19221921
bool get hasDrawer => widget.drawer != null;
1923-
19241922
/// Whether this scaffold has a non-null [Scaffold.endDrawer].
19251923
bool get hasEndDrawer => widget.endDrawer != null;
1926-
19271924
/// Whether this scaffold has a non-null [Scaffold.floatingActionButton].
19281925
bool get hasFloatingActionButton => widget.floatingActionButton != null;
19291926

1930-
/// Whether this scaffold requires [Scaffold.appBar] to automatically add
1931-
/// dismiss button.
1932-
bool get requiresAppBarDismiss => _persistentSheetHistoryEntry != null;
1933-
19341927
double? _appBarMaxHeight;
19351928
/// The max height the [Scaffold.appBar] uses.
19361929
///
@@ -2058,28 +2051,28 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
20582051
PersistentBottomSheetController<dynamic>? _currentBottomSheet;
20592052
final GlobalKey _currentBottomSheetKey = GlobalKey();
20602053

2061-
LocalHistoryEntry? _persistentSheetHistoryEntry;
20622054
void _maybeBuildPersistentBottomSheet() {
20632055
if (widget.bottomSheet != null && _currentBottomSheet == null) {
20642056
// The new _currentBottomSheet is not a local history entry so a "back" button
20652057
// will not be added to the Scaffold's appbar and the bottom sheet will not
20662058
// support drag or swipe to dismiss.
20672059
final AnimationController animationController = BottomSheet.createAnimationController(this)..value = 1.0;
2060+
LocalHistoryEntry? persistentSheetHistoryEntry;
20682061
bool _persistentBottomSheetExtentChanged(DraggableScrollableNotification notification) {
20692062
if (notification.extent > notification.initialExtent) {
2070-
if (_persistentSheetHistoryEntry == null) {
2071-
_persistentSheetHistoryEntry = LocalHistoryEntry(onRemove: () {
2063+
if (persistentSheetHistoryEntry == null) {
2064+
persistentSheetHistoryEntry = LocalHistoryEntry(onRemove: () {
20722065
if (notification.extent > notification.initialExtent) {
20732066
DraggableScrollableActuator.reset(notification.context);
20742067
}
20752068
showBodyScrim(false, 0.0);
20762069
_floatingActionButtonVisibilityValue = 1.0;
2077-
_persistentSheetHistoryEntry = null;
2070+
persistentSheetHistoryEntry = null;
20782071
});
2079-
ModalRoute.of(context)!.addLocalHistoryEntry(_persistentSheetHistoryEntry!);
2072+
ModalRoute.of(context)!.addLocalHistoryEntry(persistentSheetHistoryEntry!);
20802073
}
2081-
} else if (_persistentSheetHistoryEntry != null) {
2082-
ModalRoute.of(context)!.removeLocalHistoryEntry(_persistentSheetHistoryEntry!);
2074+
} else if (persistentSheetHistoryEntry != null) {
2075+
ModalRoute.of(context)!.removeLocalHistoryEntry(persistentSheetHistoryEntry!);
20832076
}
20842077
return false;
20852078
}

packages/flutter/lib/src/widgets/navigator.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ abstract class Route<T> {
486486
}
487487

488488
/// Whether there is at least one active route underneath this route.
489+
@protected
489490
bool get hasActiveRouteBelow {
490491
if (_navigator == null)
491492
return false;

0 commit comments

Comments
 (0)