如何从上一个列表停止的地方开始 ListView.builder 中的 itemCount?

How to Start itemCount in ListView.builder from where previous list left off?

我有 2 行 Listview 构建器(可水平滚动)显示兴趣。

希望第一行显示前 6 个兴趣,下一行显示列表中的其余部分。

如何使第二个中的 itemCount 范围从 7 一直到最后?

感谢任何帮助。代码片段如下:

Padding(
                      padding: const EdgeInsets.fromLTRB(6, 6, 0, 0),
                      child: Container(
                        width: MediaQuery.of(context).size.width,
                        height: MediaQuery.of(context).size.height * 0.045,
                        child: ListView.builder(
                            shrinkWrap: true,
                            scrollDirection: Axis.horizontal,
                            padding: const EdgeInsets.all(1),
                            itemCount: 6,
                            itemBuilder: (context, int index) {
                              return Interests2(AvailableInterestChosen(
                                allInterests[index],
                                isChosen: false,
                              ));
                            }),
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.fromLTRB(6, 3, 0, 0),
                      child: Container(
                        width: MediaQuery.of(context).size.width,
                        height: MediaQuery.of(context).size.height * 0.045,
                        child: ListView.builder(
                            shrinkWrap: true,
                            scrollDirection: Axis.horizontal,
                            padding: const EdgeInsets.all(1),
                            **// itemCount: allInterests range from 6 to end of list,**
                            itemBuilder: (context, int index) {
                              return Interests2(AvailableInterestChosen(
                                allInterests[index],
                                isChosen: false,
                              ));
                            }),
                      ),
                    ),
...

第二个填充中的粗体部分是我在构建范围时遇到的问题。

作为第二个列表视图的参数,您可以使用 allInterests.size()-6 作为项目计数,使用索引 + 6 作为访问所有兴趣列表的索引。

第二部分:

                Padding(
                  padding: const EdgeInsets.fromLTRB(6, 3, 0, 0),
                  child: Container(
                    width: MediaQuery.of(context).size.width,
                    height: MediaQuery.of(context).size.height * 0.045,
                    child: ListView.builder(
                        shrinkWrap: true,
                        scrollDirection: Axis.horizontal,
                        padding: const EdgeInsets.all(1),
                        **// itemCount: allInterests range from 6 to end of list,**
                        itemBuilder: (context, int index) {
                          int newIndex = index + 6;
                          return Interests2(AvailableInterestChosen(
                            allInterests[newIndex],
                            isChosen: false,
                          ));
                        }),
                        itemCount: allInterests.length - 6
                  ),
                ),

您可以像那样调用 listview.builder 中的第二个列表视图

ListView.builder(
                            shrinkWrap: true,
                            scrollDirection: Axis.horizontal,
                            padding: const EdgeInsets.all(1),
                           
                            itemBuilder: (context, int index) {
                              return Interests2(AvailableInterestChosen(
                                allInterests[6+index],
                                isChosen: false,
                              ));