Flutter card top radius is covered by Image

只愿长相守 提交于 2019-12-12 10:59:24

问题


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


回答1:


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(...),
)



回答2:


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,
            ),
          ),
        ),
        ...
      ]



回答3:


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,
            ),
          ),



来源:https://stackoverflow.com/questions/53267675/flutter-card-top-radius-is-covered-by-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!