How to implement Nested ListView in Flutter?

后端 未结 6 1922
我寻月下人不归
我寻月下人不归 2020-12-08 05:00

What is the preferred way to achieve a nested ListView, or in other words, ListView Widgets that could be included within a scrollable parent?

Imagine a \"Reports\"

6条回答
  •  不思量自难忘°
    2020-12-08 05:19

    Adding physics: ClampingScrollPhysics() and shrinkWrap: true did the trick for me.

    sample code:

    @override
    Widget build(BuildContext context) {
      return Container(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Expanded(
              child: ListView.builder(
                  shrinkWrap: true,
                  itemCount: 123,
                  itemBuilder: (BuildContext context, int index) {
                    return Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text('Parent'),
                        ListView.builder(
                            itemCount: 2,
                            physics: ClampingScrollPhysics(), 
                            shrinkWrap: true,
                            itemBuilder: (BuildContext context, int index) {
                              return Text('Child');
                            }),
                      ],
                    );
                  }),
            )
          ],
        ),
      );
    }
    

提交回复
热议问题