颤振卡的顶部半径被图像覆盖

zhe*_*ang 5 flutter flutter-layout

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

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

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,),
                  ],
                ),
              ))),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

这是渲染

在此处输入图片说明

And*_*sky 14

您可以clipBehavior为卡设置:

Card(
      clipBehavior: Clip.antiAliasWithSaveLayer, ...
Run Code Online (Sandbox Code Playgroud)

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

ClipRRect(
  borderRadius: BorderRadius.vertical(top: Radius.circular(4.0)),
  child: Image.network(...),
)
Run Code Online (Sandbox Code Playgroud)

  • 对于小边框半径,最好使用 `clipBehavior: Clip.hardEdge`,因为它**比其他剪切模式更快、性能更好**。 (2认同)

che*_*ins 6

您需要将图片放在a Container或a中,DecoratedBox然后在BorderRadius上设置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,
            ),
          ),
        ),
        ...
      ]
Run Code Online (Sandbox Code Playgroud)


小智 5

您可以将图像放入Material并设置Border RadiusClip 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,
            ),
          ),
Run Code Online (Sandbox Code Playgroud)

参考这张图片