首页 > 解决方案 > 容器以匹配来自 url 的图像高度

问题描述

我正在尝试拥有一个具有动态高度的灵活容器。我试图从容器中删除高度,但图像消失了。

这就是我现在拥有的固定高度

          Container(
            width: MediaQuery.of(context).size.width,
            height: 400,
            decoration: BoxDecoration(
              color: Colors.white,
              image: DecorationImage(
                fit: BoxFit.contain,
                image: NetworkImage(article.imageSrc),
              ),
            ),
          ),

标签: flutter

解决方案


尝试这个

Container(
            width: MediaQuery.of(context).size.width,       
            child: Image.network(article.imageSrc),
          ),

推荐阅读