import 'package:flutter/material.dart'; import 'package:geosector_app/app.dart'; import 'package:geosector_app/core/data/models/amicale_model.dart'; /// Widget pour afficher une ligne du tableau d'amicales /// Affiche les colonnes id, name, codePostal, libRegion et une colonne Actions /// La colonne Actions contient un bouton Delete pour les utilisateurs avec rôle > 2 /// La ligne entière est cliquable pour afficher les détails de l'amicale class AmicaleRowWidget extends StatelessWidget { final AmicaleModel amicale; final Function(AmicaleModel)? onTap; final Function(AmicaleModel)? onDelete; final bool isHeader; final bool isAlternate; const AmicaleRowWidget({ Key? key, required this.amicale, this.onTap, this.onDelete, this.isHeader = false, this.isAlternate = false, }) : super(key: key); @override Widget build(BuildContext context) { final theme = Theme.of(context); final userRole = userRepository.getUserRole(); // Définir les styles en fonction du type de ligne (en-tête ou données) final textStyle = isHeader ? theme.textTheme.titleSmall?.copyWith( fontWeight: FontWeight.bold, color: theme.colorScheme.primary, ) : theme.textTheme.bodyMedium; // Couleur de fond en fonction du type de ligne final backgroundColor = isHeader ? theme.colorScheme.primary.withOpacity(0.1) : (isAlternate ? theme.colorScheme.surface : theme.colorScheme.background); return InkWell( onTap: isHeader || onTap == null ? null : () => onTap!(amicale), child: Container( decoration: BoxDecoration( color: backgroundColor, border: Border( bottom: BorderSide( color: theme.dividerColor.withOpacity(0.3), width: 1, ), ), ), child: Padding( padding: const EdgeInsets.symmetric(vertical: 8.0), child: Row( children: [ // Colonne ID Expanded( flex: 1, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 8.0), child: Text( isHeader ? 'ID' : amicale.id.toString(), style: textStyle, overflow: TextOverflow.ellipsis, ), ), ), // Colonne Nom Expanded( flex: 4, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 8.0), child: Text( isHeader ? 'Nom' : amicale.name, style: textStyle, overflow: TextOverflow.ellipsis, ), ), ), // Colonne Code Postal Expanded( flex: 2, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 8.0), child: Text( isHeader ? 'Code Postal' : amicale.codePostal, style: textStyle, overflow: TextOverflow.ellipsis, ), ), ), // Colonne Ville Expanded( flex: 2, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 8.0), child: Text( isHeader ? 'Ville' : (amicale.ville ?? ''), style: textStyle, overflow: TextOverflow.ellipsis, ), ), ), // Colonne Région Expanded( flex: 3, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 8.0), child: Text( isHeader ? 'Région' : (amicale.libRegion ?? ''), style: textStyle, overflow: TextOverflow.ellipsis, ), ), ), // Colonne Actions - seulement si l'utilisateur a le rôle > 2 et onDelete n'est pas null if (isHeader || (userRole > 2 && onDelete != null)) Expanded( flex: 2, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 8.0), child: isHeader ? Text( 'Actions', style: textStyle, overflow: TextOverflow.ellipsis, ) : Row( mainAxisAlignment: MainAxisAlignment.start, children: [ // Bouton Delete IconButton( icon: Icon( Icons.delete, color: theme.colorScheme.error, size: 20, ), tooltip: 'Supprimer', onPressed: () => onDelete!(amicale), constraints: const BoxConstraints( minWidth: 36, minHeight: 36, ), padding: EdgeInsets.zero, visualDensity: VisualDensity.compact, ), ], ), ), ), ], ), ), ), ); } }