I have a stateful widget which I am attempted to transition the textStyle like below.
AnimatedDefaultTextStyle(
duration: Duration(seconds: 3),
child: Text(word),
style: hideWord
? TextStyle(
color: Colors.white,
fontSize: 40,
fontWeight: FontWeight.w300)
: TextStyle(
color: Colors.black,
fontSize: 40,
fontWeight: FontWeight.w300),
),
However the animation is instant and doesn't take the defined 3 seconds to complete, in fact there is no animation at all just a change from black to white text rather than the duration set in the animationDefaultTextStyle.
I am triggering the animation via the following from another stateful widget on click event.
cardlist[currentCardIndex].hideWord = true;
What am I missing here? I could implement BLOC and add a listener to the card widget and then setState, but that seems like overkill for what should be a basic trigger.
duration: Duration(seconds: 3)
means the duration of the animation, not when it starts – pskinkclass FooText extends StatefulWidget { @override _FooTextState createState() => _FooTextState(); } class _FooTextState extends State<FooText> { var colors = [Colors.black, Colors.orange]; var idx = 0; @override Widget build(BuildContext context) { return AnimatedDefaultTextStyle( child: InkWell( onTap: () => setState(() => idx ^= 1), child: Center(child: Text('click me')), ), style: TextStyle( color: colors[idx], fontSize: 64, ), duration: 500.milliseconds, ); } }
– pskink