0
votes

Hi I have a stateful widget called BobButton() which basically does an animation where the button bobs up and down when pressed.

BobButton animates the child widget with a Bobbing effect (It is Stateful)

I pass a child into the BobButton like so

BobButton( //Statefulwidget
  child: Widget(
    color: color,
    controller: animationController,
  )
)

Some of these widgets have their own animations or have variables that change in the parent widgets state. For example I might call:

setState({
  color = Colors.pink
});

or

animationController.forward()

However the widget does not update as the child has already been passed into the stateful widget BobButton.

What should I do to fix this

1

1 Answers

1
votes

In Widget override the method

@override
didUpdateWidget(Widget oldWidget) {
  super.didUpdateWidget(oldWidget);
  if (widget.color != oldWidget.color) {
    setState(() {
      //  states variables if neccessary
    });
  }
}

AnimationController is a Listenable so you may add a listener. Or try to check a value change in didUpdateWidget method as mentioned above.