gpt4 book ai didi

flutter - 如何在 flutter 中将可扩展 ListView 放入 ScrollView 中?

转载 作者:IT王子 更新时间:2023-10-29 06:45:18 25 4
gpt4 key购买 nike

你好,我正在制作一个 flutter 应用程序,其中需要在 ScrollView 中放置可扩展 ListView 。首先是我的 build 方法。

  return Scaffold(   
appBar: AppBar(
backgroundColor: app_color,
iconTheme: IconThemeData(
color: Colors.white, //change your color here
)),
//debugShowCheckedModeBanner: false,
//key: scaffoldKey,
backgroundColor: app_color,
body: SingleChildScrollView(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children:<Widget>[
Text("Header"),
new ListView.builder(
itemCount: datas.length,
shrinkWrap: true,
itemBuilder: (context, i) {
return new ExpansionTile(
title: new Text(datas[i].title, style: new TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold, fontStyle: FontStyle.italic),),
children: <Widget>[
new Column(
children: _buildExpandableContent(datas[i]),
),
],
);
},
),
Text("Footer"),
],
),
)
)

);
}

现在的问题是,如果没有 SingleScrollChidView,它工作正常但是在使用 SingleScrollChidView 之后,它不显示任何内容并给出错误 RenderBox was not layout.这里有什么问题吗?我如何在 flutter 中的 Singlechildscroll View 中使用可扩展 ListView 。

最佳答案

我能够在带有文本的 ScrollView 中实现 Expanded ListView- 在 SingleChildScrollView 中使用 Wrap,前提是您使用 shr​​inkWrap: true

制作所有 ListView
SingleChildScrollView(
child: Wrap(
direction: Axis.horizontal,
children: <Widget>[
_textBody, // text body, with 1000+ words
Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
children: <Widget>[
ListViewOne(_genericListDataOne()),
],
),
),
Column(
children: <Widget>[
ListViewTwo(_genericListDataTwo())
],
)
],
),
),

ListViewOne 的部分代码

 ListViewOne(
shrinkWrap: true,
padding: new EdgeInsets.symmetric(vertical: 8.0),
children: // build list here,
);

关于flutter - 如何在 flutter 中将可扩展 ListView 放入 ScrollView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56010233/

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