i’m using animatedSwitcher of flutter , to animate my list of widget , but the thing is i want to show the next widget of the list without pressing any button , like after a duration , but i couldn’t figure out how , so im seeking for any help here , this is my code
Scaffold(
backgroundColor: Colors.white,
body: Column(
children: [
AnimatedSwitcher(
duration: const Duration(milliseconds: 500),
transitionBuilder: (Widget child, Animation<double> animation) {
return ScaleTransition(scale: animation, child: child);
},
child: Text(
widget.aya[i].text,
style: Theme.of(context).textTheme.headlineMedium,
),
),
],
));
2
Answers
You can you
FutureBuilder
and add your desired duration after that you want the next widget to show and return it.Like below code:
Here i’m returning
FutureBuilder
from scaffold body and passed a_futureFunction()
whose returning a container after 5 seconds till that seconds a container with indigoAccent colour will be shown and after a container returned from function will be visible.This whole thing will be done without any action.
But in basic application you can use the FutureBuilder cause it’s a simple solution but i don’t suggest using in the complex application cause the FutureBuilder build itself on every changing state, For that you should use state management tools like Bloc or Cubits.
The simplest solution is to use a Timer.
With this setup, the widgets will automatically switch every 3 seconds, providing the desired behavior without needing to press any buttons.