hacktons / convex_bottom_bar

A Flutter package which implements a ConvexAppBar to show a convex tab in the bottom bar. Theming supported.
https://bar.hacktons.cn
Apache License 2.0
801 stars 151 forks source link

ConvexBar Badge With dynamic data #154

Closed cyberneticspk closed 2 years ago

cyberneticspk commented 3 years ago

Hello Sir, first of all i apologize for reporting something that actually is not an issue but not documented. i would like to know how can i use the badge to dynamically get the data for badge from a provider. here is how i am currently getting the data without using a badge i would like to use the badge option.

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]); }, ), Thank you.

cyberneticspk commented 3 years ago

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: [ 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( 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.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]); }, ),

avenwu commented 3 years ago

Please paste code with markdown syntax or gist, it's really hard to read🤣