feat(chat): add badges

This commit is contained in:
alex
2024-07-09 11:17:32 +03:00
parent 5f88f49c71
commit f79b9f03ae
12 changed files with 1372 additions and 30 deletions

View File

@@ -0,0 +1,185 @@
import 'package:eatvio_app/core/app_export.dart';
import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/new_messages_cubit/new_messages_cubit.dart';
import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/new_messages_cubit/new_messages_state.dart';
import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/notifications_cubit/notifications_cubit.dart';
import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/notifications_cubit/notifications_state.dart';
import 'package:flutter/material.dart';
import 'package:eatvio_app/widgets/custom_navigation_menu.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:go_router/go_router.dart';
import 'package:badges/badges.dart' as badges;
int currentBottomNavBarIndex = 0;
class BottomNavigationBarWidget extends StatefulWidget {
final Widget child;
const BottomNavigationBarWidget({
super.key,
required this.child,
});
@override
State<BottomNavigationBarWidget> createState() => _BottomNavigationBarWidgetState();
}
class _BottomNavigationBarWidgetState extends State<BottomNavigationBarWidget> {
void _onItemTapped(int index) {
if (currentBottomNavBarIndex != index) {
setState(() {
currentBottomNavBarIndex = index;
});
}
switch (currentBottomNavBarIndex) {
case 0:
GoRouter.of(context).replace('/my-profile-screen');
break;
case 1:
GoRouter.of(context).replace('/feed-screen');
break;
case 2:
GoRouter.of(context).replace('/diary-screen');
break;
case 3:
GoRouter.of(context).replace('/chat-select-screen');
break;
case 4:
break;
case 5:
final RenderBox overlay = Overlay.of(context).context.findRenderObject() as RenderBox;
final size = overlay.size;
showMenu(
context: context,
color: Colors.white,
shadowColor: Colors.white,
surfaceTintColor: Colors.white,
items: [
PopupMenuItem(
child: CustomNavigationMenu(),
),
],
position: RelativeRect.fromLTRB(size.width, size.height, 0, 0),
);
break;
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: widget.child,
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
onTap: _onItemTapped,
selectedFontSize: 12,
unselectedFontSize: 12,
selectedItemColor: appTheme.blueA400,
currentIndex: currentBottomNavBarIndex,
items: [
BottomNavigationBarItem(
label: '',
icon: SvgPicture.asset(
ImageConstant.imgLogo,
),
),
BottomNavigationBarItem(
label: 'Лента',
icon: SvgPicture.asset(
width: 24,
height: 24,
ImageConstant.imgFeed,
),
activeIcon: SvgPicture.asset(
ImageConstant.imgFeed,
width: 24,
height: 24,
colorFilter: ColorFilter.mode(
appTheme.blueA400,
BlendMode.srcIn,
),
),
),
BottomNavigationBarItem(
label: "diary".tr,
icon: SvgPicture.asset(
ImageConstant.imgDiary,
width: 24,
height: 24,
),
activeIcon: SvgPicture.asset(
ImageConstant.imgDiary,
width: 24,
height: 24,
colorFilter: ColorFilter.mode(
appTheme.blueA400,
BlendMode.srcIn,
),
),
),
BottomNavigationBarItem(
label: "chat".tr,
icon: BlocBuilder<NewMessagesCubit, NewMessagesState>(
builder: (BuildContext context, NewMessagesState state) {
return badges.Badge(
position: badges.BadgePosition.topEnd(),
badgeContent: Text(
(state is NewMessagesStateLoaded) ? state.messagesCount.toString() : '0',
style: TextStyle(
color: Colors.white,
),
),
child: SvgPicture.asset(
ImageConstant.imgChat,
width: 24,
height: 24,
colorFilter: currentBottomNavBarIndex == 3
? ColorFilter.mode(
appTheme.blueA400,
BlendMode.srcIn,
)
: null,
),
);
},
),
),
BottomNavigationBarItem(
label: '',
icon: BlocBuilder<NotificationsCubit, NotificationsState>(
builder: (BuildContext context, NotificationsState state) {
return badges.Badge(
position: badges.BadgePosition.topEnd(),
badgeContent: Text(
(state is NotificationsStateLoaded) ? state.notificationsCount.toString() : '0',
style: TextStyle(
color: Colors.white,
),
),
child: SvgPicture.asset(
ImageConstant.imgBell,
colorFilter: currentBottomNavBarIndex == 4
? ColorFilter.mode(
appTheme.blueA400,
BlendMode.srcIn,
)
: null,
width: 24,
height: 24,
),
);
},
),
),
BottomNavigationBarItem(
label: '',
icon: Image.asset(
ImageConstant.imgEllipse1,
width: 32,
height: 32,
),
),
],
),
);
}
}