Search code examples
flutterflutter-layout

Shadow Effect only to the left of a card In flutter?


So here is the output image which I wanted to achieve.

Output Image

and this is the result that I have achieved.

So you can see the shadow effect is in the left and slowly fading towards right. here is my code for this

Container(
     width: MediaQuery.of(context).size.width * 0.45,
     height: MediaQuery.of(context).size.height * 0.15,
     decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(20)
                              ),
     child: Card(
                 elevation: 5,
                ),
          ),


So elevation provides me with shadow but only towards bottom but I want it to be on the left to right fading... any way to achieve this?

Thanks.


Solution

  • Try the following code:

        Container(
          width: MediaQuery.of(context).size.width * 0.45,
          height: MediaQuery.of(context).size.height * 0.15,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(20),
            boxShadow: [
              BoxShadow(
                color: Colors.grey.withOpacity(0.5),
                spreadRadius: 5,
                blurRadius: 7,
                offset: const Offset(-7.5, 7.5),
              ),
            ],
          ),
          child: Card(),
        ),