Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ class PredictiveBackPageTransitionsBuilder extends PageTransitionsBuilder {
PredictiveBackEvent? startBackEvent,
PredictiveBackEvent? currentBackEvent,
) {
// Only do a predictive back transition when the user is performing a
// pop gesture. Otherwise, for things like button presses or other
// programmatic navigation, fall back to
// FadeForwardsPageTransitionsBuilder.
if (route.popGestureInProgress) {
// Only use the predictive back transition during an active back gesture.
if (phase != _PredictiveBackPhase.idle) {
return _PredictiveBackSharedElementPageTransition(
isDelegatedTransition: true,
animation: animation,
Expand Down Expand Up @@ -156,10 +153,8 @@ class PredictiveBackFullscreenPageTransitionsBuilder extends PageTransitionsBuil
PredictiveBackEvent? startBackEvent,
PredictiveBackEvent? currentBackEvent,
) {
// Only do a predictive back transition when the user is performing a
// pop gesture. Otherwise, for things like button presses or other
// programmatic navigation, fall back to ZoomPageTransitionsBuilder.
if (route.popGestureInProgress) {
// Only use the predictive back transition during an active back gesture.
if (phase != _PredictiveBackPhase.idle) {
return _PredictiveBackFullscreenPageTransition(
animation: animation,
secondaryAnimation: secondaryAnimation,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
changelog: |
- Prevents a covered route from entering a predictive back transition while dragging a `CupertinoSheet`.
version: patch
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:cupertino_ui/cupertino_ui.dart' show CupertinoPageScaffold, showCupertinoSheet;
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -673,6 +674,70 @@ void main() {
findsOneWidget,
);
});

testWidgets(
'route covered by a CupertinoSheet does not switch to the predictive back '
'transition while the sheet is dragged (${pageTransitionsBuilder.runtimeType})',
(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(
pageTransitionsTheme: PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{
for (final TargetPlatform platform in TargetPlatform.values)
platform: pageTransitionsBuilder,
},
),
),
home: Builder(
builder: (BuildContext context) {
return Scaffold(
body: Center(
child: TextButton(
onPressed: () {
showCupertinoSheet<void>(
context: context,
scrollableBuilder: (BuildContext context, ScrollController controller) {
return CupertinoPageScaffold(
child: ListView.builder(
controller: controller,
itemCount: 30,
itemBuilder: (BuildContext context, int index) {
return SizedBox(height: 56.0, child: Text('item $index'));
},
),
);
},
);
},
child: const Text('open sheet'),
),
),
);
},
),
),
);

await tester.tap(find.text('open sheet'));
await tester.pumpAndSettle();

expect(_findPredictiveBackPageTransition(pageTransitionsBuilder), findsNothing);
expect(_findFallbackPageTransition(pageTransitionsBuilder), findsOneWidget);

final TestGesture gesture = await tester.startGesture(const Offset(100, 300));
// A small drag first wins the gesture arena before the larger drag.
await gesture.moveBy(const Offset(0, 30));
await gesture.moveBy(const Offset(0, 100));
await tester.pump();

expect(_findPredictiveBackPageTransition(pageTransitionsBuilder), findsNothing);
expect(_findFallbackPageTransition(pageTransitionsBuilder), findsOneWidget);

await gesture.up();
await tester.pumpAndSettle();
},
);
}

testWidgets('PredictiveBackPageTransitionsBuilder uses fallbackColor', (
Expand Down