Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter card top radius is covered by Image

When I add a image to the card, the Radius at the top of the card are covered. How can I solve it?

When I add a image to the card, the Radius at the top of the card are covered. How can I solve it?

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(primarySwatch: Colors.yellow),
      home: Scaffold(
          backgroundColor: Colors.grey[200],
          appBar: AppBar(title: Text('Demo'),),
          body: SizedBox(
              height: 310.0,
              child: Card(
                elevation: 3.0,
                color: Colors.white,
                margin: EdgeInsets.all(8.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    SizedBox(height: 0.0,),
                    Image.network('https://img.zcool.cn/community/012157578c405f0000012e7e69e7cd.jpg@1280w_1l_2o_100sh.jpg'),
                    SizedBox(height: 16.0,),
                    Row(
                      children: <Widget>[
                        SizedBox(width: 16.0,),
                        Text('素雪', style: Theme.of(context).textTheme.headline,),
                        SizedBox(width: 16.0,),
                        Text('吉时已到', style: Theme.of(context).textTheme.subhead,),
                      ],
                    ),
                    SizedBox(height: 16.0,),
                  ],
                ),
              ))),
    );
  }
}

This is the rendering

enter image description here

like image 675
zhengliang Avatar asked Nov 12 '18 18:11

zhengliang


People also ask

How do you give Card border radius in Flutter?

You can set the shape property to RoundedRectangleBorder() or CircleBorder() in order to create a circle Card. If you use RoundedRectangleBorder, the key point here is to increase the border radius to a large number, at least half the width of the Card's child.


3 Answers

You can set clipBehavior for Card:

Card(
      clipBehavior: Clip.antiAliasWithSaveLayer, ...

Or you can wrap your image in ClipRRect

ClipRRect(
  borderRadius: BorderRadius.vertical(top: Radius.circular(4.0)),
  child: Image.network(...),
)
like image 78
Andrey Turkovsky Avatar answered Oct 19 '22 02:10

Andrey Turkovsky


You need to put your image in a Container or a DecoratedBox and set the BorderRadius on the BoxDecoration.

     children: <Widget>[
        .....
        Container(
          width: double.maxFinite,
          height: 220.0,
          decoration: BoxDecoration(
            borderRadius:
                BorderRadius.vertical(top: Radius.circular(5.0)),
            image: DecorationImage(
              image: NetworkImage(
                  'https://img.zcool.cn/community/012157578c405f0000012e7e69e7cd.jpg@1280w_1l_2o_100sh.jpg'),
            fit: BoxFit.cover,
            ),
          ),
        ),
        ...
      ]
like image 26
chemamolins Avatar answered Oct 19 '22 00:10

chemamolins


You can put the image in Material and set the Border Radius and Clip Behaviour.

    Material(
            color: Colors.white,
            borderRadius: BorderRadius.circular(10.0),
            elevation: 2.0,
            clipBehavior: Clip.antiAliasWithSaveLayer,
            type: MaterialType.transparency,
            child: Image.asset(
              "images/user.png",
              height: 150,
              width: double.infinity,
              fit: BoxFit.cover,
            ),
          ),

Refer this Image

like image 23
MOhan Avatar answered Oct 19 '22 01:10

MOhan