【发布时间】:2019-10-20 22:46:21
【问题描述】:
在我们的 Flutter Cupertino 项目中,我们需要在底部栏图标之一上显示一个徽章。确切地说,购物车中有多少商品。
我尝试了此处提供的不同小部件和解决方案,但 BottomNavigationBarItem 仅接受 icon: Icon(..) 并没有其他内容。例如,如果我输入icon: Stack(..) 而不是icon: Icon(..),则会显示错误消息,例如
“无效的常量值...”
这里是一些示例代码:
class CupertinoStoreHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.home),
title: Text('Kühlschrank'),
),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.profile_circled),
title: Text('Konto'),
),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.shopping_cart),
title: Text('Warenkorb'),
),
],
),
所以如果我不能放任何东西来代替Icon(..)。没有其他小部件,没有Stack(..)。
为什么?如何放置其他小部件,例如 Badge(..):
badges: ^1.0.2
import 'package:badges/badges.dart';
这个问题与可能的重复问题不同,因为我已经尝试过那里发布的解决方案,但仍然无法使用 Stack(..),而只能使用 Icon(..)。
【问题讨论】:
-
对图标属性使用堆栈对我有用。尝试时的确切错误消息是什么?