【问题标题】:Image height is not changing图像高度不变
【发布时间】:2021-12-17 14:19:33
【问题描述】:

我正在尝试更改图像高度,但它没有改变。

这是我的代码

 ListTile(
     
          leading: ClipRRect(
            borderRadius: BorderRadius.circular(10.0),
            child: Image.network(
              book.urlImage,
              fit: BoxFit.cover,
              width: 55,
              height: 90,
            ),
          ),

【问题讨论】:

标签: image flutter listtile


【解决方案1】:

默认情况下,ListTile's 的最大前导小部件高度为 56 像素。

这是ListTile的源码,

final Offset baseDensity = visualDensity.baseSizeAdjustment;
if (isOneLine)
  return (isDense ? 48.0 : 56.0) + baseDensity.dy;
if (isTwoLine)
  return (isDense ? 64.0 : 72.0) + baseDensity.dy;
return (isDense ? 76.0 : 88.0) + baseDensity.dy;

您可以查看每个条件的前导小部件的最大高度。 90px 是不可能的。如果 90px 是您想要的,那么请考虑使用 Row 和 Column 制作自己的 ListTile。

【讨论】:

  • 哦,我明白了!谢谢你告诉我
【解决方案2】:

您是否尝试过将 Listtile 放入容器中?

这样-->

Container(
        width: 100,
        height: 100,
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage(
             'assets/horoscopes/${horoscope.toLowerCase()}.png'),
          ),
          borderRadius: const BorderRadius.all(
            Radius.circular(25.0),
          ),
        ),
      ),

【讨论】:

  • 是的,但这不起作用!
【解决方案3】:

在 SizedBox 子中设置您的图像

SizedBox(
  width: 50,
  height: 90,
  child: Image.network( 
     book.urlImage, 
     fit: BoxFit.cover,
  ),
)

【讨论】:

  • 那不行!
【解决方案4】:

试试下面的代码希望对你有帮助。

 ListTile(
            leading: Container(
              width: 150.0,
              height: 100.0,
              decoration: BoxDecoration(
                border: Border.all(
                  color: Colors.grey.shade500,
                ),
                image: DecorationImage(
                  image: NetworkImage(
                    'https://tech.pelmorex.com/wp-content/uploads/2020/10/flutter.png',
                  ),
                ),
                //shape: BoxShape.circle,
              ),
            ),
          ),

您的结果屏幕->

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    • 1970-01-01
    • 2014-12-21
    • 2022-01-20
    • 2021-10-25
    • 1970-01-01
    相关资源
    最近更新 更多