3

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

Rex Nihilo
  • 604
  • 2
  • 7
  • 16
  • Have a look at https://stackoverflow.com/questions/56583735/flutter-change-splash-screen-background-color – wamae Jun 06 '21 at 12:57
  • I have already seen that , but it is not working neither yt tutorial , I don't know , What's the Problems – Prince Kumar Jun 06 '21 at 16:19

5 Answers5

5

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" />
TechSatya
  • 247
  • 4
  • 10
2

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.

jon
  • 3,202
  • 3
  • 23
  • 35
1

You can set & change it for booth themes light & dark simply using flutter_native_splash.

First of all, you need to add the following line to pubspec.yaml file under dependencies:

flutter_native_splash: ^1.3.1

Then add flutter_native_splash: as new section to pubspec.yaml. Now you can set the splash background color for light and dark themes by adding the following lines under flutter_native_splash:

color: "#ff8a84"
color_dark: "#ad5f5c"
android: true
ios: true

android & ios added to supply booth OS's

In the end, the pubspec.yaml file will look like this:

enter image description here

Now to generate the splash screen:

  • open the terminal in your fluter project
  • run this command: flutter clean && flutter pub get && flutter pub run flutter_native_splash:create
  • start your application :D

If the background color does not change, uninstall the application from the phone/simulator and then start your application again.

For more details enjoy Johannes Milke's tutorial.

Husam Ebish
  • 4,893
  • 2
  • 22
  • 38
0
<?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="@color/bg" />
    
        <!-- You can insert your own image assets here -->
        <!-- <item>
            <bitmap
                android:gravity="center"
                android:src="@mipmap/launch_image" />
        </item> -->
    </layer-list>

create colors.xml in res->values and paste code:

  <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="bg">#f00000</color>
    </resources>
Genius_balu
  • 162
  • 5
0

If you've updated your colors.xml (android/app/src/main/res/values/) and both launch_background.xml (android/app/src/main/res/drawable & /drawable-v21) files and it's still not working, make sure your styles.xml (android/app/src/main/res/values/) file points to the color you want like so:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowBackground">@drawable/launch_background</item>
        <item name="android:windowSplashScreenBackground">@color/yourColor</item>
    </style>
    <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowBackground">@color/yourColor</item>
    </style>
</resources>

Sludge
  • 6,072
  • 5
  • 31
  • 43