feat: add invitations badge with available invites
This commit is contained in:
parent
80a280a4aa
commit
8bc1c7bab1
@ -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<HomeScreen> {
|
||||
int _currentIndex = 0;
|
||||
int _availableInvitationsCount = 0;
|
||||
|
||||
final List<Widget> _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<HomeScreen> {
|
||||
items: [
|
||||
BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Feed'),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.mail),
|
||||
icon: _buildInvitationsBadge(),
|
||||
label: 'Invitations',
|
||||
),
|
||||
BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Profile'),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user