【发布时间】:2020-12-06 13:13:22
【问题描述】:
我有一个聊天课:
List<Message> chats = [
Message(
sender: roberta,
time: '5:30 PM',
text: 'Hey, how\'s it going? What did you do today?',
isLiked: false,
unread: true,
),
Message(
sender: roberta,
time: '5:30 PM',
text: 'Hey, how\'s it going? What did you do today?',
isLiked: false,
unread: true,
),
Message(
sender: stefano,
time: '4:30 PM',
text: 'Hey, how\'s it going? What did you do today?',
isLiked: false,
unread: true,
),
带有消息属性,其中之一是“未读”属性。 如何将 true 分配给 Int,例如数字 1,如果为 false 则为 0 我需要将这个布尔“未读”转换为一个数字,以显示有多少未读消息进入 Flutter 中的通知小部件
有什么意见吗?
【问题讨论】:
-
您可以遍历
chats列表并根据消息未读的情况增加计数器变量。然后,在通知中显示这个计数器整数。 -
使用可以使用高阶函数如'reduce'来检查未读属性并为每个未读加1 == true
标签: flutter