Skip to content

Commit 45cc90b

Browse files
committed
Partial solution for navigating both ways, but not working in some cases
1 parent d423742 commit 45cc90b

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

packages/flutter/lib/src/cupertino/route.dart

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ mixin CupertinoRouteTransitionMixin<T> on PageRoute<T> {
158158

159159
/// True if an iOS-style back swipe pop gesture is currently underway for [route].
160160
///
161-
/// This just check the route's [NavigatorState.userGestureInProgress].
161+
/// This just checks the route's [NavigatorState.userGestureInProgress].
162162
///
163163
/// See also:
164164
///
@@ -293,6 +293,7 @@ mixin CupertinoRouteTransitionMixin<T> on PageRoute<T> {
293293
child: _CupertinoBackGestureDetector<T>(
294294
enabledCallback: () => _isPopGestureEnabled<T>(route),
295295
onStartPopGesture: () => _startPopGesture<T>(route),
296+
getIsCurrent: () => route.isCurrent,
296297
child: child,
297298
),
298299
);
@@ -596,6 +597,7 @@ class _CupertinoBackGestureDetector<T> extends StatefulWidget {
596597
required this.enabledCallback,
597598
required this.onStartPopGesture,
598599
required this.child,
600+
required this.getIsCurrent,
599601
});
600602

601603
final Widget child;
@@ -604,6 +606,8 @@ class _CupertinoBackGestureDetector<T> extends StatefulWidget {
604606

605607
final ValueGetter<_CupertinoBackGestureController<T>> onStartPopGesture;
606608

609+
final ValueGetter<bool> getIsCurrent;
610+
607611
@override
608612
_CupertinoBackGestureDetectorState<T> createState() => _CupertinoBackGestureDetectorState<T>();
609613
}
@@ -613,8 +617,6 @@ class _CupertinoBackGestureDetectorState<T> extends State<_CupertinoBackGestureD
613617

614618
late HorizontalDragGestureRecognizer _recognizer;
615619

616-
int? _trackedPointer;
617-
618620
@override
619621
void initState() {
620622
super.initState();
@@ -656,6 +658,13 @@ class _CupertinoBackGestureDetectorState<T> extends State<_CupertinoBackGestureD
656658
void _handleDragEnd(DragEndDetails details) {
657659
assert(mounted);
658660
assert(_backGestureController != null);
661+
// TODO(justinmc): Why can't I drag to go back on page 3 after this?
662+
print('justin _handleDragEnd. ${widget.getIsCurrent()}');
663+
if (!widget.getIsCurrent()) {
664+
_backGestureController?.dragEnd(0.0);
665+
_backGestureController = null;
666+
return;
667+
}
659668
_backGestureController!.dragEnd(_convertToLogical(details.velocity.pixelsPerSecond.dx / context.size!.width));
660669
_backGestureController = null;
661670
}
@@ -671,14 +680,9 @@ class _CupertinoBackGestureDetectorState<T> extends State<_CupertinoBackGestureD
671680
void _handlePointerDown(PointerDownEvent event) {
672681
if (widget.enabledCallback()) {
673682
_recognizer.addPointer(event);
674-
_trackedPointer = event.pointer;
675683
}
676684
}
677685

678-
void _handlePointerUp(PointerUpEvent event) {
679-
_trackedPointer = null;
680-
}
681-
682686
double _convertToLogical(double value) {
683687
switch (Directionality.of(context)) {
684688
case TextDirection.rtl:
@@ -697,30 +701,21 @@ class _CupertinoBackGestureDetectorState<T> extends State<_CupertinoBackGestureD
697701
MediaQuery.paddingOf(context).left :
698702
MediaQuery.paddingOf(context).right;
699703
dragAreaWidth = max(dragAreaWidth, _kBackGestureWidth);
700-
return PopScope(
701-
onPopInvoked: (bool didPop) {
702-
if (!didPop || _trackedPointer == null) {
703-
return;
704-
}
705-
_recognizer.rejectGesture(_trackedPointer!);
706-
},
707-
child: Stack(
708-
fit: StackFit.passthrough,
709-
children: <Widget>[
710-
widget.child,
711-
PositionedDirectional(
712-
start: 0.0,
713-
width: dragAreaWidth,
714-
top: 0.0,
715-
bottom: 0.0,
716-
child: Listener(
717-
onPointerDown: _handlePointerDown,
718-
onPointerUp: _handlePointerUp,
719-
behavior: HitTestBehavior.translucent,
720-
),
704+
return Stack(
705+
fit: StackFit.passthrough,
706+
children: <Widget>[
707+
widget.child,
708+
PositionedDirectional(
709+
start: 0.0,
710+
width: dragAreaWidth,
711+
top: 0.0,
712+
bottom: 0.0,
713+
child: Listener(
714+
onPointerDown: _handlePointerDown,
715+
behavior: HitTestBehavior.translucent,
721716
),
722-
],
723-
),
717+
),
718+
],
724719
);
725720
}
726721
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2919,7 +2919,7 @@ class _RouteEntry extends RouteTransitionRecord {
29192919
initialState == _RouteLifecycle.pushReplace ||
29202920
initialState == _RouteLifecycle.replace,
29212921
),
2922-
currentState = initialState {
2922+
currentState = initialState {
29232923
// TODO(polina-c): stop duplicating code across disposables
29242924
// https://github.com/flutter/flutter/issues/137435
29252925
if (kFlutterMemoryAllocationsEnabled) {

0 commit comments

Comments
 (0)