Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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?_Flutter_Listview_Dart - Fatal编程技术网

Flutter 如何在不设置容器高度的情况下在容器内显示ListView?

Flutter 如何在不设置容器高度的情况下在容器内显示ListView?,flutter,listview,dart,Flutter,Listview,Dart,在我的Flatter项目中,我使用容器包装的ListView显示了一个数据列表。现在,当我在没有设置容器高度的情况下使用容器时,它会显示以下错误- RenderBox未布局:RenderPaintBoundary#a418c relayoutBoundary=up16 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE “package:flatter/src/rendering/box.dart”:失败的断言:第1687行 位置12:“hasSize” 这是我写

在我的Flatter项目中,我使用容器包装的ListView显示了一个数据列表。现在,当我在没有设置容器高度的情况下使用容器时,它会显示以下错误-

RenderBox未布局:RenderPaintBoundary#a418c relayoutBoundary=up16 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE “package:flatter/src/rendering/box.dart”:失败的断言:第1687行 位置12:“hasSize”

这是我写的整个课程结构-

SingleChildScrollView(
            child: Column(
              children: <Widget>[

                showTheHistory(),

                Container(
                    height: MediaQuery.of(context).size.height-ScreenUtil.instance.setWidth(260),

                    child: Padding(
                      padding:  EdgeInsets.only(left: ScreenUtil.instance.setWidth(10), right: ScreenUtil.instance.setWidth(10)),
                      child: Container(
                        color: Colors.white,
                        child: FutureBuilder<List>(
                          future: _searchList,
                          initialData: List(),
                          builder: (context, snapshot) {
                            return snapshot.hasData ?
                            new ListView.builder(
                              padding:  EdgeInsets.all(ScreenUtil.instance.setWidth(10)),
                              itemCount: snapshot.data.length,
                              itemBuilder: (context, i) {
                                return _buildRow(snapshot.data[i]);
                              },
                            )
                                : Center(
                              child: NoResultFoundScreen(),
                            );
                          },
                        ),
                      ),
                    ),
                  ),
                

                SizedBox(height: ScreenUtil.instance.setHeight(10),),

                Container(
                  width: MediaQuery.of(context).size.width,
                  child: Padding(
                    padding:  EdgeInsets.only(left: ScreenUtil.instance.setWidth(10), right: ScreenUtil.instance.setWidth(10) ),
                    child: Column(
                      children: <Widget>[
                        Card(
                          elevation: 6,
                          child: Padding(
                            padding:  EdgeInsets.all(ScreenUtil.instance.setWidth(5)),
                            child: Row(
                              children: <Widget>[
                                
                                Text('English to ${Credentials.languageType}', style: TextStyle(fontSize: ScreenUtil.instance.setSp(18), color: Colors.teal, fontWeight: FontWeight.bold),)

                              ],
                            ),
                          ),
                        ),



                        Padding(
                          padding:  EdgeInsets.only(top:ScreenUtil.instance.setWidth(10)),
                          child: Card(
                            color: Colors.white,
                            elevation: 10,

                            child: Container(

                              child: Column(
                                children: <Widget>[

                                  getHowToUseText('1. '),

                                  Padding(
                                    padding: const EdgeInsets.only(left:8.0, right: 8.0),
                                    child: Divider(height: 2, color: Colors.grey,),
                                  ),

                                  getHowToUseText('2. While typing you will get auto suggestions. You can tap on the words to see meaning'),

                                ],
                              ),
                            ),

                          ),
                        )


                      ],
                    ),
                  ),
                ),

                SizedBox(
                  height: ScreenUtil.instance.setHeight(160),
                )

              ],
            ),
          ),
SingleChildScrollView(
子:列(
儿童:[
显示历史(),
容器(
高度:MediaQuery.of(context).size.height ScreenUtil.instance.setWidth(260),
孩子:填充(
padding:EdgeInsets.only(左:ScreenUtil.instance.setWidth(10),右:ScreenUtil.instance.setWidth(10)),
子:容器(
颜色:颜色,白色,
孩子:未来建设者(
未来:_搜索列表,
initialData:List(),
生成器:(上下文,快照){
返回snapshot.hasData?
新建ListView.builder(
padding:EdgeInsets.all(ScreenUtil.instance.setWidth(10)),
itemCount:snapshot.data.length,
itemBuilder:(上下文,i){
返回_buildRow(snapshot.data[i]);
},
)
:中心(
子项:NoResultFoundScreen(),
);
},
),
),
),
),
SizedBox(高度:ScreenUtil.instance.setHeight(10)),
容器(
宽度:MediaQuery.of(context).size.width,
孩子:填充(
padding:EdgeInsets.only(左:ScreenUtil.instance.setWidth(10),右:ScreenUtil.instance.setWidth(10)),
子:列(
儿童:[
卡片(
标高:6,
孩子:填充(
padding:EdgeInsets.all(ScreenUtil.instance.setWidth(5)),
孩子:排(
儿童:[
Text('English to${Credentials.languageType}',style:TextStyle(fontSize:ScreenUtil.instance.setSp(18),color:Colors.teal,fontwweight:fontwweight.bold),)
],
),
),
),
填充物(
padding:EdgeInsets.only(顶部:ScreenUtil.instance.setWidth(10)),
孩子:卡片(
颜色:颜色,白色,
标高:10,
子:容器(
子:列(
儿童:[
getHowToUseText('1'),
填充物(
填充:仅限常量边集(左:8.0,右:8.0),
儿童:分隔器(高度:2,颜色:颜色。灰色,),
),
getHowToUseText('2.键入时,您将获得自动建议。您可以点击这些单词查看其含义'),
],
),
),
),
)
],
),
),
),
大小盒子(
高度:ScreenUtil.instance.setHeight(160),
)
],
),
),

因此,正如您所看到的,这是为包装ListView的容器设置的高度。在ListView中,加载数据需要时间,在这段时间内,具有固定大小的容器保持空白,这显然是不好的。因此,我需要一个解决方案,使Listview高度动态,而不必设置容器的高度。

收缩包装:true
属性添加到
Listview
中,同时删除容器


你也有很多多余的小部件。你应该考虑重构你的代码。您应该看看flatter.dev上的widgets文档

谢谢,它很有效。我接受你的回答是正确的,但是为了启用listview和SingleChildScrollView都滚动-我只是将physics:ScrollPhysics()设置为我的listview.builder。