小编Pay*_*edi的帖子

如何在 flutter 中使用 BoxFit.contain 圆化图像角

我的问题是,当我用具有特定大小的容器包装图像并使用 BoxFit.contain 属性时,它不会舍入图像。查看下图: 图片链接
我认为图像不能自行变圆,因为它不能扩展以填充容器。我知道我可以使用 BoxFit.cover,但我想使用 BoxFit.contain,因为我的空间和图像可以是任何尺寸。我的代码:

@override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey,
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Container(
          color: Colors.red,
          height: 300,
          width: 300,
          child: ClipRRect(
            borderRadius: BorderRadius.circular(16),
            child: Image.network(
              'https://i.ytimg.com/vi/fq4N0hgOWzU/maxresdefault.jpg',
              fit: BoxFit.contain,
            ),
          ),
        ),
      ),

    );
  }
Run Code Online (Sandbox Code Playgroud)

image flutter flutter-layout

8
推荐指数
1
解决办法
9007
查看次数

标签 统计

flutter ×1

flutter-layout ×1

image ×1