Make a Splash Screen using Timer and Navigator in Flutter
A splash screen is the first screen that appears when you open an app. It usually displays the logo or name of the app and gives a smooth transition to the home or main screen. In this tutorial, we will learn how to make a splash screen in Flutter using a Timer
and Navigator
.
This method is simple, and best of all—it works without any external packages!
π§ What We’ll Do
-
Create a new Flutter project
-
Make a
SplashScreen
widget -
Use
Timer
to delay the screen -
Navigate to the
HomeScreen
after a few seconds usingNavigator
-
Google Advertisement
Explain every line of code in simple words
π¦ Step 1: Create a New Flutter Project
First, open your terminal or command prompt and run:
This will create a new Flutter project named splash_screen_demo
.
π§± Step 2: Update main.dart
File
Replace the content of your lib/main.dart
file with the following code:
π§ Step-by-Step Explanation
π’ main()
Function
This is the entry point of the app. It launches the MyApp
widget.
π© MyApp
Widget
-
MaterialApp
sets up the app. -
home: SplashScreen()
means the first screen shown will be the Splash Screen.
π¨ SplashScreen
Widget
-
Google Advertisement
We use a StatefulWidget because we want to do something after a delay (navigation).
-
The
State
class_SplashScreenState
handles the timer logic.
π Using Timer
in initState()
-
This runs when the splash screen loads.
-
Timer(Duration(seconds: 3), ...)
sets a delay of 3 seconds. -
Navigator.pushReplacement()
navigates toHomeScreen
and removes the splash screen from the stack.
π¨ Splash Screen UI
-
A blue screen with centered white text.
-
You can add a logo here if you want (e.g., using
Image.asset()
).
π HomeScreen
Widget
-
Google Advertisement
Simple home screen with text.
-
This is where the app continues after the splash screen.
π― Final Output
When you run the app:
-
A blue splash screen shows the title “My Cool App” for 3 seconds.
-
Then it automatically goes to the home screen with “Welcome to the App!”
π Tips
-
You can change the timer duration to any number of seconds.
-
Add images or animations to your splash screen for a better experience.
-
For production apps, consider using the
flutter_native_splash
package for native launch screen configuration.
β Conclusion
That’s it! You’ve learned how to create a simple and clean splash screen in Flutter using Timer
and Navigator
. This method is perfect for small to medium apps and helps create a smooth user experience.