我想创建一个水平列表视图的垂直列表。我已经使用this实现了它。但是我的问题是每个项目都在水平方向分别滚动,我不希望这样。我需要完整的回收站视图一起水平滚动。这是我正在使用的代码。
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()
: '-'),
],
),
);
})
欢迎任何帮助或建议
答案 0 :(得分:0)
经过2天的研究,我终于得到了答案。只需使用 SingleChildScrollView 作为提供滚动方向为水平方向的父级,它的子级将是一个大小框,其 width 将是 static ,正如我所知道的那样列表视图的宽度,并在此大小框内,我们可以直接使用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()
: '-'),
],
);
}),
),
),
)