From e2de8d80f675611af97f015674af5c0109170b1d Mon Sep 17 00:00:00 2001 From: Dimil Kalathiya <102401667+Dimilkalathiya@users.noreply.github.com> Date: Mon, 20 May 2024 23:13:18 +0530 Subject: [PATCH] fixes `CupertinoModalPopupRoute` (#147823) --- packages/flutter/lib/src/cupertino/route.dart | 8 ++++- .../flutter/test/cupertino/route_test.dart | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/cupertino/route.dart b/packages/flutter/lib/src/cupertino/route.dart index a5c23cfc13..5c622a69fb 100644 --- a/packages/flutter/lib/src/cupertino/route.dart +++ b/packages/flutter/lib/src/cupertino/route.dart @@ -1096,7 +1096,7 @@ class CupertinoModalPopupRoute extends PopupRoute { @override Duration get transitionDuration => _kModalPopupTransitionDuration; - Animation? _animation; + CurvedAnimation? _animation; late Tween _offsetTween; @@ -1142,6 +1142,12 @@ class CupertinoModalPopupRoute extends PopupRoute { ), ); } + + @override + void dispose() { + _animation?.dispose(); + super.dispose(); + } } /// Shows a modal iOS-style popup that slides up from the bottom of the screen. diff --git a/packages/flutter/test/cupertino/route_test.dart b/packages/flutter/test/cupertino/route_test.dart index 118728dd0b..6c0810920d 100644 --- a/packages/flutter/test/cupertino/route_test.dart +++ b/packages/flutter/test/cupertino/route_test.dart @@ -2666,6 +2666,36 @@ void main() { await tester.pump(const Duration(milliseconds: 400)); }); + + testWidgets('CupertinoModalPopupRoute does not leak CurveAnimation', + // TODO(polina-c): remove when fixed https://github.com/flutter/flutter/issues/145600 [leak-tracking-opt-in] + experimentalLeakTesting: LeakTesting.settings.withTracked(classes: ['CurvedAnimation']), + (WidgetTester tester) async { + await tester.pumpWidget(MaterialApp( + home: Navigator( + onGenerateRoute: (RouteSettings settings) { + return PageRouteBuilder( + pageBuilder: (BuildContext context, Animation _, Animation __) { + return GestureDetector( + onTap: () async { + await showCupertinoModalPopup( + context: context, + semanticsDismissible: true, + builder: (BuildContext context) => const SizedBox(), + ); + }, + child: const Text('tap'), + ); + }, + ); + }, + ), + )); + + // Push the route. + await tester.tap(find.text('tap')); + await tester.pumpAndSettle(); + }); } class MockNavigatorObserver extends NavigatorObserver {