[英]how to show listview.builder horizontally ? flutter
i am trying to get data from server everything is working good but the data is ho vertically scroll view.:我正在尝试从服务器获取数据一切正常,但数据是垂直滚动视图。:
child: FutureBuilder(
future: getCartData(),
builder: (context, AsyncSnapshot snapshot) {
if (!snapshot.hasData) {
// still waiting for data to come
return Center(
child: CircularProgressIndicator(),
);
} else if (snapshot.hasData &&
snapshot.data.isEmpty) {
return Center(child: Text("No Products"));
;
} else {
int index=4;
if (snapshot.hasError) print(snapshot.error);
return snapshot.hasData
?ListView.builder(
itemCount: snapshot.data!.length,
itemBuilder: (BuildContext context, index){
List list = snapshot.data;
String urlname =
"https://myurl/media/";
String imagename = list[index]['itemimage']
.toString()
.replaceAll("/media/", "");
print("$urlname$imagename");
String Imagename = "$urlname$imagename";
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(vertical: 16.0),
width: MediaQuery.of(context).size.width / 2,
child: Column(
children: <Widget>[
SizedBox(
height: 150,
width: 200,
child: Stack(children: <Widget>[
Positioned(
left: 25,
child: SizedBox(
height: 150,
width: 150,
child: Transform.scale(
scale: 1.2,
child: Image.asset('assets/bottom_yellow.png'),
),
),
),
Positioned(
left: 50,
top: 5,
child: SizedBox(
height: 80,
width: 80,
child: Image.network(
'$Imagename',
fit: BoxFit.contain,
)),
),
Positioned(
right: 30,
bottom: 25,
child: Align(
child: IconButton(
icon: Image.asset('assets/red_clear.png'),
onPressed: (){},
),
),
)
]),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"${list[index]['title']}",
textAlign: TextAlign.center,
style: TextStyle(
color: darkGrey,
),
),
),
Text(
'${list[index]['price']}',
textAlign: TextAlign.center,
style: TextStyle(
color: darkGrey, fontWeight: FontWeight.bold, fontSize: 18.0),
),
],
)),
index == 8
? SizedBox()
: Container(
width: 2,
height: 200,
color: Color.fromRGBO(100, 100, 100, 0.1))
],
),
);
}
): Center(child: Text("no data"));
}
},
)),
everythinng working good only problem is that i want horzontal scroll view but with above code i got vertical scroll which is not what i want.一切正常,唯一的问题是我想要水平滚动视图,但是使用上面的代码我得到了垂直滚动,这不是我想要的。
so i added this line in singlechildscrollview:所以我在 singlechildscrollview 中添加了这一行:
scrollDirection: Axis.horizontal,
can someone tell me what i am doing wrog?有人能告诉我我在做什么吗?
in listview there is also scroll direction you can determin on the inside of the listview not in the singlechildscrollview在 listview 中还有滚动方向,您可以在 listview 内部而不是在 singlechildscrollview 中确定
ListView.builder(
scrollDirection: Axis.horizontal,
//physics: const NeverScrollableScrollPhysics()
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.