Site icon AndroidRide

3 Flutter Container Background Color(+Gradient) Examples With Tutorial

Hi, welcome to AndroidRide!
In this post, you’ll learn how to set the background color of a Container in Flutter. Let’s dive right in!

Flutter Container Background Color – Using color property

flutter background color container
By default, Container comes with a color property. Not only property, Flutter also provides lots of default colors to make our UI better.

Container(
                  width: 200,
                  height: 80,
                  color: Colors.red,
                  child: const Center(
                    child: Text(
                      'color property',
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                ),

Container Background color with Hex Code


Container(
                  width: 200,
                  height: 80,
                  color: const Color(0xffFA8072),
                  child: const Center(
                    child: Text(
                      'Hex color code',
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                      ),
                      textAlign: TextAlign.center,
                    ),
                  ),
                ),

Background Color With Opacity


Sometimes, you don’t need fully opaque color for your container, so you can use opacity with colors to reduce the opaqueness.


Container(
                  width: 200,
                  height: 80,
                  //color: Colors.red.withOpacity(0.5),
                  color: Colors.black54,
                  child: const Center(
                    child: Text(
                      'color with opacity',
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                ),


Container(
                  width: 200,
                  height: 80,
                  color: Colors.red.withOpacity(0.5),
                  child: const Center(
                    child: Text(
                      'color with opacity',
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                ),



Background Color Using BoxDecoration


Container’s decoration property can be used to set Background color. BoxDecoration also provides color property.

Container(
                  width: 200,
                  height: 80,
                  decoration: const BoxDecoration(
                    color: Colors.yellow,
                  ),
                  child: const Center(
                    child: Text(
                      'decoration property',
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                ),

Container Background Color as Gradient

flutter container background color gradient

You can set gradient color as Container background. By using gradient, we can give our container a different look.

Exit mobile version