# Set Up Splash Screen
Complete the following steps to configure a splash screen. The splash screen serves a crucial role by executing code to create tables in the database and directing users to the authentication, profile creation, or layout based on their authentication status and profile completion status.
- Create a file
lib/services/splash_screen/splash_screen.dart - Add this code to the file
import '../../theme/colors.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../datastore/sqlite/sqlite.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
/// Init
void initState() {
_loadData();
super.initState();
}
/// Widget
Widget build(BuildContext context) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.light),
child: Scaffold(
body: Container(
decoration: const BoxDecoration(color: secondaryColor),
child: Center(
child: Container(
width: 110.0,
height: 110.0,
padding: const EdgeInsets.all(20.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(14.0),
image: const DecorationImage(
image: AssetImage("assets/logos/ios.png"),
fit: BoxFit.contain,
)),
),
),
),
),
);
}
/// Load
_loadData() async {
await SqliteDB().createTables();
await Future.delayed(const Duration(seconds: 2));
/// Redirect to some page here
}
}
- Change
home:parameter toSplashScreen()inmain.dartas shown below
...
/// Widget
Widget build(BuildContext context) {
return AdaptiveTheme(
light: buildThemeData(),
dark: buildDarkThemeData(),
initial: AdaptiveThemeMode.light,
builder: (theme, darkTheme) => OverlaySupport(
global: true,
child: MaterialApp(
title: _title,
theme: theme,
darkTheme: darkTheme,
debugShowCheckedModeBanner: false,
home: const SplashScreen(),
),
),
);
}
...
- Run App to test