• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
October 28, 2022 |2.3K Views

How to Create a Splash Screen in Flutter App

  Share   Like
Description
Discussion

Splash Screen is the first screen that we see when we run our application. It is also known as Launch Screen. We will implement three basic methods to add a splash screen in our app.

Steps :

1. Create a new Flutter app using Command Prompt.

2. Delete the code from main.dart file and copy the below code.

Explanation of above code :

  • We have a main() function which calls runApp() by taking any widget as an argument to create the layout.
  • Then we have the home as MyHomePage() which is a stateful class(Mutable class).
  • MyHomePage() returns a Container which has a child as FlutterLogo(which will be shown initially when app starts).
  • Now, we have one most important method which is initState().
  • initState() method called once when the stateful widget is inserted in the widget tree.
  • initState() first call super.initState() and then Timer of duration 4 seconds(Timer function has 2 arguments,first is Duration and second is action to be performed). After 4 seconds,Current screen will be replaced by new Screen i.e. SecondScreen() .
  • We can also use Asset Image/Network Image instead of FlutterLogo.

Related Article :  https://www.geeksforgeeks.org/splash-screen-in-flutter/