【问题标题】:Flutter- Stack takes a lot of height despite the childrenFlutter- 尽管有孩子,Stack 还是需要很多高度
【发布时间】:2023-02-24 02:48:49
【问题描述】:

我正在使用 Listview.builder 来展示产品。 我使用 mediaquery 检查屏幕宽度是否足够大,然后它会使用 Grideview,如下图所示,但只有 Grideview 有问题,这超出了 Stack Height 我用 flutter devTools 检查并发现堆栈中的列正在占用它是最小尺寸那么是什么导致堆栈这么大?

child: Stack(
    children: [
      Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          // Work Image
          AspectRatio(
            aspectRatio: 16.0 / 9.0,
            child: Image.asset(
              Constants.appLogo,
              fit: BoxFit.cover,
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(
              left: Sizes.PADDING_18,
              bottom: Sizes.PADDING_8,
              right: Sizes.PADDING_8,
            ),
            // Work Title, Adress
            child: Row(
              children: [
                Flexible(
                  child: Text(
                    testAdress.length > 25
                        ? '${testAdress.substring(0, 25)}...'
                        : testAdress,
                    overflow: TextOverflow.ellipsis,
                    maxLines: 1,
                    style: const TextStyle(
                      fontWeight: FontWeight.w600,
                      fontSize: Sizes.TEXT_SIZE_22,
                    ),
                  ),
                ),
              ],
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(
              left: Sizes.PADDING_18,
              bottom: Sizes.PADDING_8,
              right: Sizes.PADDING_8,
            ),
            //SubTitle
            child: Row(
              children: [
                Flexible(
                  child: FittedBox(
                    fit: BoxFit.scaleDown,
                    alignment: Alignment.bottomLeft,
                    child: Text(
                      testAdress.length > 34
                          ? '${testAdress.substring(0, 34)}...'
                          : testAdress,
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                      style: TextStyle(
                        fontSize: Sizes.TEXT_SIZE_14,
                        color: Colors.grey.withOpacity(0.8),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
          ],
        ),
      ),
    ],
  ),

【问题讨论】:

  • 你可以用 `aspectRatio: 16.0 / 9.0,` 包装堆栈

标签: android flutter


【解决方案1】:

尝试用相同的纵横比包装堆栈小部件。

 AspectRatio(
   aspectRatio: 16.0 / 9.0,
   child: Stack(...)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-02
    • 2021-10-11
    • 1970-01-01
    • 2023-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-10
    相关资源
    最近更新 更多