我想知道如何使用徽章从提供商处动态获取徽章数据。这是我目前在不使用徽章的情况下获取数据的方式。我想使用包提供的徽章选项。这是包的链接
我当前的代码在没有徽章的情况下使用它。该代码使用convex_bottom_bar 来呈现选项卡和一些自定义代码来呈现徽章动态数据。
ConvexAppBar(
height: 60,
top: -30,
curveSize: 100,
style: TabStyle.titled,
backgroundColor: Colors.mainColor,
color: Color(0xbdb5ebFF),
activeColor: Color(0xFFFFFFFF),
items: [
TabItem(icon: Icons.store, title: 'Home'),
TabItem(icon: Icons.person, title: 'Profile'),
TabItem(icon: Icons.add, title: 'Add'),
TabItem(icon: Icons.favorite_border, title: 'Favourites'),
TabItem(
icon: Stack(
children: <Widget>[
Container(
child:
Icon(Icons.message, color: Color(0xbdb5ebFF)),
),
Positioned(
child: ChangeNotifierProvider<
UserUnreadMessageProvider>(
create: (BuildContext context) {
userUnreadMessageProvider =
UserUnreadMessageProvider(repo: userUnreadMessageRepository);
if (valueHolder.loginUserId != null &&
valueHolder.loginUserId != '') {
userUnreadMessageHolder =
UserUnreadMessageParameterHolder(
userId: valueHolder.loginUserId,
deviceToken: valueHolder.deviceToken);
userUnreadMessageProvider
.userUnreadMessageCount(
userUnreadMessageHolder);
}
return userUnreadMessageProvider;
}, child: Consumer<UserUnreadMessageProvider>(
builder:
(BuildContext context,
UserUnreadMessageProvider
userUnreadMessageProvider,
Widget child) {
if (userUnreadMessageProvider != null &&
userUnreadMessageProvider
.userUnreadMessage !=
null &&
userUnreadMessageProvider
.userUnreadMessage.data !=
null) {
final int sellerCount = int.parse(
userUnreadMessageProvider
.userUnreadMessage
.data
.sellerUnreadCount);
final int buyerCount = int.parse(
userUnreadMessageProvider
.userUnreadMessage
.data
.buyerUnreadCount);
userUnreadMessageProvider.totalUnreadCount =
sellerCount + buyerCount;
if (userUnreadMessageProvider
.totalUnreadCount ==
0) {
return Container();
} else {
if (userUnreadMessageProvider
.totalUnreadCount >
0) {
Future<dynamic>.delayed(Duration.zero,
() => showMessageDialog(context));
}
return Container(
width: Dimens.space50,
height: Dimens.space50,
margin: const EdgeInsets.only(
left: Dimens.space8,
bottom: Dimens.space8),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.red,
),
child: Align(
alignment: Alignment.center,
child: Text(
userUnreadMessageProvider
.totalUnreadCount >
9
? '9+'
: userUnreadMessageProvider
.totalUnreadCount
.toString(),
textAlign: TextAlign.left,
style: Theme.of(context)
.textTheme
.bodyText2
.copyWith(color: Colors.white),
maxLines: 1,
),
),
);
}
} else {
return Container();
}
})),
),
],
),
title: 'Messages'),
],
initialActiveIndex: 2, //optional, default as 0
onTap: (int index) {
final dynamic _returnValue =
getIndexFromBottonNavigationIndex(index);
updateSelectedIndexWithAnimation(
_returnValue[0], _returnValue[1]);
},
),
包中有一个方法默认执行此操作,但我无法弄清楚如何动态执行此操作。
ConvexAppBar.badge({0: '99+', 1: Icons.assistant_photo, 2: Colors.redAccent},
items: [
TabItem(icon: Icons.home, title: 'Home'),
TabItem(icon: Icons.map, title: 'Discovery'),
TabItem(icon: Icons.add, title: 'Add'),
],
onTap: (int i) => print('click index=$i'),
);