I have a CupertinoApp with a CupertinoTabScaffold, a CupertinoTabBar and a series of BottomNavigationBarItem(s). I managed to add a badge in one of the BottomNavigationBarItem (the basket tab). See the picture below as well as my code
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return CupertinoTabScaffold(
tabBar: CupertinoTabBar(
backgroundColor: kColorPrimaryLight,
items: [
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.search),
title: Text('Discover'),
),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.person_solid),
title: Text('Account'),
),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.book_solid),
title: Text('Stories'),
),
BottomNavigationBarItem(
icon: Badge(
badgeContent: Text(
appData.basketList.length.toString(),
style: kDescriptionTextStyle,
),
child: Icon(CupertinoIcons.shopping_cart)),
title: Text('Basket'),
),
],
),
Now I would like to update that badge text based on an event which get triggered in one of the the other tab. I am storing the value of the badge in a singletons (appData.basketList
) and this information is available to all my screens. Every time I trigger that event then the appData.basketList.length.toString() changes but my badge does not change. It only change if I hot reload... so here is my question: how can I update the text of my badge?
Thanks !