Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 可滚动自定义多子女布局_Flutter_Dart_Flutter Layout - Fatal编程技术网

Flutter 可滚动自定义多子女布局

Flutter 可滚动自定义多子女布局,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我无法使CustomMultiChildLayout可滚动 现在,我习惯的多孩子布局只是把孩子们排成一列。将来我会让它更复杂,但现在我想让它可以滚动。我试着把它放在列表视图中,但得到了RenderIndexedSemantics对象在布局过程中被赋予了无限大。。 我试着用IntrinsicHeight将它放在SingleChildScrollView中,但在这种情况下,它无法滚动,其高度与viewport相同 以下是一些工作不正常的示例: 返回SingleChildScrollView( 孩子:

我无法使CustomMultiChildLayout可滚动

现在,我习惯的多孩子布局只是把孩子们排成一列。将来我会让它更复杂,但现在我想让它可以滚动。我试着把它放在
列表视图
中,但得到了
RenderIndexedSemantics对象在布局过程中被赋予了无限大。
。 我试着用
IntrinsicHeight
将它放在
SingleChildScrollView
中,但在这种情况下,它无法滚动,其高度与viewport相同

以下是一些工作不正常的示例:

返回SingleChildScrollView(
孩子:内在的(
孩子:自定义多孩子布局(
代表:ViewLayoutBuilder(itemCount:cards.length),
子项:_buildChildren(上下文),
),
),
);


我所有尝试中的主要错误是,我的
CustomMultiChildLayout
给定了无限高。在其他情况下,它被裁剪到视口高度,无法滚动。

对于multichild,为什么不试试
ListView.builder
?@AndreyTurkovsky我实际上是在构建多列布局,其中按列均匀分布的子项取决于其大小。我尝试了很多不同的布局生成器,看起来
CustomMultiChildLayout
是实现这一点的唯一方法。
return ListView(
        children: <Widget>[
          CustomMultiChildLayout(
            delegate: ViewLayoutBuilder(itemCount: cards.length),
            children: _buildChildren(context),
          )
        ],
      )
class ViewLayoutBuilder extends MultiChildLayoutDelegate {
  final int itemCount;

  ViewLayoutBuilder({@required this.itemCount});

  @override
  void performLayout(Size size) {
    Offset position = Offset(0,0);
    Size firstSize = layoutChild('card_0', BoxConstraints.tightFor(width: size.width));
    positionChild('card_0', position);
    position = position.translate(0, firstSize.height);
    for (int i = 1; i < itemCount; i++) {
      final String cardId = 'card_$i';

      if (hasChild(cardId)) {
        Size newSize = layoutChild('$cardId', BoxConstraints.tightFor(width: size.width));
        positionChild('$cardId', position);
        position = position.translate(0, newSize.height);
      }
    }
  }

  @override
  bool shouldRelayout(MultiChildLayoutDelegate oldDelegate) => false;
}