Skip to content

Commit a4a8e73

Browse files
author
Casey Hillers
authored
Revert "Fix Backbutton is not displayed when there is a endDrawer (flutter#102093)" (flutter#104039)
This reverts commit f8f4387.
1 parent 6eb65b3 commit a4a8e73

File tree

4 files changed

+11
-83
lines changed

4 files changed

+11
-83
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ class _AppBarState extends State<AppBar> {
862862

863863
final bool hasDrawer = scaffold?.hasDrawer ?? false;
864864
final bool hasEndDrawer = scaffold?.hasEndDrawer ?? false;
865+
final bool canPop = parentRoute?.canPop ?? false;
865866
final bool useCloseButton = parentRoute is PageRoute<dynamic> && parentRoute.fullscreenDialog;
866867

867868
final double toolbarHeight = widget.toolbarHeight ?? appBarTheme.toolbarHeight ?? kToolbarHeight;
@@ -947,8 +948,9 @@ class _AppBarState extends State<AppBar> {
947948
onPressed: _handleDrawerButton,
948949
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
949950
);
950-
} else if (parentRoute?.impliesAppBarDismissal ?? false) {
951-
leading = useCloseButton ? const CloseButton() : const BackButton();
951+
} else {
952+
if (!hasEndDrawer && canPop)
953+
leading = useCloseButton ? const CloseButton() : const BackButton();
952954
}
953955
}
954956
if (leading != null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
401401
if (_historyEntry == null) {
402402
final ModalRoute<dynamic>? route = ModalRoute.of(context);
403403
if (route != null) {
404-
_historyEntry = LocalHistoryEntry(onRemove: _handleHistoryEntryRemoved, impliesAppBarDismissal: false);
404+
_historyEntry = LocalHistoryEntry(onRemove: _handleHistoryEntryRemoved);
405405
route.addLocalHistoryEntry(_historyEntry!);
406406
FocusScope.of(context).setFirstFocus(_focusScopeNode);
407407
}

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

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -455,21 +455,13 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
455455
/// An entry in the history of a [LocalHistoryRoute].
456456
class LocalHistoryEntry {
457457
/// Creates an entry in the history of a [LocalHistoryRoute].
458-
///
459-
/// The [impliesAppBarDismissal] defaults to true if not provided.
460-
LocalHistoryEntry({ this.onRemove, this.impliesAppBarDismissal = true });
458+
LocalHistoryEntry({ this.onRemove });
461459

462460
/// Called when this entry is removed from the history of its associated [LocalHistoryRoute].
463461
final VoidCallback? onRemove;
464462

465463
LocalHistoryRoute<dynamic>? _owner;
466464

467-
/// Whether an [AppBar] in the route this entry belongs to should
468-
/// automatically add a back button or close button.
469-
///
470-
/// Defaults to true.
471-
final bool impliesAppBarDismissal;
472-
473465
/// Remove this entry from the history of its associated [LocalHistoryRoute].
474466
void remove() {
475467
_owner?.removeLocalHistoryEntry(this);
@@ -490,7 +482,7 @@ class LocalHistoryEntry {
490482
/// is removed from the list and its [LocalHistoryEntry.onRemove] is called.
491483
mixin LocalHistoryRoute<T> on Route<T> {
492484
List<LocalHistoryEntry>? _localHistory;
493-
int _entriesImpliesAppBarDismissal = 0;
485+
494486
/// Adds a local history entry to this route.
495487
///
496488
/// When asked to pop, if this route has any local history entries, this route
@@ -628,12 +620,7 @@ mixin LocalHistoryRoute<T> on Route<T> {
628620
_localHistory ??= <LocalHistoryEntry>[];
629621
final bool wasEmpty = _localHistory!.isEmpty;
630622
_localHistory!.add(entry);
631-
bool internalStateChanged = false;
632-
if (entry.impliesAppBarDismissal) {
633-
internalStateChanged = _entriesImpliesAppBarDismissal == 0;
634-
_entriesImpliesAppBarDismissal += 1;
635-
}
636-
if (wasEmpty || internalStateChanged)
623+
if (wasEmpty)
637624
changedInternalState();
638625
}
639626

@@ -645,15 +632,10 @@ mixin LocalHistoryRoute<T> on Route<T> {
645632
assert(entry != null);
646633
assert(entry._owner == this);
647634
assert(_localHistory!.contains(entry));
648-
bool internalStateChanged = false;
649-
if (_localHistory!.remove(entry) && entry.impliesAppBarDismissal) {
650-
_entriesImpliesAppBarDismissal -= 1;
651-
internalStateChanged = _entriesImpliesAppBarDismissal == 0;
652-
}
635+
_localHistory!.remove(entry);
653636
entry._owner = null;
654637
entry._notifyRemoved();
655-
if (_localHistory!.isEmpty || internalStateChanged) {
656-
assert(_entriesImpliesAppBarDismissal == 0);
638+
if (_localHistory!.isEmpty) {
657639
if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.persistentCallbacks) {
658640
// The local history might be removed as a result of disposing inactive
659641
// elements during finalizeTree. The state is locked at this moment, and
@@ -681,12 +663,7 @@ mixin LocalHistoryRoute<T> on Route<T> {
681663
assert(entry._owner == this);
682664
entry._owner = null;
683665
entry._notifyRemoved();
684-
bool internalStateChanged = false;
685-
if (entry.impliesAppBarDismissal) {
686-
_entriesImpliesAppBarDismissal -= 1;
687-
internalStateChanged = _entriesImpliesAppBarDismissal == 0;
688-
}
689-
if (_localHistory!.isEmpty || internalStateChanged)
666+
if (_localHistory!.isEmpty)
690667
changedInternalState();
691668
return false;
692669
}
@@ -720,7 +697,6 @@ class _ModalScopeStatus extends InheritedWidget {
720697
const _ModalScopeStatus({
721698
required this.isCurrent,
722699
required this.canPop,
723-
required this.impliesAppBarDismissal,
724700
required this.route,
725701
required super.child,
726702
}) : assert(isCurrent != null),
@@ -730,14 +706,12 @@ class _ModalScopeStatus extends InheritedWidget {
730706

731707
final bool isCurrent;
732708
final bool canPop;
733-
final bool impliesAppBarDismissal;
734709
final Route<dynamic> route;
735710

736711
@override
737712
bool updateShouldNotify(_ModalScopeStatus old) {
738713
return isCurrent != old.isCurrent ||
739714
canPop != old.canPop ||
740-
impliesAppBarDismissal != old.impliesAppBarDismissal ||
741715
route != old.route;
742716
}
743717

@@ -746,7 +720,6 @@ class _ModalScopeStatus extends InheritedWidget {
746720
super.debugFillProperties(description);
747721
description.add(FlagProperty('isCurrent', value: isCurrent, ifTrue: 'active', ifFalse: 'inactive'));
748722
description.add(FlagProperty('canPop', value: canPop, ifTrue: 'can pop'));
749-
description.add(FlagProperty('impliesAppBarDismissal', value: impliesAppBarDismissal, ifTrue: 'implies app bar dismissal'));
750723
}
751724
}
752725

@@ -849,7 +822,6 @@ class _ModalScopeState<T> extends State<_ModalScope<T>> {
849822
route: widget.route,
850823
isCurrent: widget.route.isCurrent, // _routeSetState is called if this updates
851824
canPop: widget.route.canPop, // _routeSetState is called if this updates
852-
impliesAppBarDismissal: widget.route.impliesAppBarDismissal,
853825
child: Offstage(
854826
offstage: widget.route.offstage, // _routeSetState is called if this updates
855827
child: PageStorage(
@@ -1589,14 +1561,6 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
15891561
/// notified.
15901562
bool get canPop => hasActiveRouteBelow || willHandlePopInternally;
15911563

1592-
/// Whether an [AppBar] in the route should automatically add a back button or
1593-
/// close button.
1594-
///
1595-
/// This getter returns true if there is at least one active route below it,
1596-
/// or there is at least one [LocalHistoryEntry] with `impliesAppBarDismissal`
1597-
/// set to true
1598-
bool get impliesAppBarDismissal => hasActiveRouteBelow || _entriesImpliesAppBarDismissal > 0;
1599-
16001564
// Internals
16011565

16021566
final GlobalKey<_ModalScopeState<T>> _scopeKey = GlobalKey<_ModalScopeState<T>>();

packages/flutter/test/material/app_bar_test.dart

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3074,44 +3074,6 @@ void main() {
30743074
});
30753075
});
30763076

3077-
// Regression test for https://github.com/flutter/flutter/issues/80256
3078-
testWidgets('The second page should have a back button even it has a end drawer', (WidgetTester tester) async {
3079-
final Page<void> page1 = MaterialPage<void>(
3080-
key: const ValueKey<String>('1'),
3081-
child: Scaffold(
3082-
key: const ValueKey<String>('1'),
3083-
appBar: AppBar(),
3084-
endDrawer: const Drawer(),
3085-
)
3086-
);
3087-
final Page<void> page2 = MaterialPage<void>(
3088-
key: const ValueKey<String>('2'),
3089-
child: Scaffold(
3090-
key: const ValueKey<String>('2'),
3091-
appBar: AppBar(),
3092-
endDrawer: const Drawer(),
3093-
)
3094-
);
3095-
final List<Page<void>> pages = <Page<void>>[ page1, page2 ];
3096-
await tester.pumpWidget(
3097-
MaterialApp(
3098-
home: Navigator(
3099-
pages: pages,
3100-
onPopPage: (Route<Object?> route, Object? result) => false,
3101-
),
3102-
),
3103-
);
3104-
3105-
// The page2 should have a back button.
3106-
expect(
3107-
find.descendant(
3108-
of: find.byKey(const ValueKey<String>('2')),
3109-
matching: find.byType(BackButton),
3110-
),
3111-
findsOneWidget
3112-
);
3113-
});
3114-
31153077
testWidgets('AppBar.preferredHeightFor', (WidgetTester tester) async {
31163078
late double preferredHeight;
31173079
late Size preferredSize;

0 commit comments

Comments
 (0)