-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial animation for LineChart / BarChart / RadarChart
- Loading branch information
Showing
17 changed files
with
623 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
lib/src/chart/base/base_chart/initial_animation_configuration.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:equatable/equatable.dart'; | ||
|
||
/// It holds configuration for initial animation | ||
class InitialAnimationConfiguration with EquatableMixin { | ||
const InitialAnimationConfiguration({ | ||
this.enabled = true, | ||
this.initialValue, | ||
}); | ||
|
||
/// Determines if the initial animation is enabled. | ||
final bool enabled; | ||
|
||
/// Initial value of the animation. If null then max(0, minY) is used. | ||
final double? initialValue; | ||
|
||
@override | ||
List<Object?> get props => [enabled, initialValue]; | ||
} |
55 changes: 55 additions & 0 deletions
55
lib/src/chart/base/base_chart/initial_animation_mixin.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import 'package:fl_chart/src/chart/base/base_chart/initial_animation_configuration.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
@optionalTypeArgs | ||
mixin InitialAnimationMixin<T, D extends ImplicitlyAnimatedWidget> | ||
on AnimatedWidgetBaseState<D> { | ||
InitialAnimationConfiguration get initialAnimationConfiguration; | ||
Tween<dynamic>? get tween; | ||
|
||
T? _targetValue; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_handleInitialAnimation(); | ||
} | ||
|
||
void _handleInitialAnimation() { | ||
if (!initialAnimationConfiguration.enabled) { | ||
return; | ||
} | ||
|
||
if (tween == null || _targetValue == null) { | ||
return; | ||
} | ||
tween! | ||
..begin = tween!.evaluate(animation) | ||
..end = _targetValue; | ||
|
||
controller | ||
..value = 0.0 | ||
..forward(); | ||
didUpdateTweens(); | ||
} | ||
|
||
T constructInitialData(T data) { | ||
if (!initialAnimationConfiguration.enabled) { | ||
return data; | ||
} | ||
_targetValue = data; | ||
|
||
return getAppearanceAnimationData(data); | ||
} | ||
|
||
T getAppearanceAnimationData(T data); | ||
|
||
double getAppearanceValue(double minY, double maxY) { | ||
final initialValue = initialAnimationConfiguration.initialValue; | ||
if (initialValue != null) { | ||
return initialValue; | ||
} | ||
|
||
return (minY <= 0 && maxY >= 0) ? 0.0 : minY; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.