如何在flutter中创建水平列表

问题描述 投票:0回答:1

我正试图在flutter中开发一个水平的列表视图,当我输入scrollDirection: Axis.horizontal, and re run the program I have issues saying. 我试着用listview拍打整个,但也没有用。enter image description hereenter image description here

body: Container(
child:ListView.builder(                  
      itemCount: _list.length,
       itemExtent: 200.0,
      itemBuilder: (context, i) {
        final b = _list[i];

        return new ListTile(
            title: new Card(
              elevation: 1.0,
              child: new Container(
                height: 293,
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.all(Radius.circular(10.0)),
                    boxShadow: [
                      BoxShadow(
                          blurRadius: 6,
                          color: Colors.black,
                          offset: Offset(4, 4))
                    ]),
                padding: EdgeInsets.all(1.0),
                child: 
                Column(
                  children: <Widget>[
                    SizedBox(height: 4),
                    Padding(
                      child: Image.network(b.bikeimage),
                      padding: EdgeInsets.only(bottom: 0.0),
                    ),
                    Padding(
                      child: Text(
                        b.name,
                        textAlign: TextAlign.right,
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 20,
                            color: Colors.black), ),
                      padding: EdgeInsets.only(left: 10),
                    ),
                  ],
                ),
              ),
            ),
            onTap: () {
            });
      },
    ),

)

flutter flutter-layout
1个回答
1
投票

你得到的错误是因为你的Container没有被赋予指定的宽度和高度。

下面的代码将完美的工作,检查出来。

body: Container(
      // give your container any desired height
       height: 500,
       // give your container any desired width
       width: double.infinity,
       child: ListView.builder(    

       // set the scroll direction to horizontal for a horizontal list
       scrollDirection: Axis.horizontal,              
      ...
      // the rest of your listview.builder code here
      ...
       ),
     );

希望能帮到你。


0
投票

看起来你的容器没有高度或宽度的限制,所以无法绘制。


0
投票

你的代码中没有提到scrollaxisdirection,请添加并尝试。进一步参考https:/pusher.comtutorialflutter-listviews。

© www.soinside.com 2019 - 2024. All rights reserved.