Little Monkey
Little Monkey

Reputation: 6157

How to pass a voidcallback

I'm working with the Animator and I'm creating my own class. I'm trying to pass a function to endAnimationListener, but with bad results:

class AnimatedFade extends StatelessWidget {
  final Duration _duration;
  final VoidCallBack _action;
  AnimatedFade(this._thidation, this._action);

  @override
   Widget build(BuildContext context) {
          return Animator(
              duration: _duration,
              endAnimationListener: (_) => _action,

and the way how I pass it it's just:

 () {....}

Upvotes: 0

Views: 207

Answers (1)

Sami Kanafani
Sami Kanafani

Reputation: 15751

try

class AnimatedFade extends StatelessWidget {
  final Duration _duration;
  final VoidCallBack _action;
  AnimatedFade(this._thidation, this._action);

  @override
   Widget build(BuildContext context) {
          return Animator(
              duration: _duration,
              endAnimationListener: (_) => _action(),

this means when the animation ends, execute the voidcallback function you defined

Upvotes: 1

Related Questions