How to create a transparent container in flutter

3,808

Solution 1

try wrapping it inside the Opacity Widget

Opacity(
  opacity: 0.5,
  child: Container(child: Column(
    children: [
             Container(child: Text('Address: '), alignment: Alignment.centerLeft,),
             Divider(color: Colors.grey,),
             Container(child: Text('$address'), alignment: Alignment.centerLeft,),
             ],
            ),
   color: Color(0xFF005D),
   ),
)

Solution 2

Try using Colors.transparent + withOpacity for Container.

Container(
  color: Colors.transparent.withOpacity(0.5),
  child: Column(
    children: [
      Container(
        child: Text('Address: '),
        alignment: Alignment.centerLeft,
      ),
      Divider(
        color: Colors.grey,
      ),
      Container(
        child: Text('$address'),
        alignment: Alignment.centerLeft,
      ),
   ],
),
Share:
3,808
shalu j
Author by

shalu j

Updated on December 27, 2022

Comments

  • shalu j
    shalu j over 1 year

    I want to make a container transparent like this: enter image description here

    Here's the container code:

    : Container(child: Column(
        children: [
                 Container(child: Text('Address: '), alignment: Alignment.centerLeft,),
                 Divider(color: Colors.grey,),
                 Container(child: Text('$address'), alignment: Alignment.centerLeft,),
                 ],
                ),
       color: Color(0xFF005D6C),
       );
    

    If I give color: Color(0xFF005D6C).withOpacity(0.5) then, it is just making the color light like this enter image description here

    How can I make the container transparent?

  • shalu j
    shalu j over 3 years
    Now the container's background color is not coming.
  • pedro pimont
    pedro pimont over 3 years
    do you have some kind of image in the background? because if you just have a white background below, the color will just appear to be lighter
  • shalu j
    shalu j over 3 years
    Currently, I don't have any background image.
  • pedro pimont
    pedro pimont over 3 years
    So thats probably the problem... Try adding something to the background and it'll be easier to se if your container got transparent
  • shalu j
    shalu j over 3 years
    I have given white color to the background, So, if I am giving green color to the container with some opacity, it should make the container transparent