我正在使用Flutter制作关于电影的信息列表。现在我想在左边的封面图像是一个圆角图片。我做了下面的事情,但是没有用。谢谢!

    getItem(var subject) {
    var row = Container(
      margin: EdgeInsets.all(8.0),
      child: Row(
        children: <Widget>[
          Container(
            width: 100.0,
            height: 150.0,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(8.0)),
              color: Colors.redAccent,
            ),
            child: Image.network(
              subject['images']['large'],
              height: 150.0,
              width: 100.0,
            ),
          ),
        ],
      ),
    );
    return Card(
      color: Colors.blueGrey,
      child: row,
    );
  }

如下


当前回答

图片所有侧面圆角尝试这一个

Container(
 // height and width depend on your your requirement.
 height: 220.0,
 width: double.infinity,
 decoration: BoxDecoration(
   // radius circular depend on your requirement
   borderRadius: new BorderRadius.all(
    Radius.circular(10),
    ),
    image: DecorationImage(
    fit: BoxFit.fill,
     // image url your network image url       
      image: NetworkImage(
       "dynamic image url",
     ),
    ),
   ),
 );

其他回答

1. 圆形图像(无边框)

使用CircleAvatar: CircleAvatar ( radius: 48, //图像半径 分辨率:NetworkImage(“imageUrl”), ) 使用ClipRRect: ClipOval ( 孩子:SizedBox.fromSize ( size: size . fromradius(48), //图像半径 child: Image.network('imageUrl', fit: BoxFit.cover), ), )


2. 圆形图像(带边框)

Using CircleAvatar: CircleAvatar( radius: 56, backgroundColor: Colors.red, child: Padding( padding: const EdgeInsets.all(8), // Border radius child: ClipOval(child: Image.network('imageUrl')), ), ) Using ClipRRect: Container( padding: EdgeInsets.all(8), // Border width decoration: BoxDecoration(color: Colors.red, shape: BoxShape.circle), child: ClipOval( child: SizedBox.fromSize( size: Size.fromRadius(48), // Image radius child: Image.network('imageUrl', fit: BoxFit.cover), ), ), )


3.圆角图像(无边框)

ClipRRect(
  borderRadius: BorderRadius.circular(20), // Image border
  child: SizedBox.fromSize(
    size: Size.fromRadius(48), // Image radius
    child: Image.network('imageUrl', fit: BoxFit.cover),
  ),
)

4. 圆角图像(带边框)

final borderRadius = BorderRadius.circular(20); // Image border

Container(
  padding: EdgeInsets.all(8), // Border width
  decoration: BoxDecoration(color: Colors.red, borderRadius: borderRadius),
  child: ClipRRect(
    borderRadius: borderRadius,
    child: SizedBox.fromSize(
      size: Size.fromRadius(48), // Image radius
      child: Image.network('imageUrl', fit: BoxFit.cover),
    ),
  ),
)

还有其他方法,如使用DecoratedBox,但这会使答案有点太长。

你也可以使用附带颤振的CircleAvatar

CircleAvatar(
  radius: 20,
  backgroundImage: NetworkImage('https://via.placeholder.com/140x100')
)

试试这个,用CircleAvatar和CachedNetworkImage加载图像。

CircleAvatar(
  radius: 45,
  child: ClipOval(
    child: CachedNetworkImage(
      imageUrl:  "https:// your image url path",
      fit: BoxFit.cover,
      width: 80,
      height: 80,
    ),
  ),
),

如果你也想要边框,然后添加

backgroundColor: Colors.deepOrangeAccent,

在这个

CircleAvatar(
  radius: 45,
  backgroundColor: Colors.deepOrangeAccent,
  child: ClipOval(
    child: CachedNetworkImage(
      imageUrl: "https:// your image url path",
      fit: BoxFit.cover,
      width: 80,
      height: 80,
    ),
  ),
),

图片所有侧面圆角尝试这一个

Container(
 // height and width depend on your your requirement.
 height: 220.0,
 width: double.infinity,
 decoration: BoxDecoration(
   // radius circular depend on your requirement
   borderRadius: new BorderRadius.all(
    Radius.circular(10),
    ),
    image: DecorationImage(
    fit: BoxFit.fill,
     // image url your network image url       
      image: NetworkImage(
       "dynamic image url",
     ),
    ),
   ),
 );

使用ClipRRect,设置图像属性fit: BoxFit.fill

ClipRRect(
          borderRadius: new BorderRadius.circular(10.0),
          child: Image(
            fit: BoxFit.fill,
            image: AssetImage('images/image.png'),
            width: 100.0,
            height: 100.0,
          ),
        ),