[英]How can I change an Icon in flutter when i add a new Entry in my Database?
So i set up a working Realtime Database, to which i can add entries.所以我建立了一个工作实时数据库,我可以添加条目。 Now i want to notify the user whenever a new entry was added to the Database by adding a little Red Dot to the Icon in the BottomNavigationBar which disappears again when the user has clicked it.
现在我想通过在底部导航栏中的图标上添加一个小红点来通知用户每当有新条目添加到数据库中时,当用户单击它时它会再次消失。 Any ideas on how to achieve this?
关于如何实现这一目标的任何想法?
I recommend using the badge package to achieve this.我建议使用徽章包来实现这一点。 You will have to ensure the state updates using your own state management.
您必须使用自己的状态管理来确保状态更新。 If the user goes to the notification screen, you will need to trigger an update to mark notifications as read.
如果用户进入通知屏幕,您将需要触发更新以将通知标记为已读。
return Badge(
showBadge: unreadNotifications > 0,
badgeContent: Text(
'$unreadNotifications',
style: kTextStyle,
),
position: const BadgePosition(
top: -3,
end: 3,
),
child: IconButton(
icon: const Icon(
Icons.notifications,
),
onPressed: () {
Navigator.pushNamed(context, NotificationScreen.id);
},
),
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.