Splash Screen Example in Flutter
Flutter Tutorial
Install Flutter in Win/Linux/Mac
Flutter Widgets:
Bottom Navigation Bar in Flutter
Auto Close Keyboard in Flutter
Screen size handling in Flutter
Flutter REST API
Flutter Advance
Wrap vs Builder vs OverBarFlow
Circular progress contain Icon
Flutter State management Comparison
Flutter Database
Flutter Token Expired Handling
Flutter Provider
Flutter GetX
Flutter with Native
Flutter Tips
Interview Questions
Splash screens are very common in Flutter, almost every application on the App Store or Play Store has integrated this feature. The main importance of splash screen is to create UI in running mode and get all relevant information from backend/cloud through APIs, so that user experience towards app is good, in this example we have created custom splash without external package:-
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ResearchThinker Splash Screen Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: SplashScreen(), // Replace with your main screen
);
}
}
//here we have creates Splash screen code
this screen open Flutter logo for 5 seconds
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
// initialization process & delay of 5 seconds
Future.delayed(Duration(seconds: 5), () { // here you can set time
// Navigate to the main screen after the splash screen
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => MainScreen()), // Replace with your main screen
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: FlutterLogo(
size: 150,
),
),
);
}
}
//This screen will come after 5 seconds
class MainScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Main Screen'),
),
body: Center(
child: Text('This is the main screen!'),
),
);
}
}
The SplashScreen class is a StatefulWidget that uses the FutureBuilder widget to simulate an asynchronous process (e.g., initialization or data loading). The initState method simulates a delay of 5 seconds (you can replace this with your actual initialization logic). After the delay, it navigates to the MainScreen using Navigator.pushReplacement.