gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 04:39:47 24 4
gpt4 key购买 nike

在我的Flutter项目中,我使用带容器包装的ListView显示数据列表。现在,当我在未设置容器高度的情况下使用它时,显示以下错误-

RenderBox was not laid out: RenderRepaintBoundary#a418crelayoutBoundary=up16 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE'package:flutter/src/rendering/box.dart': Failed assertion: line 1687pos 12: 'hasSize'


这是我所写类(class)的整个结构,
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),
)

],
),
),
因此,如您所见,这是设置为包装ListView的Container的高度。在ListView中,数据需要花费一些时间来加载,并且在那个时间段内具有固定大小的Container保持空白,这显然不好。因此,尽管需要设置Container的高度,但我仍需要一种解决方案来使Listview的高度动态变化。

最佳答案

shrinkWrap: true属性添加到listview也会删除容器。
另外,您有很多冗余小部件。您应该考虑重构代码。您应该看看flutter.dev上的小部件文档

关于flutter - 如何在不设置Flutter中的容器高度的情况下在容器内显示ListView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63456923/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com