Google Advertisement

How to Create a Splash Screen in Flutter using Timer and Navigator

Google Advertisement
πŸ”₯ Read with Full Features on Our Website

Learn how to create a simple splash screen in Flutter using Timer and Navigator. This step-by-step tutorial includes complete code and beginner-friendly explanations.

Published on 04 May 2025
By Vandu

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.

πŸ”₯ Read with Full Features on Our Website

This method is simple, and best of all—it works without any external packages!


πŸ”§ What We’ll Do


πŸ“¦ Step 1: Create a New Flutter Project

First, open your terminal or command prompt and run:

flutter create splash_screen_demo
cd splash_screen_demo

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:

import 'dart:async';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Splash Screen Demo',
      debugShowCheckedModeBanner: false,
      home: SplashScreen(),
    );
  }
}

// Splash Screen Widget
class SplashScreen extends StatefulWidget {
  @override
  _SplashScreenState createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> {
  @override
  void initState() {
    super.initState();

    // Timer that waits 3 seconds then moves to HomeScreen
    Timer(Duration(seconds: 3), () {
      Navigator.pushReplacement(
        context,
        MaterialPageRoute(builder: (context) => HomeScreen()),
      );
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.blueAccent,
      body: Center(
        child: Text(
          'My Cool App',
          style: TextStyle(
            fontSize: 30,
            fontWeight: FontWeight.bold,
            color: Colors.white,
          ),
        ),
      ),
    );
  }
}

// Home Screen Widget
class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Home Screen'),
      ),
      body: Center(
        child: Text(
          'Welcome to the App!',
          style: TextStyle(fontSize: 24),
        ),
      ),
    );
  }
}

🧠 Step-by-Step Explanation

🟒 main() Function

void main() {
  runApp(MyApp());
}

This is the entry point of the app. It launches the MyApp widget.


🟩 MyApp Widget

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Splash Screen Demo',
      debugShowCheckedModeBanner: false,
      home: SplashScreen(),
    );
  }
}

🟨 SplashScreen Widget

class SplashScreen extends StatefulWidget {
  @override
  _SplashScreenState createState() => _SplashScreenState();
}
 

πŸ•’ Using Timer in initState()

@override
void initState() {
  super.initState();

  Timer(Duration(seconds: 3), () {
    Navigator.pushReplacement(
      context,
      MaterialPageRoute(builder: (context) => HomeScreen()),
    );
  });
}

🎨 Splash Screen UI

Scaffold(
  backgroundColor: Colors.blueAccent,
  body: Center(
    child: Text(
      'My Cool App',
      style: TextStyle(
        fontSize: 30,
        fontWeight: FontWeight.bold,
        color: Colors.white,
      ),
    ),
  ),
);

🏠 HomeScreen Widget

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Home Screen'),
      ),
      body: Center(
        child: Text(
          'Welcome to the App!',
          style: TextStyle(fontSize: 24),
        ),
      ),
    );
  }
}

🎯 Final Output

When you run the app:

  1. A blue splash screen shows the title “My Cool App” for 3 seconds.

  2. Then it automatically goes to the home screen with “Welcome to the App!”


πŸ“ Tips


βœ… 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.

❀️ Like πŸ’¬ Comment πŸ”— Share
Google Advertisement
πŸ‘‰ View Full Version on Main Website β†—
Google Advertisement
πŸ‘‰ Read Full Article on Website