Skip to content

Commit

Permalink
fixes CupertinoModalPopupRoute (#147823)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimilkalathiya committed May 20, 2024
1 parent 76a07a1 commit e2de8d8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/flutter/lib/src/cupertino/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ class CupertinoModalPopupRoute<T> extends PopupRoute<T> {
@override
Duration get transitionDuration => _kModalPopupTransitionDuration;

Animation<double>? _animation;
CurvedAnimation? _animation;

late Tween<Offset> _offsetTween;

Expand Down Expand Up @@ -1142,6 +1142,12 @@ class CupertinoModalPopupRoute<T> extends PopupRoute<T> {
),
);
}

@override
void dispose() {
_animation?.dispose();
super.dispose();
}
}

/// Shows a modal iOS-style popup that slides up from the bottom of the screen.
Expand Down
30 changes: 30 additions & 0 deletions packages/flutter/test/cupertino/route_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: <String>['CurvedAnimation']),
(WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Navigator(
onGenerateRoute: (RouteSettings settings) {
return PageRouteBuilder<dynamic>(
pageBuilder: (BuildContext context, Animation<double> _, Animation<double> __) {
return GestureDetector(
onTap: () async {
await showCupertinoModalPopup<void>(
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 {
Expand Down

0 comments on commit e2de8d8

Please sign in to comment.