Skip to content

Commit e2de8d8

Browse files
fixes CupertinoModalPopupRoute (#147823)
1 parent 76a07a1 commit e2de8d8

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ class CupertinoModalPopupRoute<T> extends PopupRoute<T> {
10961096
@override
10971097
Duration get transitionDuration => _kModalPopupTransitionDuration;
10981098

1099-
Animation<double>? _animation;
1099+
CurvedAnimation? _animation;
11001100

11011101
late Tween<Offset> _offsetTween;
11021102

@@ -1142,6 +1142,12 @@ class CupertinoModalPopupRoute<T> extends PopupRoute<T> {
11421142
),
11431143
);
11441144
}
1145+
1146+
@override
1147+
void dispose() {
1148+
_animation?.dispose();
1149+
super.dispose();
1150+
}
11451151
}
11461152

11471153
/// Shows a modal iOS-style popup that slides up from the bottom of the screen.

packages/flutter/test/cupertino/route_test.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,6 +2666,36 @@ void main() {
26662666

26672667
await tester.pump(const Duration(milliseconds: 400));
26682668
});
2669+
2670+
testWidgets('CupertinoModalPopupRoute does not leak CurveAnimation',
2671+
// TODO(polina-c): remove when fixed https://github.com/flutter/flutter/issues/145600 [leak-tracking-opt-in]
2672+
experimentalLeakTesting: LeakTesting.settings.withTracked(classes: <String>['CurvedAnimation']),
2673+
(WidgetTester tester) async {
2674+
await tester.pumpWidget(MaterialApp(
2675+
home: Navigator(
2676+
onGenerateRoute: (RouteSettings settings) {
2677+
return PageRouteBuilder<dynamic>(
2678+
pageBuilder: (BuildContext context, Animation<double> _, Animation<double> __) {
2679+
return GestureDetector(
2680+
onTap: () async {
2681+
await showCupertinoModalPopup<void>(
2682+
context: context,
2683+
semanticsDismissible: true,
2684+
builder: (BuildContext context) => const SizedBox(),
2685+
);
2686+
},
2687+
child: const Text('tap'),
2688+
);
2689+
},
2690+
);
2691+
},
2692+
),
2693+
));
2694+
2695+
// Push the route.
2696+
await tester.tap(find.text('tap'));
2697+
await tester.pumpAndSettle();
2698+
});
26692699
}
26702700

26712701
class MockNavigatorObserver extends NavigatorObserver {

0 commit comments

Comments
 (0)