我在BoxDecoration中有一个Image,当我从CachedNetworkImageProvider获取图像时,它可以工作,但是当我从Assetimage获取图像时,该图像没有被裁剪到盒子的大小。这两个图像源都显示在ListTile中。 来自AssetImage的代码:
return Container(
width: widget.width,
height: widget.heigth,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color:widget.colour, width:3),
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(url)
)....
来自CachedNetworkImageProvider的代码:
return Container(
width: widget.width,
height: widget.heigth,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color:widget.colour, width:3),
image: DecorationImage(
fit: BoxFit.cover,
image: CachedNetworkImageProvider(widget.location.imageURLs[widget.index])...
答案 0 :(得分:0)
不是将其作为boxDecoration.image的属性,而是尝试将其设置为child?
return Container(
child: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(url)
)....
width: widget.width,
height: widget.heigth,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color:widget.colour, width:3)),
答案 1 :(得分:0)
尝试一下
calculate_score
答案 2 :(得分:0)
使用以下示例
decoration: BoxDecoration(
image: DecorationImage(
alignment: Alignment.center,
matchTextDirection: true,
repeat: ImageRepeat.noRepeat,
image: AssetImage("assets/images/bed.jpg"),
))