Refacto et clean
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ class EventDetails extends StatelessWidget {
|
||||
final EventModel event;
|
||||
|
||||
const EventDetails({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.event,
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
Reference in New Issue
Block a user