在ListView项目中使用嵌套的列和行滚动jank

时间:2018-06-01 08:37:12

标签: dart flutter

此代码有问题。列表中的每个项目都是一个包含两列文本的行。即使在发布模式下,这也会导致大量性能下降。目前正在尝试为帖子构建Reddit样式布局。使用嵌套在一行中的列会大大降低性能。我的猜测是因为Row和Column的大小本身都是基于他们的孩子所以嵌套它们会增加所需的大小计算。我只是不知道如何解决这个问题。

new ListView.builder(
    controller: new ScrollController(initialScrollOffset: this.offset),
    key: new UniqueKey(),
    itemCount: this._posts != null ? this._posts.length : 0,
    itemBuilder: (BuildContext context, int i) {
      return new PostCard(
        widget._posts[i],
      );
    },
  ),

PostCard的回归如下(示例):

return new Container(
  child: new Row(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: <Widget>[
      new Column(
        children: <Widget>[
          new Text("Hello World"),
          new Text("Hello World"),
          new Text("Hello World"),
          new Text("Hello World"),
        ],
      ),
      new Column(
        children: <Widget>[
          new Text("Hello World"),
          new Text("Hello World"),
          new Text("Hello World"),
          new Text("Hello World"),
        ],
      ),
    ],
  ),
);

编辑:完整UI示例的屏幕截图。与上面的嵌套Column示例相同的jank级别。

New account can't embed, but here's my goal.

1 个答案:

答案 0 :(得分:0)

更新。在其他手机上测试,问题不存在。问题仅出在我的特定手机上(S7 Edge on 7.0)。