mirror of
https://github.com/flutter/flutter
synced 2024-10-03 23:14:12 +00:00
Fix memory leak in switch painter (#147228)
This commit is contained in:
parent
b0524b354b
commit
b0198426b5
|
@ -1066,9 +1066,14 @@ class _SwitchPainter extends ToggleablePainter {
|
|||
return;
|
||||
}
|
||||
_positionController = value;
|
||||
_colorAnimation?.dispose();
|
||||
_colorAnimation = CurvedAnimation(parent: positionController, curve: Curves.easeOut, reverseCurve: Curves.easeIn);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
CurvedAnimation? _colorAnimation;
|
||||
|
||||
|
||||
Icon? get activeIcon => _activeIcon;
|
||||
Icon? _activeIcon;
|
||||
set activeIcon(Icon? value) {
|
||||
|
@ -1516,7 +1521,7 @@ class _SwitchPainter extends ToggleablePainter {
|
|||
final double inset = thumbOffset == null ? 0 : 1.0 - (currentValue - thumbOffset!).abs() * 2.0;
|
||||
thumbSize = Size(thumbSize!.width - inset, thumbSize.height - inset);
|
||||
|
||||
final double colorValue = CurvedAnimation(parent: positionController, curve: Curves.easeOut, reverseCurve: Curves.easeIn).value;
|
||||
final double colorValue = _colorAnimation!.value;
|
||||
final Color trackColor = Color.lerp(inactiveTrackColor, activeTrackColor, colorValue)!;
|
||||
final Color? trackOutlineColor = inactiveTrackOutlineColor == null || activeTrackOutlineColor == null ? null
|
||||
: Color.lerp(inactiveTrackOutlineColor, activeTrackOutlineColor, colorValue);
|
||||
|
@ -1737,6 +1742,7 @@ class _SwitchPainter extends ToggleablePainter {
|
|||
_cachedThumbColor = null;
|
||||
_cachedThumbImage = null;
|
||||
_cachedThumbErrorListener = null;
|
||||
_colorAnimation?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import 'package:flutter/gestures.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
|
||||
|
||||
void main() {
|
||||
group('$ReorderableListView', () {
|
||||
|
@ -689,7 +690,10 @@ void main() {
|
|||
handle.dispose();
|
||||
});
|
||||
|
||||
testWidgets("Doesn't hide accessibility when a child declares its own semantics", (WidgetTester tester) async {
|
||||
testWidgets("Doesn't hide accessibility when a child declares its own semantics",
|
||||
// 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 SemanticsHandle handle = tester.ensureSemantics();
|
||||
final Widget reorderableListView = ReorderableListView(
|
||||
onReorder: (int oldIndex, int newIndex) { },
|
||||
|
|
Loading…
Reference in a new issue