简体   繁体   English

Flutter - 具有两个方向滚动和未知子大小的 ListView.Builder

[英]Flutter - ListView.Builder with two direction scroll and unknown children size

I'm building a data list like this我正在建立一个这样的数据列表

List<String> list=[.....];  //a lot of data
ListView.builder(
    scrollDirection: Axis.vertical,
    shrinkWrap: true,
    controller: scrollController,
    itemCount: list.length,
    itemBuilder: (context, i) => 
        ListTile(title: Text(list[i])))  

It can scroll on vertical now but some long data will overflow on the right,so I want to add a horizontal scroll outside.它现在可以垂直滚动,但是一些长数据会在右侧溢出,所以我想在外面添加一个水平滚动。

I tried many ways but it always return error such as "'constraints.hasBoundedWidth': is not true."我尝试了很多方法,但它总是返回错误,例如“'constraints.hasBoundedWidth': is not true”。

Code like this works fine but I have to set a width in Container first:像这样的代码可以正常工作,但我必须先在 Container 中设置宽度:

ListView(
    shrinkWrap: true,
    scrollDirection: Axis.horizontal,
    children: [
        Container(
            width: 2000,    //will return error if not set a value
            child: ListView.builder(.....)
                 )])

Is there any way to add a horizontal scroll outside with unknown child width?有没有办法在外部添加未知子宽度的水平滚动?

Nothing wrong in vertical list.垂直列表没有错。 I have run code in android studio as well.我也在 android 工作室中运行了代码。
no need to use Listview in the inner of another list view.无需在另一个列表视图的内部使用 Listview。 you can wrap your title with Expanded widget, if your list title overflow on right side of screen.如果您的列表标题在屏幕右侧溢出,您可以使用 Expanded 小部件包装您的标题。

return ListView.builder(
        scrollDirection: Axis.vertical,
        shrinkWrap: true,
        padding: EdgeInsets.all(10),
        itemCount:100,
        itemBuilder: (context, i) =>
            ListTile(title: Text("{$i ===}babul dshdshfdsh dfhdhfdh hbfdshhds hdfhdsvhfdsv hdsvd hdsfhdshv dhfbhdsb hdsghshdsg hdvshvv jdsfjfdbvjfdnfjbfjbfhbfbf fhbfdhbfdhbf")));
  }

在此处输入图像描述

Below code will serve your purpose.下面的代码将满足您的目的。 Happy coding...快乐的编码...

 return Container(
          child: ListView.builder(
              scrollDirection: Axis.vertical,
              shrinkWrap: true,
              itemCount:10,
              itemBuilder: (context, i) =>
               SingleChildScrollView(
                 scrollDirection: Axis.horizontal,
                child: new Text(
                  "Description that is too long in text format(Here Data is coming from API Description that is too long in text format)",
                  style: new TextStyle(
                    fontSize: 16.0, color: Colors.black87,
                  ),
                ),
              ),
        ),);

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM