How to remove default splash screen in flutter

To remove the default splash screen in Flutter, you need to perform the following steps:

  1. Open the pubspec.yaml file of your Flutter project.
  2. Under the flutter section, specify the assets you want to show as your splash screen. For example:

    flutter:
      assets:
        - assets/images/splash.png
          
  3. Inside the lib folder, create a new folder called utils (or any other appropriate name) and create a new Dart file inside it, for example, splash_screen.dart.
  4. In the splash_screen.dart file, import the required packages:

    import 'package:flutter/material.dart';
    import 'package:flutter/services.dart';
          
  5. Create a new class called SplashScreen that extends StatelessWidget:

    class SplashScreen extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage('assets/images/splash.png'),
                fit: BoxFit.cover,
              ),
            ),
          ),
        );
      }
    }
          
  6. In the main lib folder, open the main.dart file and replace the existing MyApp class with the following:

    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top]);
        return MaterialApp(
          title: 'Your App',
          theme: ThemeData(
            primarySwatch: Colors.blue,
            visualDensity: VisualDensity.adaptivePlatformDensity,
          ),
          home: SplashScreen(), // Replace this with your app's home screen widget
        );
      }
    }
          
  7. Run your Flutter app, and the specified image will be displayed as the splash screen before transitioning to your app’s home screen.

Make sure to update the path and asset name in the steps above to match your actual asset folder structure and file name.

Leave a comment