【发布时间】:2021-01-02 08:45:38
【问题描述】:
我需要获取一个购物车值并在 Flutter 底部导航中添加为徽章,但在函数之后没有设置值
我的代码
void _getCartValue() {
getCartcount().then((value) => {print(value), cartlength = value});
// setState(() {});
}
_getCartValue();
底部导航代码
BottomNavigationBarItem(
label: 'Cart',
icon: Badge(
shape: BadgeShape.circle,
borderRadius: BorderRadius.circular(100),
child: Icon(Icons.shopping_cart),
badgeContent: Container(
height: 15,
width: 15,
decoration:
BoxDecoration(shape: BoxShape.circle, color: Colors.red),
child: Text(
cartlength.toString(),
style: TextStyle(
color: Colors.white,
fontSize: 10,
fontWeight: FontWeight.bold),
),
),
),
),
该值正在函数内部打印,但我无法获取函数下方的值。帮我将值从_getCartValue 传递到cartlength 值
函数下方出现空值
【问题讨论】:
标签: flutter