我想建立一个类似Instagram的个人资料页面,在该页面中,当前用户的所有帖子将在动态列表中列出。此外,应显示有关用户的一些信息(头像、粉丝数、发帖数、个人简介等)。用户应能够滑动整个页面。 目前,该页面只能滚动到ListView.builder中的sizedBox-widget的高度。就像这样:
ProfilePage类的构建方法如下:
在 postImagesWidget 中,我使用 ListView.builder 来构建动态内容:
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:
Another exception was thrown: RenderBox was not laid out: RenderViewport#50ccf NEEDS-PAINT
这个错误的描述说我应该给我的ListView.builder添加shrinkwrap,但是当我滚动一段时间后,这会导致整个应用程序崩溃并出现以下错误:
Failed assertion: line 470 pos 12: 'child.hasSize': is not true.
如何使整个页面可滚动而不是独立滚动两个部分(标题和内容)?
我知道这与我在ListView内部使用ListView.builder有关...
最好的问候。