List of Horizontal List view to scroll together Flutter

前端 未结 1 1327
情话喂你
情话喂你 2021-01-27 07:26

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

相关标签:
1条回答
  • 2021-01-27 07:35

    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()
                                              : '-'),
                                    ],
                                  );
                                }),
                          ),
                        ),
                      )
    
    0 讨论(0)
提交回复
热议问题