Skip to content

Commit f020535

Browse files
authored
Add CurvedAnimation disposals in some widgets (#143790)
Contributes to flutter/flutter#141198 ### Description - Adds `CurvedAnimation` disposals to `material/chip.dart`, `material/input_decorator.dart`, `material/toggleable.dart`, `widgets/animated_switcher.dart`, `widgets/overscroll_indicator.dart`.
1 parent 9176f7b commit f020535

7 files changed

Lines changed: 37 additions & 26 deletions

File tree

packages/flutter/lib/src/material/chip.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -902,11 +902,11 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
902902
late AnimationController avatarDrawerController;
903903
late AnimationController deleteDrawerController;
904904
late AnimationController enableController;
905-
late Animation<double> checkmarkAnimation;
906-
late Animation<double> avatarDrawerAnimation;
907-
late Animation<double> deleteDrawerAnimation;
908-
late Animation<double> enableAnimation;
909-
late Animation<double> selectionFade;
905+
late CurvedAnimation checkmarkAnimation;
906+
late CurvedAnimation avatarDrawerAnimation;
907+
late CurvedAnimation deleteDrawerAnimation;
908+
late CurvedAnimation enableAnimation;
909+
late CurvedAnimation selectionFade;
910910

911911
bool get hasDeleteButton => widget.onDeleted != null;
912912
bool get hasAvatar => widget.avatar != null;
@@ -993,6 +993,11 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
993993
avatarDrawerController.dispose();
994994
deleteDrawerController.dispose();
995995
enableController.dispose();
996+
checkmarkAnimation.dispose();
997+
avatarDrawerAnimation.dispose();
998+
deleteDrawerAnimation.dispose();
999+
enableAnimation.dispose();
1000+
selectionFade.dispose();
9961001
super.dispose();
9971002
}
9981003

packages/flutter/lib/src/material/input_decorator.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ class _BorderContainerState extends State<_BorderContainer> with TickerProviderS
181181

182182
late AnimationController _controller;
183183
late AnimationController _hoverColorController;
184-
late Animation<double> _borderAnimation;
184+
late CurvedAnimation _borderAnimation;
185185
late _InputBorderTween _border;
186-
late Animation<double> _hoverAnimation;
186+
late CurvedAnimation _hoverAnimation;
187187
late ColorTween _hoverColorTween;
188188

189189
@override
@@ -218,6 +218,8 @@ class _BorderContainerState extends State<_BorderContainer> with TickerProviderS
218218
void dispose() {
219219
_controller.dispose();
220220
_hoverColorController.dispose();
221+
_borderAnimation.dispose();
222+
_hoverAnimation.dispose();
221223
super.dispose();
222224
}
223225

@@ -1902,7 +1904,7 @@ class InputDecorator extends StatefulWidget {
19021904

19031905
class _InputDecoratorState extends State<InputDecorator> with TickerProviderStateMixin {
19041906
late final AnimationController _floatingLabelController;
1905-
late final Animation<double> _floatingLabelAnimation;
1907+
late final CurvedAnimation _floatingLabelAnimation;
19061908
late final AnimationController _shakingLabelController;
19071909
final _InputBorderGap _borderGap = _InputBorderGap();
19081910
static const OrdinalSortKey _kPrefixSemanticsSortOrder = OrdinalSortKey(0);
@@ -1946,6 +1948,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
19461948
@override
19471949
void dispose() {
19481950
_floatingLabelController.dispose();
1951+
_floatingLabelAnimation.dispose();
19491952
_shakingLabelController.dispose();
19501953
_borderGap.dispose();
19511954
super.dispose();

packages/flutter/lib/src/material/toggleable.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ mixin ToggleableStateMixin<S extends StatefulWidget> on TickerProviderStateMixin
6868
///
6969
/// To paint the actual radial reaction, [ToggleablePainter.paintRadialReaction]
7070
/// may be used.
71-
Animation<double> get reaction => _reaction;
72-
late Animation<double> _reaction;
71+
CurvedAnimation get reaction => _reaction;
72+
late CurvedAnimation _reaction;
7373

7474
/// Controls the radial reaction's opacity animation for hover changes.
7575
///
@@ -79,8 +79,8 @@ mixin ToggleableStateMixin<S extends StatefulWidget> on TickerProviderStateMixin
7979
///
8080
/// To paint the actual radial reaction, [ToggleablePainter.paintRadialReaction]
8181
/// may be used.
82-
Animation<double> get reactionHoverFade => _reactionHoverFade;
83-
late Animation<double> _reactionHoverFade;
82+
CurvedAnimation get reactionHoverFade => _reactionHoverFade;
83+
late CurvedAnimation _reactionHoverFade;
8484
late AnimationController _reactionHoverFadeController;
8585

8686
/// Controls the radial reaction's opacity animation for focus changes.
@@ -90,8 +90,8 @@ mixin ToggleableStateMixin<S extends StatefulWidget> on TickerProviderStateMixin
9090
///
9191
/// To paint the actual radial reaction, [ToggleablePainter.paintRadialReaction]
9292
/// may be used.
93-
Animation<double> get reactionFocusFade => _reactionFocusFade;
94-
late Animation<double> _reactionFocusFade;
93+
CurvedAnimation get reactionFocusFade => _reactionFocusFade;
94+
late CurvedAnimation _reactionFocusFade;
9595
late AnimationController _reactionFocusFadeController;
9696

9797
/// Whether [value] of this control can be changed by user interaction.
@@ -203,9 +203,13 @@ mixin ToggleableStateMixin<S extends StatefulWidget> on TickerProviderStateMixin
203203
@override
204204
void dispose() {
205205
_positionController.dispose();
206+
_position.dispose();
206207
_reactionController.dispose();
208+
_reaction.dispose();
207209
_reactionHoverFadeController.dispose();
210+
_reactionHoverFade.dispose();
208211
_reactionFocusFadeController.dispose();
212+
_reactionFocusFade.dispose();
209213
super.dispose();
210214
}
211215

packages/flutter/lib/src/widgets/animated_switcher.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class _ChildEntry {
2525
final AnimationController controller;
2626

2727
// The (curved) animation being used to drive the transition.
28-
final Animation<double> animation;
28+
final CurvedAnimation animation;
2929

3030
// The currently built transition for this child.
3131
Widget transition;
@@ -308,7 +308,7 @@ class _AnimatedSwitcherState extends State<AnimatedSwitcher> with TickerProvider
308308
reverseDuration: widget.reverseDuration,
309309
vsync: this,
310310
);
311-
final Animation<double> animation = CurvedAnimation(
311+
final CurvedAnimation animation = CurvedAnimation(
312312
parent: controller,
313313
curve: widget.switchInCurve,
314314
reverseCurve: widget.switchOutCurve,
@@ -331,7 +331,7 @@ class _AnimatedSwitcherState extends State<AnimatedSwitcher> with TickerProvider
331331
required Widget child,
332332
required AnimatedSwitcherTransitionBuilder builder,
333333
required AnimationController controller,
334-
required Animation<double> animation,
334+
required CurvedAnimation animation,
335335
}) {
336336
final _ChildEntry entry = _ChildEntry(
337337
widgetChild: child,
@@ -348,6 +348,7 @@ class _AnimatedSwitcherState extends State<AnimatedSwitcher> with TickerProvider
348348
_markChildWidgetCacheAsDirty();
349349
});
350350
controller.dispose();
351+
animation.dispose();
351352
}
352353
});
353354
return entry;
@@ -376,9 +377,11 @@ class _AnimatedSwitcherState extends State<AnimatedSwitcher> with TickerProvider
376377
void dispose() {
377378
if (_currentEntry != null) {
378379
_currentEntry!.controller.dispose();
380+
_currentEntry!.animation.dispose();
379381
}
380382
for (final _ChildEntry entry in _outgoingEntries) {
381383
entry.controller.dispose();
384+
entry.animation.dispose();
382385
}
383386
super.dispose();
384387
}

