首页 > 解决方案 > 颤动的 ImageAsset 图像延伸到 BoxDecoration 容器之外

问题描述

当我从 CachedNetworkImageProvider 获取图像时,我在 BoxDecoration 中有图像,但是当我从 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])...

在此处输入图像描述

标签: imageflutter

解决方案


使用以下示例

decoration: BoxDecoration(

                image: DecorationImage(
                  alignment: Alignment.center,
                  matchTextDirection: true,
                  repeat: ImageRepeat.noRepeat,
                  image: AssetImage("assets/images/bed.jpg"),
                ))

推荐阅读