【发布时间】:2019-09-23 06:27:38
【问题描述】:
我想建立一个类似 instagram 的个人资料页面,其中当前用户的所有帖子都列在一个提要中。在此之上,应显示有关用户的一些信息(头像、关注者数量、帖子数量、个人简介等)。 用户应该能够滚动整个页面。 目前页面只能滚动到我的 ListView.builder 中 sizedBox-widget 的高度。就这样:
ProfilePage类的构建方法如下:
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(),
body: ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 25.0, top: 30.0),
child: Text(_user.displayName,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20.0)),
),
...(all the other information for the "header-part")
postImagesWidget(),
])));}
在 postImagesWidget 中,我使用 ListView.builder 构建提要:
Widget postImagesWidget(){
return FutureBuilder(
future: _future,
builder:
((context, AsyncSnapshot<List<DocumentSnapshot>> snapshot) {
if (snapshot.hasData) {
if (snapshot.connectionState == ConnectionState.done) {
return SizedBox(
height: 600,
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
//shrinkWrap: true,
itemCount: snapshot.data.length,
itemBuilder: ((context, index) => ListItem(
list: snapshot.data,
index: index,
user: _user))));
} else {
return Center(
child: CircularProgressIndicator(),
);
}
} else {
return Center(
child: CircularProgressIndicator(),
);
}
}),
);
}
我必须添加一个 sizedBox-Widget 以避免此错误:
抛出了另一个异常:RenderBox 未布置:RenderViewport#50ccf NEEDS-PAINT
这个错误的描述说我应该将收缩包装添加到我的 ListView.builder 中,但是在出现这个错误的一些滚动之后,这会使我的整个应用程序崩溃:
断言失败:第 470 行 pos 12: 'child.hasSize': is not true.
如何使整个页面可滚动,而不是两个部分(页眉和提要)分开滚动?
我知道我在 ListView 中使用 ListView.builder...
最好的问候。
【问题讨论】: