86 lines
2.0 KiB
Dart
86 lines
2.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:geosector_app/chat/services/chat_info_service.dart';
|
|
|
|
/// Fonction helper pour créer une NavigationDestination avec badge
|
|
NavigationDestination createBadgedNavigationDestination({
|
|
required Icon icon,
|
|
required Icon selectedIcon,
|
|
required String label,
|
|
bool showBadge = false,
|
|
}) {
|
|
if (!showBadge) {
|
|
return NavigationDestination(
|
|
icon: icon,
|
|
selectedIcon: selectedIcon,
|
|
label: label,
|
|
);
|
|
}
|
|
|
|
// Créer les icônes avec badge
|
|
final badgedIcon = BadgedIcon(
|
|
icon: icon.icon!,
|
|
showBadge: true,
|
|
color: icon.color,
|
|
size: icon.size,
|
|
);
|
|
|
|
final badgedSelectedIcon = BadgedIcon(
|
|
icon: selectedIcon.icon!,
|
|
showBadge: true,
|
|
color: selectedIcon.color,
|
|
size: selectedIcon.size,
|
|
);
|
|
|
|
return NavigationDestination(
|
|
icon: badgedIcon,
|
|
selectedIcon: badgedSelectedIcon,
|
|
label: label,
|
|
);
|
|
}
|
|
|
|
/// Widget pour afficher un badge sur une icône
|
|
class BadgedIcon extends StatelessWidget {
|
|
final IconData icon;
|
|
final bool showBadge;
|
|
final Color? color;
|
|
final double? size;
|
|
|
|
const BadgedIcon({
|
|
super.key,
|
|
required this.icon,
|
|
this.showBadge = false,
|
|
this.color,
|
|
this.size,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final iconWidget = Icon(icon, color: color, size: size);
|
|
|
|
if (!showBadge) {
|
|
return iconWidget;
|
|
}
|
|
|
|
return AnimatedBuilder(
|
|
animation: ChatInfoService.instance,
|
|
builder: (context, _) {
|
|
final unreadCount = ChatInfoService.instance.unreadMessages;
|
|
final badgeLabel = ChatInfoService.instance.badgeLabel;
|
|
|
|
if (unreadCount == 0) {
|
|
return iconWidget;
|
|
}
|
|
|
|
return Badge(
|
|
label: Text(
|
|
badgeLabel,
|
|
style: const TextStyle(fontSize: 10),
|
|
),
|
|
backgroundColor: Colors.red,
|
|
textColor: Colors.white,
|
|
child: iconWidget,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
} |