From 8bc1c7bab10eb58e3787fe209d3b10852f1d5d5a Mon Sep 17 00:00:00 2001 From: sBubshait Date: Mon, 28 Jul 2025 11:34:44 +0300 Subject: [PATCH] feat: add invitations badge with available invites --- frontend/lib/screens/home_screen.dart | 64 ++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/frontend/lib/screens/home_screen.dart b/frontend/lib/screens/home_screen.dart index 1a74c6f..2f63012 100644 --- a/frontend/lib/screens/home_screen.dart +++ b/frontend/lib/screens/home_screen.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'pages/feed_page.dart'; import 'pages/invitations_page.dart'; import 'pages/profile_page.dart'; +import '../services/invitations_service.dart'; class HomeScreen extends StatefulWidget { @override @@ -10,9 +11,70 @@ class HomeScreen extends StatefulWidget { class _HomeScreenState extends State { int _currentIndex = 0; + int _availableInvitationsCount = 0; final List _pages = [FeedPage(), InvitationsPage(), ProfilePage()]; + @override + void initState() { + super.initState(); + // Start polling and listen to invitations stream + InvitationsService.startPolling(); + _listenToInvitations(); + } + + @override + void dispose() { + InvitationsService.stopPolling(); + super.dispose(); + } + + void _listenToInvitations() { + InvitationsService.getInvitationsStream().listen((invitationsData) { + if (mounted) { + setState(() { + _availableInvitationsCount = invitationsData.available.length; + }); + } + }); + } + + Widget _buildInvitationsBadge() { + if (_availableInvitationsCount == 0) { + return Icon(Icons.mail); + } + + return Stack( + children: [ + Icon(Icons.mail), + Positioned( + right: 0, + top: 0, + child: Container( + padding: EdgeInsets.all(1), + decoration: BoxDecoration( + color: Colors.red, + borderRadius: BorderRadius.circular(10), + ), + constraints: BoxConstraints( + minWidth: 16, + minHeight: 16, + ), + child: Text( + _availableInvitationsCount > 99 ? '99+' : '$_availableInvitationsCount', + style: TextStyle( + color: Colors.white, + fontSize: 10, + fontWeight: FontWeight.bold, + ), + textAlign: TextAlign.center, + ), + ), + ), + ], + ); + } + @override Widget build(BuildContext context) { return PopScope( @@ -32,7 +94,7 @@ class _HomeScreenState extends State { items: [ BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Feed'), BottomNavigationBarItem( - icon: Icon(Icons.mail), + icon: _buildInvitationsBadge(), label: 'Invitations', ), BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Profile'),