Simplifies simple controller

This commit is contained in:
matt Sullivan
2021-06-14 17:18:29 -07:00
parent 4ef8d32a93
commit a8e27e3ef8
3 changed files with 15 additions and 41 deletions

View File

@ -28,30 +28,19 @@ class SpeedyAnimation extends StatelessWidget {
class SpeedController extends SimpleAnimation {
final double speedMultiplier;
/// Stops the animation on the next apply
bool _stopOnNextApply = false;
SpeedController(
String animationName, {
double mix = 1,
this.speedMultiplier = 1,
}) : super(
animationName,
mix: mix,
);
}) : super(animationName, mix: mix);
@override
void apply(RuntimeArtboard artboard, double elapsedSeconds) {
if (_stopOnNextApply || instance == null) {
if (instance == null || !instance!.keepGoing) {
isActive = false;
}
instance!.animation.apply(instance!.time, coreContext: artboard, mix: mix);
if (!instance!.advance(elapsedSeconds * speedMultiplier)) {
_stopOnNextApply = true;
}
instance!
..animation.apply(instance!.time, coreContext: artboard, mix: mix)
..advance(elapsedSeconds * speedMultiplier);
}
@override
void onActivate() => _stopOnNextApply = false;
}

View File

@ -44,7 +44,7 @@ class _PlayOneShotAnimationState extends State<PlayOneShotAnimation> {
floatingActionButton: FloatingActionButton(
// disable the button while playing the animation
onPressed: () => _isPlaying ? null : _controller.isActive = true,
tooltip: 'Play',
tooltip: 'Bounce',
child: const Icon(Icons.arrow_upward),
),
);