我的问题是,当我用具有特定大小的容器包装图像并使用 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)