【发布时间】:2022-01-06 08:00:15
【问题描述】:
我在 Stream Builder 中有一个列表视图构建器,内容是在快照中获取的,但是,我遇到的问题是我只需要显示一次重复的数据。
如您所见,同一个人查看了列表并向我发送了一些聊天,我如何告诉 Listview Builder Return,仅在此示例中的人员和操作不同时才创建小部件,而不是 6 Eduardo Alas 查看您的列表和 4 Eduardo Alas 想给您发送消息,我只想显示 2 行,因为这是重复操作。
这是我的代码:
StreamBuilder(
stream: DatabaseMethods().getNotifications(),
builder: (context, snapshot) {
int lastdoc = 0;
if (snapshot.hasData) {
lastdoc = snapshot.data.docs.length - 1;
}
return snapshot.hasData
? Expanded(
child: Container(
color: Color(0xFFF9F7F0),
child: ListView.builder(
shrinkWrap: true,
padding: const EdgeInsets.all(10),
itemCount: snapshot.data.docs.length,
reverse: false,
itemBuilder: (context, index) {
DocumentSnapshot ds =
snapshot.data.docs[index];
return NotificationInfo(
id: ds.id,
email: ds['email'],
image: ds['image'],
name: ds['name'],
phone: ds['phone'],
platform: ds['platform'],
token: ds['token'],
typeNot: ds['notification'],
username: ds['username'],
listingId: ds['listingId'],
listingImage: ds['listingImage'],
notificationId: ds.id,
blockDemo: false,
islast: index == lastdoc,
);
//}
}),
),
)
: Center(
child: RoofLoadingBar(
height: 100,
),
);
},
)
有什么想法吗?
【问题讨论】:
标签: flutter listview stream-builder