简体   繁体   English

用于一起滚动 Flutter 的水平列表视图列表

[英]List of Horizontal List view to scroll together Flutter

I want to create a vertical list of a horizontal list view.我想创建一个水平列表视图的垂直列表。 I have achieved it using this .我已经使用这个实现了它。 But my issue is that each item is scrolling separately horizontally and I don't want that.但我的问题是每个项目都单独水平滚动,我不想要那样。 I need that complete recycler view scrolls horizontally together.我需要完整的回收器视图水平滚动在一起。 This is the code I'm using.这是我正在使用的代码。

ListView.builder(
                itemCount: memberItemArray.length,
                shrinkWrap: true,
                itemBuilder: (BuildContext context, int index) {
                  return SingleChildScrollView(
                    scrollDirection: Axis.horizontal,
                    child: Row(
                      children: <Widget>[
                        scrollItem(
                            75,
                            const Color(0x00FFFFFF),
                            const Color(0x50000000),
                            memberItemArray[index].sID),
                        scrollItem(
                            200,
                            const Color(0x00FFFFFF),
                            const Color(0x50000000),
                            memberItemArray[index].sName),
                        scrollItem(
                            150,
                            const Color(0x00FFFFFF),
                            const Color(0x50000000),
                            memberItemArray[index].sMobile),
                        scrollItem(
                            150,
                            const Color(0x00FFFFFF),
                            const Color(0x50000000),
                            memberItemArray[index].sPlan != null &&
                                memberItemArray[index].sPlan !=
                                    'null' &&
                                memberItemArray[index].sPlan != ''
                                ? memberItemArray[index].sPlan
                                : '-'),
                        scrollItem(
                            150,
                            const Color(0x00FFFFFF),
                            const Color(0x50000000),
                            memberItemArray[index].sExpDate != null &&
                                memberItemArray[index].sExpDate !=
                                    'null' &&
                                memberItemArray[index].sExpDate !=
                                    ''
                                ? memberItemArray[index].sExpDate
                                : '-'),
                        scrollItem(
                            100,
                            const Color(0x00FFFFFF),
                            const Color(0x50000000),
                            memberItemArray[index].sAmount != null &&
                                memberItemArray[index]
                                    .sAmount
                                    .toString() !=
                                    'null' &&
                                memberItemArray[index]
                                    .sAmount
                                    .toString() !=
                                    ''
                                ? memberItemArray[index]
                                .sAmount
                                .toString()
                                : '-'),
                        scrollItem(
                            100,
                            const Color(0x00FFFFFF),
                            const Color(0x50000000),
                            memberItemArray[index].sDue != null &&
                                memberItemArray[index]
                                    .sDue
                                    .toString() !=
                                    'null' &&
                                memberItemArray[index]
                                    .sDue
                                    .toString() !=
                                    ''
                                ? memberItemArray[index]
                                .sDue
                                .toString()
                                : '-'),
                      ],
                    ),
                  );
                })

Any Help or suggestions are welcomed欢迎任何帮助或建议

After 2 days of research, I finally got the answer to this.经过2天的研究,我终于得到了这个答案。 Simply use SingleChildScrollView as a parent giving scroll direction as horizontal and its child will be a sized box whose width will be static as I already know the width of the list view, and inside this sized box, we can directly use the ListView.Builder and child of this ListView.Builder will be simple Row只需使用SingleChildScrollView作为父级,将滚动方向设置为水平,其子级将是一个宽度静态的大小框,因为我已经知道列表视图的宽度,在这个大小的框内,我们可以直接使用 ListView.Builder 和这个 ListView.Builder 的孩子将是简单的Row

SingleChildScrollView(
                    scrollDirection: Axis.horizontal,
                    child: Container(
                      margin: EdgeInsets.only(left: 5, right: 5),
                      child: SizedBox(
                        width: 975,
                        child: ListView.builder(
                            itemCount: memberItemArray.length,
                            shrinkWrap: true,
                            itemBuilder: (BuildContext context, int index) {
                              return Row(
                                children: <Widget>[
                                  scrollItem(
                                      75,
                                      const Color(0x00FFFFFF),
                                      const Color(0x50000000),
                                      memberItemArray[index].sID),
                                  scrollItem(
                                      200,
                                      const Color(0x00FFFFFF),
                                      const Color(0x50000000),
                                      memberItemArray[index].sName),
                                  scrollItem(
                                      150,
                                      const Color(0x00FFFFFF),
                                      const Color(0x50000000),
                                      memberItemArray[index].sMobile),
                                  scrollItem(
                                      150,
                                      const Color(0x00FFFFFF),
                                      const Color(0x50000000),
                                      memberItemArray[index].sPlan != null &&
                                              memberItemArray[index].sPlan !=
                                                  'null' &&
                                              memberItemArray[index].sPlan != ''
                                          ? memberItemArray[index].sPlan
                                          : '-'),
                                  scrollItem(
                                      150,
                                      const Color(0x00FFFFFF),
                                      const Color(0x50000000),
                                      memberItemArray[index].sExpDate != null &&
                                              memberItemArray[index].sExpDate !=
                                                  'null' &&
                                              memberItemArray[index].sExpDate !=
                                                  ''
                                          ? memberItemArray[index].sExpDate
                                          : '-'),
                                  scrollItem(
                                      100,
                                      const Color(0x00FFFFFF),
                                      const Color(0x50000000),
                                      memberItemArray[index].sAmount != null &&
                                              memberItemArray[index]
                                                      .sAmount
                                                      .toString() !=
                                                  'null' &&
                                              memberItemArray[index]
                                                      .sAmount
                                                      .toString() !=
                                                  ''
                                          ? memberItemArray[index]
                                              .sAmount
                                              .toString()
                                          : '-'),
                                  scrollItem(
                                      100,
                                      const Color(0x00FFFFFF),
                                      const Color(0x50000000),
                                      memberItemArray[index].sDue != null &&
                                              memberItemArray[index]
                                                      .sDue
                                                      .toString() !=
                                                  'null' &&
                                              memberItemArray[index]
                                                      .sDue
                                                      .toString() !=
                                                  ''
                                          ? memberItemArray[index]
                                              .sDue
                                              .toString()
                                          : '-'),
                                ],
                              );
                            }),
                      ),
                    ),
                  )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM