Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 在ListView.builder的末尾提供一些额外的空间_Flutter_Dart - Fatal编程技术网

Flutter 在ListView.builder的末尾提供一些额外的空间

Flutter 在ListView.builder的末尾提供一些额外的空间,flutter,dart,Flutter,Dart,下面是我的代码,我想在列表项的末尾添加一些额外的高度为50的空格。因为当堆栈的第二个子项出现时,它几乎与列表视图的最后一项重叠。我尝试用列包装ListView.builder,最后添加了一个容器,但破坏了我的整个结构。在这个场景中,我必须将列包装成一个可滚动的列,它将Stack2nd小部件推到ListItem的末尾,但我不希望Stack2nd对象是可滚动的。 正如你所看到的,我无法点击热狗 body: Stack( children: <Widget>[

下面是我的代码,我想在列表项的末尾添加一些额外的高度为50的空格。因为当堆栈的第二个子项出现时,它几乎与列表视图的最后一项重叠。我尝试用列包装ListView.builder,最后添加了一个容器,但破坏了我的整个结构。在这个场景中,我必须将列包装成一个可滚动的列,它将Stack2nd小部件推到ListItem的末尾,但我不希望Stack2nd对象是可滚动的。 正如你所看到的,我无法点击热狗

 body: Stack(
        children: <Widget>[
          ListView.builder(
                  itemCount: itemData.length,
                  shrinkWrap: true,
                  scrollDirection: Axis.vertical,
                 itemBuilder: (BuildContext context,int index){ 
                   return Text(data[index].name);
 }

                     ),

          Padding(
            padding: const EdgeInsets.all(10.0),
            child: Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(8),
                color: Colors.cyan
              ),
              padding: EdgeInsets.all(10),
              height: 60,

            ),
          )
        ],
      ),

您如何添加空的最后一项,如下面的代码

          ListView.builder(
                  itemCount: itemData.length + 1,
                  shrinkWrap: true,
                  scrollDirection: Axis.vertical,
                 itemBuilder: (BuildContext context,int index){
                   if (index == item.Data.length) {
                       return SizedBox(height: 50);
                   } else {
                       return Text(data[index].name);
                   }
                 }
            ),

您如何添加空的最后一项,如下面的代码

          ListView.builder(
                  itemCount: itemData.length + 1,
                  shrinkWrap: true,
                  scrollDirection: Axis.vertical,
                 itemBuilder: (BuildContext context,int index){
                   if (index == item.Data.length) {
                       return SizedBox(height: 50);
                   } else {
                       return Text(data[index].name);
                   }
                 }
            ),

由于listview.builder位于堆栈中,因此只需使用定位小部件即可。只需将listview包装为如下位置:

Positioned(
 bottom:50, //adjust this since this is the padding inside the stack
  child:Container(
width:MediaQuery.of(context).size.width //width of the whole phone
child: ListView.builder(
          itemCount: itemData.length,
          shrinkWrap: true,
          scrollDirection: Axis.vertical,
         itemBuilder: (BuildContext context,int index){ 
           return Text(data[index].name);
    }
  ),
 ),
),
要确保容器位于底部,请使用定位小部件将其包裹,并将底部属性设置为0:

Positioned(
 bottom:0, //adjust this since this is the padding inside the stack
  child:Container(),
),

下面是一个一分钟的剪辑,演示如何使用定位小部件:

由于您的listview.builder位于堆栈中,因此只需使用定位小部件即可。只需将listview包装为如下位置:

Positioned(
 bottom:50, //adjust this since this is the padding inside the stack
  child:Container(
width:MediaQuery.of(context).size.width //width of the whole phone
child: ListView.builder(
          itemCount: itemData.length,
          shrinkWrap: true,
          scrollDirection: Axis.vertical,
         itemBuilder: (BuildContext context,int index){ 
           return Text(data[index].name);
    }
  ),
 ),
),
要确保容器位于底部,请使用定位小部件将其包裹,并将底部属性设置为0:

Positioned(
 bottom:0, //adjust this since this is the padding inside the stack
  child:Container(),
),

下面是一个一分钟的剪辑,展示了如何使用定位小部件:

默认情况下没有具体的方法,您必须使用自己的逻辑手动执行

          ListView.builder(
                  itemCount: itemData.length,
                  shrinkWrap: true,
                  scrollDirection: Axis.vertical,
                 itemBuilder: (BuildContext context,int index){ 
                   if(index == itemData.length - 1 )
                     return Padding(

                      padding: EdgeInsets.only(bottom : 50),
                      child : Text(data[index].name)
                   );
                   return Text(data[index].name);
                 }),

默认情况下,没有特定的方法来执行此操作,您必须使用自己的逻辑手动执行此操作

          ListView.builder(
                  itemCount: itemData.length,
                  shrinkWrap: true,
                  scrollDirection: Axis.vertical,
                 itemBuilder: (BuildContext context,int index){ 
                   if(index == itemData.length - 1 )
                     return Padding(

                      padding: EdgeInsets.only(bottom : 50),
                      child : Text(data[index].name)
                   );
                   return Text(data[index].name);
                 }),
ListViewBuilder应该封装在扩展的小部件中,该小部件将全屏显示 并根据需要提供容器底部宽度

例如:

输出:

ListViewBuilder应该封装在扩展的小部件中,该小部件将全屏显示 并根据需要提供容器底部宽度

例如:

输出:


这是一个好方法,但是如果他拥有的物品超过了手机的高度怎么办。例:有10个这样的项目。在项目底部添加一个额外大小的框是不够的。@uni-Hm。。。我添加了一个列表项。所以我认为无论手机的高度是多少,列表都不能超过高度。你说的@Kuku是什么意思?对不起,我不明白你第二句话的意思。您提供的此解决方案将起作用,但仅当listview中所有项目的组合高度与手机的高度相同时才起作用。您只是在列表末尾添加了一个大小的框,对吗?因此,当列表中的项目太多时,SizedBox不会显示。它只显示在列表的末尾。希望这能澄清我想说的。你仍然有一个很好的答案,但它不适用于包含许多项目的列表视图。祝你的项目好运:这是一个好方法,但如果他拥有的项目超过了手机的高度怎么办。例:有10个这样的项目。在项目底部添加一个额外大小的框是不够的。@uni-Hm。。。我添加了一个列表项。所以我认为无论手机的高度是多少,列表都不能超过高度。你说的@Kuku是什么意思?对不起,我不明白你第二句话的意思。您提供的此解决方案将起作用,但仅当listview中所有项目的组合高度与手机的高度相同时才起作用。您只是在列表末尾添加了一个大小的框,对吗?因此,当列表中的项目太多时,SizedBox不会显示。它只显示在列表的末尾。希望这能澄清我想说的。您仍然有一个很好的答案,但它不适用于包含许多项的ListView。祝您的项目好运:这同样有效。这是使用定位小部件的另一种选择:它也可以工作。这是使用定位小部件的另一种选择:嘿@Uni,我已经尝试过你的方法,但是得到了这个错误。断言失败:第1648行第16位:“constraints.hasBoundedWidth”:不正确。@PraveenGupta必须用容器包装它。我更新了答案每当我在Posited wigdet中提供底部值时,它会将我带到屏幕底部,我无法滚动到任何地方。嘿@Uni,我尝试过你的方法,但得到了这个错误。断言失败:第1648行第16位:“constraints.hasBoundedWidth”:不正确。@PraveenGupta必须用容器包装它。我更新了答案每当我在定位wigdet中提供底部值时,它会将我带到屏幕底部,我无法滚动到任何地方。