I am trying to add a shadow to only the right side of of my container widget using the boxShadow parameter in the BoxDecoration widget.
new Container( decoration: BoxDecoration( color: Colors.grey.withOpacity(0.5), boxShadow: [ BoxShadow( blurRadius: 5.0 ), ], ), ),
This code works but adds a shadow to every possible side of the container. I would like to have it only be on the right side.
Box-Shadow on One Side In order to create a shadow that would, in theory, have a light source coming from a singular point, the shadow would need to only exist on one side of the box. For instance, the bottom of the box. When creating a box-shadow on one side only, we have to focus on the last value, the spread radius.
new Container( decoration: BoxDecoration( color: Colors. grey. withOpacity(0.5), boxShadow: [ BoxShadow( blurRadius: 5.0 ), ], ), ), This code works but adds a shadow to every possible side of the container.
Simply apply the following CSS to the element in question: box-shadow: 0 0 Xpx Ypx [hex/rgba]; /* note 0 offset values */ clip-path: inset(Apx Bpx Cpx Dpx); Where: Apx sets the shadow visibility for the top edge.
How to add a box shadow to only one side of an element? To apply a shadow effect only on one side of an element set the blur value to a positive number and set the spread value to the same size but with a negative sign. Depending on which side you want the shadow on, set the offset value as follows:
To apply a shadow effect only on one side of an element set the blur value to a positive number and set the spread value to the same size but with a negative sign. Depending on which side you want the shadow on, set the offset value as follows: Share "How to add a box shadow to only one side of an element?"
While making beautiful UI, the box-shadow property is very important during designing. See the example below and learn how to apply a box-shadow on the Container widget of Flutter. To apply box shadow, use the following code: BoxShadow(color: Colors.grey.withOpacity(0.5), spreadRadius: 5, blurRadius: 7, offset: Offset(0, 2),)
Probably, the best way is using the CSS box-shadow property with the “inset” value. Also, use the :before and :after pseudo-elements, which are absolutely positioned on the right and left sides of the element. Let’s see another example without the :before and :after pseudo-elements.
You can set the offset
property of BoxShadow
. It is defined as Offset(double dx, double dy)
. So, for example:
boxShadow: [ BoxShadow( blurRadius: 5.0, offset: Offset(3.0, 0), ), ],
This will cast a shadow only at 3 units to the right (dx
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With