Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leaks in CupertinoSwitch [prod-leak-fix] #147821

Merged
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
6 changes: 4 additions & 2 deletions packages/flutter/lib/src/cupertino/switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ class _CupertinoSwitchState extends State<CupertinoSwitch> with TickerProviderSt
late HorizontalDragGestureRecognizer _drag;

late AnimationController _positionController;
late CurvedAnimation position;
late final CurvedAnimation position;

late AnimationController _reactionController;
late Animation<double> _reaction;
late CurvedAnimation _reaction;

late bool isFocused;

Expand Down Expand Up @@ -424,6 +424,8 @@ class _CupertinoSwitchState extends State<CupertinoSwitch> with TickerProviderSt

_positionController.dispose();
_reactionController.dispose();
position.dispose();
_reaction.dispose();
super.dispose();
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/flutter/test/cupertino/switch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

void main() {
testWidgets('Switch can toggle on tap', (WidgetTester tester) async {
testWidgets('Switch can toggle on tap',
// TODO(polina-c): remove when fixed https://github.com/flutter/flutter/issues/145600 [leak-tracking-opt-in]
experimentalLeakTesting: LeakTesting.settings.withTracked(classes: const <String>['CurvedAnimation']),
(WidgetTester tester) async {
final Key switchKey = UniqueKey();
bool value = false;
await tester.pumpWidget(
Expand Down