petitspas/frontend/lib/screens/home/parent_screen/ParentDashboardScreen.dart
Julien Martin 4339e1e53d feat(100): bandeau dashboard générique, icônes rôle/email, footer go_router, user fromJson défensif
- Bandeau générique DashboardBandeau (logo | onglets | capsule utilisateur)
- Capsule: icône rôle (admin/gestionnaire/parent/AM) + Prénom Nom + menu (email avec icône, Profil, Paramètres, Déconnexion)
- Migration admin, gestionnaire, parent, AM vers DashboardBandeau
- Écran AM (page blanche), route /am-dashboard
- Routes /privacy et /legal, footer avec context.push
- AppUser.fromJson: id/email/role null-safe
- Suppression DashboardAppBarAdmin et dashboard_app_bar.dart

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-25 19:50:53 +01:00

264 lines
8.4 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import 'package:p_tits_pas/controllers/parent_dashboard_controller.dart';
import 'package:p_tits_pas/models/user.dart';
import 'package:p_tits_pas/services/auth_service.dart';
import 'package:p_tits_pas/services/dashboardService.dart';
import 'package:p_tits_pas/widgets/app_footer.dart';
import 'package:p_tits_pas/widgets/dashbord_parent/children_sidebar.dart';
import 'package:p_tits_pas/widgets/dashbord_parent/wid_dashbord.dart';
import 'package:p_tits_pas/widgets/dashboard/dashboard_bandeau.dart';
import 'package:p_tits_pas/widgets/main_content_area.dart';
import 'package:p_tits_pas/widgets/messaging_sidebar.dart';
import 'package:provider/provider.dart';
class ParentDashboardScreen extends StatefulWidget {
const ParentDashboardScreen({Key? key}) : super(key: key);
@override
State<ParentDashboardScreen> createState() => _ParentDashboardScreenState();
}
class _ParentDashboardScreenState extends State<ParentDashboardScreen> {
int selectedIndex = 0;
AppUser? _user;
void onTabChange(int index) {
setState(() {
selectedIndex = index;
});
}
@override
void initState() {
super.initState();
_loadUser();
// Initialiser les données du dashboard
WidgetsBinding.instance.addPostFrameCallback((_) {
context.read<ParentDashboardController>().initDashboard();
});
}
Future<void> _loadUser() async {
final user = await AuthService.getCurrentUser();
if (mounted) setState(() => _user = user);
}
Widget _getBody() {
switch (selectedIndex) {
case 0:
return Dashbord_body();
case 1:
return const Center(child: Text("🔍 Trouver une nounou"));
case 2:
return const Center(child: Text("⚙️ Paramètres"));
default:
return const Center(child: Text("Page non trouvée"));
}
}
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => ParentDashboardController(DashboardService())..initDashboard(),
child: Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(60.0),
child: DashboardBandeau(
tabItems: const [
DashboardTabItem(label: 'Mon tableau de bord'),
DashboardTabItem(label: 'Trouver une nounou'),
DashboardTabItem(label: 'Paramètres'),
],
selectedTabIndex: selectedIndex,
onTabSelected: onTabChange,
userDisplayName: _user?.fullName.isNotEmpty == true
? _user!.fullName
: 'Parent',
userEmail: _user?.email,
userRole: _user?.role,
onProfileTap: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Modification du profil à venir')),
);
},
onSettingsTap: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Paramètres à venir')),
);
},
onLogout: () {},
showLogoutConfirmation: true,
),
),
body: Column(
children: [
Expanded(child: _getBody()),
const AppFooter(),
],
),
),
);
}
Widget _buildResponsiveBody(BuildContext context, ParentDashboardController controller) {
return LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth < 768) {
// Layout mobile : colonnes empilées
return _buildMobileLayout(controller);
} else if (constraints.maxWidth < 1024) {
// Layout tablette : 2 colonnes
return _buildTabletLayout(controller);
} else {
// Layout desktop : 3 colonnes
return _buildDesktopLayout(controller);
}
},
);
}
Widget _buildDesktopLayout(ParentDashboardController controller) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Sidebar gauche - Enfants
SizedBox(
width: 280,
child: ChildrenSidebar(
children: controller.children,
selectedChildId: controller.selectedChildId,
onChildSelected: controller.selectChild,
onAddChild: controller.showAddChildModal,
),
),
// Contenu central
Expanded(
flex: 2,
child: MainContentArea(
selectedChild: controller.selectedChild,
selectedAssistant: controller.selectedAssistant,
events: controller.upcomingEvents,
contracts: controller.contracts,
),
),
// Sidebar droite - Messagerie
SizedBox(
width: 320,
child: MessagingSidebar(
conversations: controller.conversations,
notifications: controller.notifications,
),
),
],
);
}
Widget _buildTabletLayout(ParentDashboardController controller) {
return Row(
children: [
// Sidebar enfants plus étroite
SizedBox(
width: 240,
child: ChildrenSidebar(
children: controller.children,
selectedChildId: controller.selectedChildId,
onChildSelected: controller.selectChild,
onAddChild: controller.showAddChildModal,
isCompact: true,
),
),
// Contenu principal avec messagerie intégrée
Expanded(
child: Column(
children: [
Expanded(
flex: 2,
child: MainContentArea(
selectedChild: controller.selectedChild,
selectedAssistant: controller.selectedAssistant,
events: controller.upcomingEvents,
contracts: controller.contracts,
),
),
SizedBox(
height: 200,
child: MessagingSidebar(
conversations: controller.conversations,
notifications: controller.notifications,
isCompact: true,
),
),
],
),
),
],
);
}
Widget _buildMobileLayout(ParentDashboardController controller) {
return DefaultTabController(
length: 4,
child: Column(
children: [
// Navigation par onglets sur mobile
Container(
color: Theme.of(context).primaryColor.withOpacity(0.1),
child: const TabBar(
isScrollable: true,
tabs: [
Tab(text: 'Enfants', icon: Icon(Icons.child_care)),
Tab(text: 'Planning', icon: Icon(Icons.calendar_month)),
Tab(text: 'Contrats', icon: Icon(Icons.description)),
Tab(text: 'Messages', icon: Icon(Icons.message)),
],
),
),
Expanded(
child: TabBarView(
children: [
// Onglet Enfants
ChildrenSidebar(
children: controller.children,
selectedChildId: controller.selectedChildId,
onChildSelected: controller.selectChild,
onAddChild: controller.showAddChildModal,
isMobile: true,
),
// Onglet Planning
MainContentArea(
selectedChild: controller.selectedChild,
selectedAssistant: controller.selectedAssistant,
events: controller.upcomingEvents,
contracts: controller.contracts,
showOnlyCalendar: true,
),
// Onglet Contrats
MainContentArea(
selectedChild: controller.selectedChild,
selectedAssistant: controller.selectedAssistant,
events: controller.upcomingEvents,
contracts: controller.contracts,
showOnlyContracts: true,
),
// Onglet Messages
MessagingSidebar(
conversations: controller.conversations,
notifications: controller.notifications,
isMobile: true,
),
],
),
),
],
),
);
}
}