首页 > 解决方案 > Flutter 卡顶半径被 Image 覆盖

问题描述

当我向卡片添加图像时,卡片顶部的半径被覆盖。我该如何解决?

当我向卡片添加图像时,卡片顶部的半径被覆盖。我该如何解决?

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,),
                  ],
                ),
              ))),
    );
  }
}

这是渲染图

在此处输入图像描述

标签: flutterflutter-layout

解决方案


您可以clipBehavior为卡设置:

Card(
      clipBehavior: Clip.antiAliasWithSaveLayer, ...

或者您可以将图像包装在ClipRRect

ClipRRect(
  borderRadius: BorderRadius.vertical(top: Radius.circular(4.0)),
  child: Image.network(...),
)

推荐阅读