我正在使用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",
     ),
    ),
   ),
 );

其他回答

使用ClipRRect它将完美地工作。

ClipRRect(
    borderRadius: BorderRadius.circular(8.0),
    child: Image.network(
        subject['images']['large'],
        height: 150.0,
        width: 100.0,
    ),
)

试试这个,效果不错。

Container(
  height: 220.0,
  width: double.infinity,
  decoration: BoxDecoration(
    borderRadius: new BorderRadius.only(
      topLeft: Radius.circular(10),
       topRight: Radius.circular(10),
    ),
    image: DecorationImage(
      fit: BoxFit.fill,
      image: NetworkImage(
        photoUrl,
      ),
     ),
   ),
);

输出:

使用BoxDecoration

Container(
              margin: EdgeInsets.all(8),
              width: 86,
              height: 86,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                image: DecorationImage(
                    image: NetworkImage('https://i.stack.imgur.com/0VpX0.png'),
                    fit: BoxFit.cover
                ),
              ), 
           ),

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,但这会使答案有点太长。

试试这个,对我很有效:

Container(
  width: 100.0,
  height: 150.0,
  decoration: BoxDecoration(
    image: DecorationImage(
        fit: BoxFit.cover, image: NetworkImage('Path to your image')),
    borderRadius: BorderRadius.all(Radius.circular(8.0)),
    color: Colors.redAccent,
  ),
),