Refacto et clean

This commit is contained in:
2025-05-18 20:34:57 +02:00
parent 62c6125d8c
commit 6adc90ecfe
13 changed files with 830 additions and 792 deletions

View File

@ -3,25 +3,33 @@ import 'package:provider/provider.dart';
import 'package:em2rp/providers/local_user_provider.dart';
import 'package:em2rp/utils/colors.dart';
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
class CustomAppBar extends StatefulWidget implements PreferredSizeWidget {
final String title;
final List<Widget>? actions;
final bool showLogoutButton;
const CustomAppBar({
Key? key,
super.key,
required this.title,
this.actions,
this.showLogoutButton = true,
}) : super(key: key);
});
@override
State<CustomAppBar> createState() => _CustomAppBarState();
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}
class _CustomAppBarState extends State<CustomAppBar> {
@override
Widget build(BuildContext context) {
return AppBar(
title: Text(title),
title: Text(widget.title),
backgroundColor: AppColors.rouge,
actions: [
if (showLogoutButton)
if (widget.showLogoutButton)
IconButton(
icon: const Icon(Icons.logout, color: AppColors.blanc),
onPressed: () async {
@ -45,21 +53,19 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
),
);
if (shouldLogout == true) {
if (shouldLogout == true && context.mounted) {
// Déconnexion
await Provider.of<LocalUserProvider>(context, listen: false)
.signOut();
final provider =
Provider.of<LocalUserProvider>(context, listen: false);
await provider.signOut();
if (context.mounted) {
Navigator.of(context).pushReplacementNamed('/login');
}
}
},
),
if (actions != null) ...actions!,
if (widget.actions != null) ...widget.actions!,
],
);
}
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}