diff --git a/lib/src/chart.dart b/lib/src/chart.dart index d79fb77..d5d4aae 100644 --- a/lib/src/chart.dart +++ b/lib/src/chart.dart @@ -74,6 +74,7 @@ class _ChartState extends State with TickerProviderStateMixin { @override void dispose() { _controller.dispose(); + widget.layers.forEach((e) => e.dispose()); super.dispose(); } @@ -86,7 +87,7 @@ class _ChartState extends State with TickerProviderStateMixin { Expanded( child: AnimatedBuilder( animation: _controller, - builder: (_, __) => ChartTouchDetector( + builder: (_, __) => ChartTouchDetector( onShapes: () => _touchableShapes, onTap: ((touchPosition, data) => setState(() { _touchedData = data == null diff --git a/lib/src/models/animation/chart_color_animation.dart b/lib/src/models/animation/chart_color_animation.dart index 9554e93..8a0192d 100644 --- a/lib/src/models/animation/chart_color_animation.dart +++ b/lib/src/models/animation/chart_color_animation.dart @@ -3,6 +3,8 @@ part of 'chart_animation.dart'; /// Provides color animation values. class ChartColorAnimation implements ChartAnimation { Animation? _animation; + CurvedAnimation? _listener; + Color _lastColor = Colors.transparent; ChartColorAnimation(); @@ -21,6 +23,7 @@ class ChartColorAnimation implements ChartAnimation { @override void dispose() { _animation = null; + _listener?.dispose(); } /// Initialize animation. @@ -31,15 +34,14 @@ class ChartColorAnimation implements ChartAnimation { Color? initialColor, ChartColorAnimation? oldAnimation, }) { - final Animation animation = ColorTween( + _listener?.dispose(); + _listener = CurvedAnimation( + parent: controller, + curve: curve, + ); + _animation = ColorTween( begin: oldAnimation?._lastColor ?? initialColor ?? Colors.transparent, end: color, - ).animate( - CurvedAnimation( - parent: controller, - curve: curve, - ), - ); - _animation = animation; + ).animate(_listener!); } } diff --git a/lib/src/models/animation/chart_position_animation.dart b/lib/src/models/animation/chart_position_animation.dart index 199784b..255227a 100644 --- a/lib/src/models/animation/chart_position_animation.dart +++ b/lib/src/models/animation/chart_position_animation.dart @@ -3,6 +3,7 @@ part of 'chart_animation.dart'; /// Provides position animation values. class ChartPositionAnimation implements ChartAnimation { Animation? _animation; + CurvedAnimation? _listener; Offset _lastPosition = Offset.zero; ChartPositionAnimation(); @@ -21,6 +22,7 @@ class ChartPositionAnimation implements ChartAnimation { @override void dispose() { _animation = null; + _listener?.dispose(); } /// Initialize animation. @@ -31,15 +33,14 @@ class ChartPositionAnimation implements ChartAnimation { Offset? initialPosition, ChartPositionAnimation? oldAnimation, }) { - final Animation animation = Tween( + _listener?.dispose(); + _listener = CurvedAnimation( + parent: controller, + curve: curve, + ); + _animation = Tween( begin: oldAnimation?._lastPosition ?? initialPosition ?? position, end: position, - ).animate( - CurvedAnimation( - parent: controller, - curve: curve, - ), - ); - _animation = animation; + ).animate(_listener!); } } diff --git a/lib/src/models/animation/chart_size_animation.dart b/lib/src/models/animation/chart_size_animation.dart index bb42268..cb6130a 100644 --- a/lib/src/models/animation/chart_size_animation.dart +++ b/lib/src/models/animation/chart_size_animation.dart @@ -3,6 +3,7 @@ part of 'chart_animation.dart'; /// Provides size animation values. class ChartSizeAnimation implements ChartAnimation { Animation? _animation; + CurvedAnimation? _listener; Size _lastSize = Size.zero; ChartSizeAnimation(); @@ -21,6 +22,7 @@ class ChartSizeAnimation implements ChartAnimation { @override void dispose() { _animation = null; + _listener?.dispose(); } /// Initialize animation. @@ -31,15 +33,14 @@ class ChartSizeAnimation implements ChartAnimation { Size? initialSize, ChartSizeAnimation? oldAnimation, }) { - final Animation animation = Tween( + _listener?.dispose(); + _listener = CurvedAnimation( + parent: controller, + curve: curve, + ); + _animation = Tween( begin: oldAnimation?._lastSize ?? initialSize ?? size, end: size, - ).animate( - CurvedAnimation( - parent: controller, - curve: curve, - ), - ); - _animation = animation; + ).animate(_listener!); } } diff --git a/lib/src/models/animation/chart_text_style_animation.dart b/lib/src/models/animation/chart_text_style_animation.dart index b51e556..2b14aab 100644 --- a/lib/src/models/animation/chart_text_style_animation.dart +++ b/lib/src/models/animation/chart_text_style_animation.dart @@ -3,6 +3,8 @@ part of 'chart_animation.dart'; /// Provides text style animation values. class ChartTextStyleAnimation implements ChartAnimation { Animation? _animation; + CurvedAnimation? _listener; + TextStyle _lastTextStyle = const TextStyle( color: Colors.transparent, ); @@ -26,6 +28,7 @@ class ChartTextStyleAnimation implements ChartAnimation { @override void dispose() { _animation = null; + _listener?.dispose(); } /// Initialize animation. @@ -36,19 +39,18 @@ class ChartTextStyleAnimation implements ChartAnimation { TextStyle? initialTextSyle, ChartTextStyleAnimation? oldAnimation, }) { - final Animation animation = TextStyleTween( + _listener?.dispose(); + _listener = CurvedAnimation( + parent: controller, + curve: curve, + ); + _animation = TextStyleTween( begin: oldAnimation?._lastTextStyle ?? initialTextSyle ?? const TextStyle( color: Colors.transparent, ), end: textStyle, - ).animate( - CurvedAnimation( - parent: controller, - curve: curve, - ), - ); - _animation = animation; + ).animate(_listener!); } } diff --git a/lib/src/models/line/chart_line_data_item.dart b/lib/src/models/line/chart_line_data_item.dart index 341d30c..b7687de 100644 --- a/lib/src/models/line/chart_line_data_item.dart +++ b/lib/src/models/line/chart_line_data_item.dart @@ -61,6 +61,7 @@ class ChartLineDataItem extends ChartDataItem { @override void dispose() { _value.dispose(); + _touch.dispose(); } /// Initialize touch area animations. diff --git a/pubspec.yaml b/pubspec.yaml index c485130..7ee7044 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: mrx_charts description: Simple, high-performance Flutter charts with beautiful animations. -version: 0.1.3 +version: 0.1.4 repository: https://github.com/merixstudio/mrx-flutter-charts issue_tracker: https://github.com/merixstudio/mrx-flutter-charts/issues homepage: