- Correction mapping JSON membres (fk_role, chk_active) - Ajout traitement amicale au login - Fix callback onSubmit pour sync Hive après update API
229 lines
7.4 KiB
Dart
229 lines
7.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:geosector_app/core/data/models/membre_model.dart';
|
|
|
|
class MembreRowWidget extends StatelessWidget {
|
|
final MembreModel membre;
|
|
final Function(MembreModel)? onEdit;
|
|
final Function(MembreModel)? onDelete;
|
|
final bool isAlternate;
|
|
|
|
const MembreRowWidget({
|
|
super.key,
|
|
required this.membre,
|
|
this.onEdit,
|
|
this.onDelete,
|
|
this.isAlternate = false,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
|
|
// Couleur de fond alternée
|
|
final backgroundColor = isAlternate ? theme.colorScheme.surface : theme.colorScheme.surface;
|
|
|
|
return InkWell(
|
|
onTap: () => _showMembreDetails(context),
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0),
|
|
decoration: BoxDecoration(
|
|
color: backgroundColor,
|
|
),
|
|
child: Row(
|
|
children: [
|
|
// ID
|
|
Expanded(
|
|
flex: 1,
|
|
child: Text(
|
|
membre.id.toString(),
|
|
style: theme.textTheme.bodyMedium,
|
|
),
|
|
),
|
|
|
|
// Prénom (firstName)
|
|
Expanded(
|
|
flex: 2,
|
|
child: Text(
|
|
membre.firstName ?? '',
|
|
style: theme.textTheme.bodyMedium,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
|
|
// Nom (name)
|
|
Expanded(
|
|
flex: 2,
|
|
child: Text(
|
|
membre.name ?? '',
|
|
style: theme.textTheme.bodyMedium,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
|
|
// Email
|
|
Expanded(
|
|
flex: 3,
|
|
child: Text(
|
|
membre.email,
|
|
style: theme.textTheme.bodyMedium,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
|
|
// Rôle (role au lieu de fkRole)
|
|
Expanded(
|
|
flex: 1,
|
|
child: Text(
|
|
_getRoleName(membre.role),
|
|
style: theme.textTheme.bodyMedium,
|
|
),
|
|
),
|
|
|
|
// Statut (isActive au lieu de chkActive)
|
|
Expanded(
|
|
flex: 1,
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: membre.isActive ? Colors.green.withOpacity(0.1) : Colors.red.withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(
|
|
color: membre.isActive ? Colors.green.withOpacity(0.3) : Colors.red.withOpacity(0.3),
|
|
),
|
|
),
|
|
child: Text(
|
|
membre.isActive ? 'Actif' : 'Inactif',
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: membre.isActive ? Colors.green[700] : Colors.red[700],
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
),
|
|
|
|
// Actions
|
|
if (onEdit != null || onDelete != null)
|
|
Expanded(
|
|
flex: 2,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
// Bouton Edit
|
|
if (onEdit != null)
|
|
IconButton(
|
|
icon: Icon(
|
|
Icons.edit,
|
|
size: 20,
|
|
color: theme.colorScheme.primary,
|
|
),
|
|
onPressed: () => onEdit!(membre),
|
|
tooltip: 'Modifier',
|
|
constraints: const BoxConstraints(
|
|
minWidth: 36,
|
|
minHeight: 36,
|
|
),
|
|
padding: EdgeInsets.zero,
|
|
visualDensity: VisualDensity.compact,
|
|
),
|
|
|
|
// Espacement entre les boutons
|
|
if (onEdit != null && onDelete != null) const SizedBox(width: 8),
|
|
|
|
// Bouton Delete
|
|
if (onDelete != null)
|
|
IconButton(
|
|
icon: Icon(
|
|
Icons.delete,
|
|
size: 20,
|
|
color: theme.colorScheme.error,
|
|
),
|
|
onPressed: () => onDelete!(membre),
|
|
tooltip: 'Supprimer',
|
|
constraints: const BoxConstraints(
|
|
minWidth: 36,
|
|
minHeight: 36,
|
|
),
|
|
padding: EdgeInsets.zero,
|
|
visualDensity: VisualDensity.compact,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Afficher les détails du membre dans une boîte de dialogue
|
|
void _showMembreDetails(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: Text('${membre.firstName ?? ''} ${membre.name ?? ''}'),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
_buildDetailRow('ID', membre.id.toString()),
|
|
_buildDetailRow('Email', membre.email),
|
|
_buildDetailRow('Username', membre.username ?? 'Non défini'),
|
|
_buildDetailRow('Rôle', _getRoleName(membre.role)),
|
|
_buildDetailRow('Titre', membre.fkTitre?.toString() ?? 'Non défini'),
|
|
_buildDetailRow('Secteur', membre.sectName ?? 'Non défini'),
|
|
_buildDetailRow('Statut', membre.isActive ? 'Actif' : 'Inactif'),
|
|
_buildDetailRow('Téléphone', membre.phone ?? 'Non défini'),
|
|
_buildDetailRow('Mobile', membre.mobile ?? 'Non défini'),
|
|
if (membre.dateNaissance != null)
|
|
_buildDetailRow('Date de naissance', '${membre.dateNaissance!.day}/${membre.dateNaissance!.month}/${membre.dateNaissance!.year}'),
|
|
if (membre.dateEmbauche != null)
|
|
_buildDetailRow('Date d\'embauche', '${membre.dateEmbauche!.day}/${membre.dateEmbauche!.month}/${membre.dateEmbauche!.year}'),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('Fermer'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildDetailRow(String label, String value) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
SizedBox(
|
|
width: 120,
|
|
child: Text(
|
|
'$label:',
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Text(value),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// Méthode pour convertir l'ID de rôle en nom lisible
|
|
String _getRoleName(int roleId) {
|
|
switch (roleId) {
|
|
case 1:
|
|
return 'User';
|
|
case 2:
|
|
return 'Admin';
|
|
case 3:
|
|
return 'Super';
|
|
default:
|
|
return roleId.toString();
|
|
}
|
|
}
|
|
}
|