Lunching Other Screen After Delay in Flutter.

Using Duration & Timer to Create Simple Splash Screen in Flutter

Aminullah Taj Muhammad
CodeChai
3 min readJan 17, 2020

--

Hello Guys, this is my third article of this series. In this article we’ll learn about splash screen in flutter. Most of the applications have splash screen. The working on splash screen is depends on the product. This article is basically part of Today I Learned.

Here is the video tutorial

In Android Development we usepostDelayed() Callback to hold the screen. But in Flutter this is much tricky because in Flutter there are async methods that perform such type of tasks.

In case you are not familiar, here’s a little overview about the difference between StatefulWidget and StatelessWidget.

StatefulWidget is a widget that loads dynamically like it changes their states or rebuild at run time.

StatelessWidget is a widget that loads only compile time like it never rebuild by itself. It is usually use for build the UI of the screen.

So first add a class which extends from StatefulWidget like this.

Now override the method createState that returns the state of the screen class. So, for this we create new class which extends from State class.

So, it will override initState and build methods. In initState method, we add delay functionality by adding these lines here.

The startTime method is an async method that perform task in background. We use Timer class for this where we pass duration for holding the screen and route/designation to indicate where to go. We use Navigator to set the route/designation. Here is the code.

For Timer class import this file.

So, after that their is a build method that helps to creates User Interface of the screen.

Here is the full code of the SplashScreen.dart

Here is the result.

--

--