6

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.

9
  • Please post the code that demonstrates what you tried. Commented Jan 4, 2019 at 9:41
  • @GünterZöchbauer Updated question Commented Jan 4, 2019 at 10:06
  • I guess the inner list needs to be built to get the size for the outer list. I don't know how to fix though. Commented Jan 4, 2019 at 10:09
  • I have that suspicion also. If that is the case, is it a bug or is it expected behaviour? Commented Jan 4, 2019 at 10:19
  • There might be features that would improve behavior I don't know of. I don't have deep knowlege about layout stuff. I think it would be ok to create a Flutter bug report/feature request. Please ensure to create it with a complete but minimal single-file copy-paste runnable reproduction. Commented Jan 4, 2019 at 10:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.