mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix memory leaks in CupertinoSwitch (#147821)
This commit is contained in:
parent
02d239a098
commit
459df3c62d
@ -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;
|
||||
|
||||
@ -424,6 +424,8 @@ class _CupertinoSwitchState extends State<CupertinoSwitch> with TickerProviderSt
|
||||
|
||||
_positionController.dispose();
|
||||
_reactionController.dispose();
|
||||
position.dispose();
|
||||
_reaction.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user