how to set box shadow in flutter

1,792

Solution 1

Use a Container widget and set the boxShadow property from its decoration property.

Code Sample

Container(
  height: 75,
  width: 150,
  decoration: BoxDecoration(
    color: Colors.white,
    borderRadius: BorderRadius.circular(12),
    boxShadow: [
      BoxShadow(
        offset: Offset(0, 1),
        blurRadius: 5,
        color: Colors.black.withOpacity(0.3),
      ),
    ],
  ),
);

Screenshot enter image description here

Try the full code on DartPad

Solution 2

You can use Container and BoxDecoration

Container(
      padding: EdgeInsets.symmetric(vertical: 1, horizontal: 8),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.3),
            offset: Offset(0, 1),
            blurRadius: 5,
            spreadRadius: 0,
          )
        ],
      ),
      child: Container(),
    );
  }
Share:
1,792
Avdienko Viktor
Author by

Avdienko Viktor

Updated on December 01, 2022

Comments

  • Avdienko Viktor
    Avdienko Viktor over 1 year

    I have a figma design and I need to set box shadow like this.

    Drop shadow
    x 0, y : 1, B: 5, S: 0, #000000 30%
    

    Drop Shadow

  • Avdienko Viktor
    Avdienko Viktor almost 3 years
    I will check and come back soon. Thank you