mobile_team/lib/screens/home_screen.dart
2026-04-16 15:06:41 +05:30

141 lines
4.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/auth_provider.dart';
import 'tabs/today_logs_tab.dart';
import 'tabs/projects_tab.dart';
import 'tabs/all_logs_tab.dart';
import 'tabs/reports_tab.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
int _currentIndex = 0;
final List<String> _titles = ["Today's Log", "Projects", "All Team Logs", "Reports"];
final List<Widget> _tabs = [
const TodayLogsTab(),
const ProjectsTab(),
const AllLogsTab(),
const ReportsTab(),
];
@override
Widget build(BuildContext context) {
String? userName = context.watch<AuthProvider>().user?.name;
return Scaffold(
appBar: AppBar(
title: Text(_titles[_currentIndex]),
actions: [
IconButton(
onPressed: () {
context.read<AuthProvider>().logout();
},
icon: const Icon(Icons.logout),
tooltip: "Logout",
),
],
),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
UserAccountsDrawerHeader(
accountName: Text(userName ?? "User"),
accountEmail: Text(context.watch<AuthProvider>().user?.email ?? ""),
currentAccountPicture: const CircleAvatar(
backgroundColor: Colors.white,
child: Icon(Icons.person, color: Colors.indigo, size: 40),
),
decoration: const BoxDecoration(
color: Colors.indigo,
),
),
ListTile(
leading: const Icon(Icons.today),
title: const Text("Today's Log"),
selected: _currentIndex == 0,
onTap: () {
setState(() => _currentIndex = 0);
Navigator.pop(context);
},
),
ListTile(
leading: const Icon(Icons.folder_shared),
title: const Text("Projects"),
selected: _currentIndex == 1,
onTap: () {
setState(() => _currentIndex = 1);
Navigator.pop(context);
},
),
ListTile(
leading: const Icon(Icons.list_alt),
title: const Text("All Logs"),
selected: _currentIndex == 2,
onTap: () {
setState(() => _currentIndex = 2);
Navigator.pop(context);
},
),
ListTile(
leading: const Icon(Icons.bar_chart),
title: const Text("Reports"),
selected: _currentIndex == 3,
onTap: () {
setState(() => _currentIndex = 3);
Navigator.pop(context);
},
),
const Divider(),
ListTile(
leading: const Icon(Icons.logout, color: Colors.red),
title: const Text("Logout", style: TextStyle(color: Colors.red)),
onTap: () {
Navigator.pop(context);
context.read<AuthProvider>().logout();
},
),
],
),
),
body: IndexedStack(
index: _currentIndex,
children: _tabs,
),
bottomNavigationBar: NavigationBar(
selectedIndex: _currentIndex,
onDestinationSelected: (index) => setState(() => _currentIndex = index),
destinations: const [
NavigationDestination(
icon: Icon(Icons.today_outlined),
selectedIcon: Icon(Icons.today),
label: 'Today',
),
NavigationDestination(
icon: Icon(Icons.folder_outlined),
selectedIcon: Icon(Icons.folder),
label: 'Projects',
),
NavigationDestination(
icon: Icon(Icons.list_alt_outlined),
selectedIcon: Icon(Icons.list_alt),
label: 'All Logs',
),
NavigationDestination(
icon: Icon(Icons.insights_outlined),
selectedIcon: Icon(Icons.insights),
label: 'Reports',
),
],
),
);
}
}