How to show splash screen in flutter for 3 seconds and then go next my login screen.
I have tried.countdowntimer but import is unresolved
import \'pack
Future.delayed
would be a good solution without a countdown.
But considering you have a countdown, you can use the animation framework Flutter provides.
The idea behind it would be to use an AnimationController
with a duration of 3 seconds. Start the animation as soon as the splashScreen is instantiated. And add a listener to redirect to /login
on animation end.
Then pass that controller to an AnimationBuilder
which would handle the formating of your countdown based on animationController.lastElaspedDuration
.
class SplashScreen extends StatefulWidget {
final Duration duration;
const SplashScreen({this.duration});
@override
_SplashScreenState createState() => new _SplashScreenState();
}
class _SplashScreenState extends State with SingleTickerProviderStateMixin {
AnimationController animationController;
@override
void initState() {
animationController = new AnimationController(duration: widget.duration, vsync: this)
..forward()
..addStatusListener((status) {
if (status == AnimationStatus.completed) {
Navigator.pushReplacementNamed(context, '/login');
}
});
super.initState();
}
@override
Widget build(BuildContext context) {
return new AnimatedBuilder(
animation: animationController,
builder: (context, _) {
return new Center(
child: new Text(animationController.lastElapsedDuration.inSeconds.toString()),
);
},
);
}
}