【问题标题】:RenderFlex error in flutter after a stateful widget is called inside a singlechildscrollview column在 singlechildscrollview 列中调用有状态小部件后,颤动中的 RenderFlex 错误
【发布时间】:2020-12-24 02:57:37
【问题描述】:

这是显示喜欢的点赞小部件。它在另一个 dart 文件的滚动视图列中调用。在添加此小部件之前一切正常

     @override
      Widget build(BuildContext context) {
        return Container(
          height: 100,
          child: Row(
            children: <Widget>[
              Expanded(
                child: ListTile(
                  leading: IconButton(
                    icon: likedByReader
                        ? Icon(Icons.favorite, color: Colors.orange)
                        : Icon(Icons.favorite, color: Colors.grey),
                    onPressed: _pressed,
                  ),
                ),
              ),
              Expanded(
                child: Text('${likesList.length} likes'),
              )
            ],
          ),
        );
      }

这就是 LikeWidget 的调用方式

Expanded(child: LikeWidget(widget.readerEmail, widget.blogUIDInFirebase),),

控制台显示错误

RenderFlex children have non-zero flex but incoming height constraints are unbounded.

RenderBox was not laid out: _RenderSingleChildViewport#89f28 relayoutBoundary=up10 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1694 pos 12: 'hasSize'

【问题讨论】:

    标签: flutter


    【解决方案1】:

    您不能在 SingleChildScrollView 中使用 Expanded。因为 SingleChildScrollView 有特殊的约束并且 Expanded 它期望在 Column 或 Row 中使用。 有一个类似的问题here,基本上你应该为此进行条件渲染,当内容高度小于父高度时返回一列,当内容不适合时返回滚动视图。为此我将使用 LayoutBuilder,但使用 CustomScrollView seems to be more performant 检查该问题的答案。

    【讨论】:

      猜你喜欢
      • 2023-03-17
      • 2019-10-06
      • 2017-12-19
      • 1970-01-01
      • 2018-08-07
      • 2020-08-06
      • 1970-01-01
      • 1970-01-01
      • 2018-10-27
      相关资源
      最近更新 更多