packages/flutter/lib/src/widgets/overscroll_indicator.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,12 @@ class _GlowController extends ChangeNotifier {
313313
}
314314
_glowController = AnimationController(vsync: vsync)
315315
..addStatusListener(_changePhase);
316-
final Animation<double> decelerator = CurvedAnimation(
316+
_decelerator = CurvedAnimation(
317317
parent: _glowController,
318318
curve: Curves.decelerate,
319319
)..addListener(notifyListeners);
320-
_glowOpacity = decelerator.drive(_glowOpacityTween);
321-
_glowSize = decelerator.drive(_glowSizeTween);
320+
_glowOpacity = _decelerator.drive(_glowOpacityTween);
321+
_glowSize = _decelerator.drive(_glowSizeTween);
322322
_displacementTicker = vsync.createTicker(_tickDisplacement);
323323
}
324324

@@ -330,6 +330,7 @@ class _GlowController extends ChangeNotifier {
330330
double _paintOffsetScrollPixels = 0.0;
331331

332332
// animation values
333+
late final CurvedAnimation _decelerator;
333334
final Tween<double> _glowOpacityTween = Tween<double>(begin: 0.0, end: 0.0);
334335
late final Animation<double> _glowOpacity;
335336
final Tween<double> _glowSizeTween = Tween<double>(begin: 0.0, end: 0.0);
@@ -383,6 +384,7 @@ class _GlowController extends ChangeNotifier {
383384
@override
384385
void dispose() {
385386
_glowController.dispose();
387+
_decelerator.dispose();
386388
_displacementTicker.dispose();
387389
_pullRecedeTimer?.cancel();
388390
super.dispose();

packages/flutter/test/widgets/overscroll_indicator_test.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:math' as math;
66

77
import 'package:flutter/widgets.dart';
88
import 'package:flutter_test/flutter_test.dart';
9-
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
109

1110
final Matcher doesNotOverscroll = isNot(paints..circle());
1211

@@ -293,8 +292,6 @@ void main() {
293292
});
294293

295294
testWidgets('Nested overscrolls do not throw exceptions',
296-
// TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787 [leaks-to-clean]
297-
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
298295
(WidgetTester tester) async {
299296
await tester.pumpWidget(Directionality(
300297
textDirection: TextDirection.ltr,

packages/flutter/test/widgets/scrollable_restoration_test.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'package:flutter/material.dart';
66
import 'package:flutter/rendering.dart';
77
import 'package:flutter_test/flutter_test.dart';
8-
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
98

109
void main() {
1110
testWidgets('CustomScrollView restoration', (WidgetTester tester) async {
@@ -264,8 +263,6 @@ void main() {
264263
});
265264

266265
testWidgets('PageView restoration',
267-
// TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787 [leaks-to-clean]
268-
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
269266
(WidgetTester tester) async {
270267
await tester.pumpWidget(
271268
TestHarness(

0 commit comments

Comments
 (0)