Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splash Screen Color not Changing in Flutter

I am new to Flutter and still practicing

I am creating a splash screen but the color of splash screen is not changing

My Code:

-launch_background.xml

<?xml version="1.0" encoding="utf-8"?>
    <!-- Modify this file to customize your launch splash screen -->
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@android:color/black" />
    
        <!-- You can insert your own image assets here -->
        <!-- <item>
            <bitmap
                android:gravity="center"
                android:src="@mipmap/launch_image" />
        </item> -->
    </layer-list>

-main.dart

import 'package:flutter/material.dart';
import 'package:id_locker/Screens/HomeScreen.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomeScreen(),
    );
  }
}

-HomeScreen.dart

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

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(color: HexColor("#2301FA")),
    );
  }
}

It should ho black screen but it still white screen SS: enter image description here

like image 291
Prince Kumar Avatar asked Dec 07 '25 14:12

Prince Kumar


2 Answers

You also need to change in launch_background.xml file of the drawable-v21 folder the same as of the drawable folder.

Change

<item android:drawable="?android:colorBackground" />

to the tweaks you made @android:color/black (or @color/backgroudColor for the custom-defined colors.xml file);

<item android:drawable="@color/backgroudColor" />
like image 109
TechSatya Avatar answered Dec 11 '25 05:12

TechSatya


Did you edit the launch_background.xml in the drawable folder? You may need to edit the launch_background.xml in the drawable-v21 folder instead. Or, just use the flutter_native_splash package that I maintain.

like image 40
jon Avatar answered Dec 11 '25 05:12

jon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!