Add SidebarAdmin
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:p_tits_pas/services/auth_service.dart';
|
||||
|
||||
class DashboardAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
final int selectedIndex;
|
||||
@@ -9,6 +10,29 @@ class DashboardAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
@override
|
||||
Size get preferredSize => const Size.fromHeight(kToolbarHeight + 10);
|
||||
|
||||
Future <String> _getUserName() async {
|
||||
final authS = AuthService();
|
||||
final userName = await authS.getUserNameById();
|
||||
return userName ?? 'Bienvenue';
|
||||
}
|
||||
|
||||
void _logout (BuildContext context) {
|
||||
try {
|
||||
final authS = AuthService();
|
||||
authS.logout();
|
||||
Navigator.of(context).pushReplacementNamed('/login');
|
||||
} catch (e) {
|
||||
print('Erreur lors de la déconnexion: $e');
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Erreur lors de la déconnexion'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isMobile = MediaQuery.of(context).size.width < 768;
|
||||
@@ -17,20 +41,6 @@ class DashboardAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
elevation: 0,
|
||||
title: Row(
|
||||
children: [
|
||||
// Logo de la ville
|
||||
// Container(
|
||||
// height: 32,
|
||||
// width: 32,
|
||||
// decoration: BoxDecoration(
|
||||
// color: Colors.white,
|
||||
// borderRadius: BorderRadius.circular(8),
|
||||
// ),
|
||||
// child: const Icon(
|
||||
// Icons.location_city,
|
||||
// color: Color(0xFF9CC5C0),
|
||||
// size: 20,
|
||||
// ),
|
||||
// ),
|
||||
SizedBox(width: MediaQuery.of(context).size.width * 0.19),
|
||||
const Text(
|
||||
"P'tit Pas",
|
||||
@@ -54,16 +64,20 @@ class DashboardAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
? [_buildMobileMenu(context)]
|
||||
: [
|
||||
// Nom de l'utilisateur
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Jean Dupont',
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
child: FutureBuilder<String>(
|
||||
future: _getUserName(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Text("Chargement...");
|
||||
} else if (snapshot.hasError) {
|
||||
return const Text("Erreur");
|
||||
} else {
|
||||
return Text(snapshot.data ?? "Admin");
|
||||
}
|
||||
}
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -145,6 +159,7 @@ class DashboardAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
_logout(context);
|
||||
// TODO: Implémenter la logique de déconnexion
|
||||
},
|
||||
child: const Text('Déconnecter'),
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:p_tits_pas/widgets/dashbord_parent/ChildrenSidebarwidget.dart';
|
||||
import 'package:p_tits_pas/widgets/dashbord_parent/children_sidebar.dart';
|
||||
import 'package:p_tits_pas/widgets/dashbord_parent/wid_mainContentArea.dart';
|
||||
import 'package:p_tits_pas/widgets/messaging_sidebar.dart';
|
||||
|
||||
Widget Dashbord_body() {
|
||||
return Row(
|
||||
|
||||
Reference in New Issue
Block a user