I've made the quote fade out and in if the previous quote is from another category. However, I'm unable to replicate that if the quote is from the same category.
How do I make the quote fade out and in if the quote is from the same category?
I feel like tween sequence is getting there but still unable to get the results.
Any guidance is appreciated thanks!
AnimationController animationController;
Animation<double> opacityAnimation;
double opacity1 = 0.0;
///ditto for opacity2 and opacity3
String quotes1 = Quotes1[Random().nextInt(Quotes1.length)];
void generateQuotes1() {
setState(() {
quotes1 = Quotes1[Random().nextInt(Quotes1.length)];
});
}
///ditto for Quotes2 and Quotes 3
@override
void initState() {
super.initState();
changeOpacity();
animationController =
AnimationController(vsync: this, duration: Duration(seconds: 3));
animationController.forward();
opacityAnimation = TweenSequence(
<TweenSequenceItem<double>>[
TweenSequenceItem<double>(
tween: Tween<double>(begin: 1.0, end: 0.0)
.chain(CurveTween(curve: Curves.easeInOutBack)),
weight: 27),
TweenSequenceItem<double>(
tween: Tween<double>(begin: 0.0, end: 1.0)
.chain(CurveTween(curve: Curves.easeInOutBack)),
weight: 27),
],
).animate(
animationController,
);
}
@override
void dispose() {
animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold
...
AnimatedOpacity(
opacity: opacity1 == 1.0 ? opacityAnimation.value : 0.0,
duration: Duration(seconds: 1),
child: Text(quotes1),
///this shows the quote
ElevatedButton(
...
onPressed: () {
generateQuotes1();
///This returns randomized quote from the list.
opacity1 = 1.0;
opacity2 = 0.0;
opacity3 = 0.0;
},
),
///ditto for quotes2 and quotes3
...
}
}
category
. Did I understood correctly? – Motherland