[英]Flutter ListViewBuilder with 2 different types of elements (eg. profile pic on top and profile details list after that)
I'm aiming for a page that looks like this -我的目标是一个看起来像这样的页面 -
ListView
列表显示
[Profile _ Image] {Swiper}
[个人资料_图片] {Swiper}
[SizedBox]
[大小盒]
[Profile Detail-1 ]{Text}
[个人资料详情-1]{文字}
[Profile Detail-2 ]{Text}
[个人资料详情-2]{文本}
[Profile Detail-3 ]{Text}
[个人资料详情-3]{文字}
[Profile Detail-N ] {Text}
[个人资料详细信息-N] {文本}
I looked at the Flutter cookbook example of MultiList我查看了 MultiList 的 Flutter食谱示例
The cookbook expects all items in the listview to implement the same class.食谱期望列表视图中的所有项目都实现相同的 class。 What if this is not possible.
如果这是不可能的怎么办。
I have tried using index
of ListViewBuilder to return Widget based on index.我尝试使用 ListViewBuilder 的
index
来根据索引返回 Widget。
Is that the right approach?这是正确的方法吗? Shall I be doing something completely different - like siglechildScrollView?
我应该做一些完全不同的事情——比如 siglechildScrollView 吗?
Thanks!谢谢!
Edit1- Current Code that I'm using - Edit1-我正在使用的当前代码-
return NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification scrollInfo) {
if (scrollInfo.metrics.pixels == scrollInfo.metrics.maxScrollExtent) {
this._feedBloc.loadMore();
}
return false;
},
child: ListView.builder(
padding: EdgeInsets.only(bottom: 72),
itemCount: this._postItems.length + 1,
itemBuilder: (context, index) {
if (this._postItems.length == index) {
if (this._isLoadingMore) {
return Container(
margin: EdgeInsets.all(4.0),
height: 36,
width: 36,
child: Center(
child: CircularProgressIndicator(),
),
);
} else {
return Container();
}
}
if(index==0){
return WdgtProfileImage();}
else if(index==1){
return SizedBox(2.0);}
return WdgtUserPost(
model: this._postItems[index],
onPostClick: onPostClick,
);
//return postItemWidget(
// postItem: this._postItems[index], onClick: onPostClick);
}),
);
You can use a CustomScrollView instead of the normal Listview.builder
.您可以使用CustomScrollView而不是普通的
Listview.builder
。 The CustomScrollView
takes in a list of slivers to which you can pass/use a SliverList to build a list. CustomScrollView
接收一个 sliver 列表,您可以将其传递/使用SliverList来构建列表。
CustomScrollView(
slivers: <Widget>[
//A sliver widget that renders a normal box widget
SliverToBoxAdapter(
child: WdgtProfileImage(),
),
//A sliver list
SliverList(
//With SliverChildBuilderDelegate the items are constructed lazily
//just like in Listview.builder
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return WdgtUserPost(
model: _postItems[index],
onPostClick: onPostClick,
);
},
childCount: _postItems.length,
),
),
if (_isLoadingMore)
//your loading widget shown at the bootom of the list
SliverToBoxAdapter(
child: Container(
margin: EdgeInsets.all(4.0),
height: 36,
width: 36,
child: Center(
child: CircularProgressIndicator(),
),
),
),
],
)
Additional links to docs:文档的其他链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.