Skip to content

Commit

Permalink
Rename isAnimating field and removed 2 assignments
Browse files Browse the repository at this point in the history
Renamed `isAnimating` -> `animate`. Also removed the 2 assignments inside of the `build` method (e.g. `final glowColor = widget.glowColor;`). The issue must've been a local thing as their initial warnings are now gone.
  • Loading branch information
stargazing-dino authored and apgapg committed Nov 13, 2019
1 parent 5f196a8 commit 25cecf6
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions lib/avatar_glow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AvatarGlow extends StatefulWidget {
final BoxShape shape;
final Duration duration;
final bool repeat;
final bool isAnimating;
final bool animate;
final Duration repeatPauseDuration;
final Curve curve;
final bool showTwoGlows;
Expand All @@ -24,7 +24,7 @@ class AvatarGlow extends StatefulWidget {
this.shape = BoxShape.circle,
this.duration = const Duration(milliseconds: 2000),
this.repeat = true,
this.isAnimating = true,
this.animate = true,
this.repeatPauseDuration = const Duration(milliseconds: 100),
this.curve = Curves.fastOutSlowIn,
this.showTwoGlows = true,
Expand Down Expand Up @@ -53,7 +53,7 @@ class _AvatarGlowState extends State<AvatarGlow>

_createAnimation();

if (widget.isAnimating) {
if (widget.animate) {
_startAnimation();
}
super.initState();
Expand All @@ -69,8 +69,8 @@ class _AvatarGlowState extends State<AvatarGlow>
_createAnimation();
}

if (widget.isAnimating != oldWidget.isAnimating) {
if (widget.isAnimating) {
if (widget.animate != oldWidget.animate) {
if (widget.animate) {
_startAnimation();
} else {
_stopAnimation();
Expand Down Expand Up @@ -103,7 +103,7 @@ class _AvatarGlowState extends State<AvatarGlow>
if (controller.status == AnimationStatus.completed) {
await Future.delayed(widget.repeatPauseDuration);

if (mounted && widget.repeat && widget.isAnimating) {
if (mounted && widget.repeat && widget.animate) {
controller.reset();
controller.forward();
}
Expand Down Expand Up @@ -135,20 +135,16 @@ class _AvatarGlowState extends State<AvatarGlow>

@override
Widget build(BuildContext context) {
// AnimatedBuilder creates its own closure for some reason
// and widget.shape is not available inside its builder method
final shape = widget.shape;
final glowColor = widget.glowColor;

return AnimatedBuilder(
animation: alphaAnimation,
child: widget.child,
builder: (context, widgetChild) {
final decoration = BoxDecoration(
shape: shape,
// If the user picks a curve that goes below 0,
// this opacity will have unexpected effects
color: glowColor.withOpacity(alphaAnimation.value.clamp(0.0, 1.0)),
shape: widget.shape,
// If the user picks a curve that goes below 0 or above 1
// this opacity will have unexpected effects without clamping
color: widget.glowColor
.withOpacity(alphaAnimation.value.clamp(0.0, 1.0)),
);

return Container(
Expand All @@ -161,7 +157,7 @@ class _AvatarGlowState extends State<AvatarGlow>
animation: bigDiscAnimation,
builder: (context, widget) {
// If the user picks a curve that goes below 0,
// this will throw without clampping
// this will throw without clamping
final size =
bigDiscAnimation.value.clamp(0.0, double.infinity);

Expand Down

0 comments on commit 25cecf6

Please sign in to comment.