Can Flutter efficiently layout nested lists?

2020-07-26 13:58发布

Can a layout like this be achieved and rendered efficiently in Flutter?

Example:

enter image description here

Yellow and blue blocks can both be around 30 elements, so I guess something like ListView.builder should be used.

I have tried nesting 2 ListView.builder, the inner with shrinkWrap = true. The yellow block is being built just when is needed, but the blue list, although it has an itemBuilder, it builds all children elements at once, causing performance problems.

new ListView.builder(
  itemCount: 20,
  itemBuilder: (BuildContext context, int blockIdx) {
    print("Building block $blockIdx");
    return new Column(
      children: [
        Padding(
          child: Text("Block $blockIdx"),
          padding: EdgeInsets.all(8.0)
        ),
        ListView.builder(
          shrinkWrap: true,
          physics: ClampingScrollPhysics(),
          itemCount: 30,
          itemBuilder: (BuildContext context, int childIdx) {
            print("Building block $blockIdx child $childIdx");
            return Padding(
              child: Text("Child $childIdx"),
              padding: EdgeInsets.only(left: 20.0, right: 8.0, top: 8.0, bottom: 8.0),
            );
          },
        );
      ],
    );
  },
);

Thanks in advance.

0条回答
登录 后发表回答