我有一个带有CupertinoTabScaffold,CupertinoTabBar和一系列BottomNavigationBarItem的CupertinoApp。我设法在BottomNavigationBarItem(购物篮标签)之一中添加了徽章。看到下面的图片以及我的代码
import numpy as np
def microcar(expected, actual):
horizontal_expected = expected[0,1]*expected[0,2]*np.cos(expected[0,0])
vertical_expected = expected[0,1]*expected[0,2]*np.sin(expected[0,0])
horizontal_actual = actual[0,1]*actual[0,2]*np.cos(actual[0,0])
vertical_actual = actual[0,1]*actual[0,2]*np.sin(actual[0,0])
distance_expected = expected[0,1]*expected[0,2]
distance_actual = actual[0,1]*actual[0,2]
return horizontal_expected, vertical_expected, horizontal_actual, vertical_actual, distance_expected, distance_actual
现在,我想基于在另一个标签之一中触发的事件来更新徽章文本。我将徽章的值存储为单例(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'),
),
],
),
),此信息可用于所有屏幕。每次触发该事件时,appData.basketList.length.toString()都会更改,但我的徽章不会更改。仅当我热装时它才会改变...所以这是我的问题:如何更新徽章的文字?
谢谢!