Search code examples
flutter

How to put opacity for container in flutter


I want to put opacity for container which contain hexadecimal color code. How can it be done?

Here is my current code:

final body = Container(
  width: MediaQuery.of(context).size.width,

  margin: const EdgeInsets.only(left: 40.0, right: 40.0),
  padding: EdgeInsets.all(28.0),
   decoration: new BoxDecoration(
     color:   const Color(0xFF0E3311),//here i want to add opacity

   border: new Border.all(color: Colors.black54,
   ),
       borderRadius: new BorderRadius.only(
           topLeft: const Radius.circular(40.0),
           topRight: const Radius.circular(40.0),
       bottomLeft: const Radius.circular(40.0),
       bottomRight:const Radius.circular(40.0) )
),

  child: Column(
    children: <Widget>[ email, password,loginButton],
  ),
);

Solution

  • Change the line

    const Color(0xFF0E3311)
    

    to

    const Color(0xFF0E3311).withOpacity(0.5)
    

    or any value you want.