107 lines
2.8 KiB
Dart
107 lines
2.8 KiB
Dart
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
|
|
_HomeScreenState createState() => _HomeScreenState();
|
|
}
|
|
|
|
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(
|
|
canPop: false, // Prevent going back to authentication screens
|
|
child: Scaffold(
|
|
body: _pages[_currentIndex],
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
currentIndex: _currentIndex,
|
|
onTap: (index) {
|
|
setState(() {
|
|
_currentIndex = index;
|
|
});
|
|
},
|
|
type: BottomNavigationBarType.fixed,
|
|
selectedItemColor: Color(0xFF6A4C93),
|
|
unselectedItemColor: Colors.grey,
|
|
items: [
|
|
BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Feed'),
|
|
BottomNavigationBarItem(
|
|
icon: _buildInvitationsBadge(),
|
|
label: 'Invitations',
|
|
),
|
|
BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Profile'),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|