Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to set background color to Container in Flutter

I am using the below code to set the background color as black to the container, but it's not showing.

       Align(
            alignment: Alignment.bottomCenter,
            child: Container(
              color: Colors.black,
              margin: EdgeInsets.only(left: 20, right: 20, bottom: 20, top: 10),
              height: 40,
              width: double.infinity,
              child: RaisedButton(
                textColor: Colors.white,
                color: Colors.blue[300],
                onPressed: () => null,
                child: Text('Next'),
              ),
             ),
          )

Output:

enter image description here

Can somebody please help me?

like image 242
Jitesh Mohite Avatar asked Oct 26 '25 14:10

Jitesh Mohite


2 Answers

Easy solution: Wrap it inside container and give it color property.

Container(
            color: Colors.black,
            child: Align(
              alignment: Alignment.bottomCenter,
              child: Container(
                margin: EdgeInsets.only(left: 20, right: 20, bottom: 20, top: 10),
                height: 40,
                width: double.infinity,
                child: RaisedButton(
                  textColor: Colors.white,
                  color: Colors.blue[300],
                  onPressed: () => null,
                  child: Text('Next'),
                ),
              ),
            ),
          )
like image 61
Jitesh Mohite Avatar answered Oct 28 '25 03:10

Jitesh Mohite


I think the problem is that the RaisedButton gets the size of the Container and that's why you are not seeing any black colour. As NetanZaf suggested, You can use a padding so RaisedButton will not get the container size and you will see a black colour.

This This is the result of the following code:

Align(
        alignment: Alignment.bottomCenter,
        child: Container(
          color: Colors.black,
          margin: EdgeInsets.only(left: 20, right: 20, bottom: 20, top: 10),
          padding : EdgeInsets.only(left: 10, right: 10, bottom: 10, top: 10),
          height: 40,
          width: double.infinity,
          child: RaisedButton(
            textColor: Colors.white,
            color:Colors.blue[300],
            onPressed: () => null,
            child: Text('Next'),
          ),
         ),
      ),

You can change the values to get the result you want

like image 32
Morez Avatar answered Oct 28 '25 04:10

Morez