0

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

Nimit Goyal
  • 149
  • 2
  • 7
  • 1
    what is scrollItem?? – Darish Feb 01 '20 at 05:49
  • it is my widget which returns a Container. I made it a function so that I don't have to write it again and again @Darish ```Container scrollItem( double width, Color backColor, Color boundaryColor, String stText) { return Container( height: 30, width: width, decoration: BoxDecoration( color: backColor, border: Border.all(color: boundaryColor, width: .5)), child: Center( child: Text( stText, style: TextStyle(fontSize: 12, color: Colors.black), ), ), ); }``` – Nimit Goyal Feb 01 '20 at 06:27

1 Answers1

0

After 2 days of research, I finally got the answer to this. 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(
                    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()
                                          : '-'),
                                ],
                              );
                            }),
                      ),
                    ),
                  )
Nimit Goyal
  • 149
  • 2
  • 7