简体   繁体   English

如何水平显示listview.builder? flutter

[英]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()
     ),

Add scrollDirection as Axis.horizontal reference添加scrollDirection作为Axis.horizontal参考

 ListView.builder(
      scrollDirection: Axis.horizontal,
    ),

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

相关问题 Flutter:如何在 ListView.builder 中显示来自 ListView.builder 的数组数据? - Flutter: How to show array data from ListView.builder inside a ListView.builder? Flutter,如何获取object的数据数组并显示给ListView.builder? - Flutter, how to get data array of object and show to ListView.builder? Flutter Firestore StreamBuilder 和 ListView.builder() 如何显示索引号 - Flutter Firestore StreamBuilder and ListView.builder() how to show index number 如何在带有分页的 flutter 的 listview.builder 中显示原生广告? - How to Show native ads in listview.builder in flutter with pagination? 如何正确解析嵌套的 map 并将其显示在 Flutter 的 listview.builder 中? - How to parse nested map properly and show it in the listview.builder in Flutter? Flutter:文本字段 onTap 显示 ListView.Builder - Flutter : Textfield onTap show ListView.Builder Flutter ListView.builder - Flutter ListView.builder flutter 中的 LIstView.builder - LIstView.builder in flutter 如何在 Column 中使用 Listview.builder 并使它们在 flutter 中水平滚动? - How to use Listview.builder in Column and make them scrollable horizontally in flutter? flutter:如何将 DataTable 与 Listview.builder 一起使用 - flutter: how to use DataTable with Listview.builder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM