add custom boxshadow to Flutter card

2019-05-03 04:35发布

问题:

I've implemented cards in a Flutter app. I need a custom BoxShadow for every card. How can this be done?

What I've tried so far is to add the BoxShadow property to the Card() constructor, which is not working...

回答1:

The Card Widget doesn't have decoration property so you need to make a card inside a Container and then apply the BoxShadow to the Container,

Sample :

class mycard extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Container(
      child: new Card(
        child: new Center(
          child: new Icon(
            Icons.refresh,
            size: 150.0,
          ),
        ),
      ),
      decoration: new BoxDecoration(boxShadow: [
        new BoxShadow(
          color: Colors.black,
          blurRadius: 20.0,
        ),
      ]),
    );
  }
}