简体   繁体   English

当我在数据库中添加新条目时,如何更改 Flutter 中的图标?

[英]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.

相关问题 我是 Flutter 的新手,并试图用 Flutter Launcher Icons 更改我的应用程序图标并收到错误“错误:InvalidConfigException”我该如何解决这个问题? - I am new in flutter and trying to change my app icon with Flutter Launcher Icons and getting error 'ERROR: InvalidConfigException' how i can fix this? 在 flutter 中被点击时如何为我的图标设置动画 - How can i animate my icon when being tapped in flutter 如何在颤动中更改抽屉图标? - How can I change Drawer icon in flutter? 如何为 flutter 中的图标添加阴影? - How can I add shadow to an icon in flutter? 如何在 flutter 的 appBar 图标处的购物车图标上添加商品编号? 我怎样才能让它动画添加新项目? - How can I add item number on the cart icon at at appBar icon in flutter? And how can I make it animate adding new item? flutter 当 api 更改时,我如何重建我的小部件? - flutter how can i rebuild my widget when api change? 如何在 flutter 的 TextFormField 中的图标和文本之间添加分隔线 - How can i add a divider between icon and text in TextFormField in flutter 如何在 flutter 中使我的图标图像更小 - How can I make my icon image smaller in flutter 如何在我的 flutter 应用程序中使汉堡图标更大 - how can i make the burger icon bigger in my flutter app 当验证为空时如何删除图标? - How can I remove the icon when the validation is null in flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM