feat: Add user-specific group retrieval and enhance UI with dynamic theming
This commit is contained in:
@@ -287,12 +287,19 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
required DateTime? date,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
// Détecter le thème actuel
|
||||
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
||||
final textColor = isDarkMode ? Colors.white : Colors.black;
|
||||
final labelColor = isDarkMode ? Colors.white70 : Colors.grey[600];
|
||||
final iconColor = isDarkMode ? Colors.white70 : Colors.grey[600];
|
||||
final placeholderColor = isDarkMode ? Colors.white38 : Colors.grey[500];
|
||||
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey[400]!),
|
||||
border: Border.all(color: isDarkMode ? Colors.white24 : Colors.grey[400]!),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
@@ -300,12 +307,12 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
|
||||
style: TextStyle(fontSize: 12, color: labelColor),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.calendar_today, size: 16, color: Colors.grey[600]),
|
||||
Icon(Icons.calendar_today, size: 16, color: iconColor),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
date != null
|
||||
@@ -313,7 +320,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
: 'Sélectionner',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: date != null ? Colors.black : Colors.grey[500],
|
||||
color: date != null ? textColor : placeholderColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -403,25 +410,35 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
});
|
||||
}
|
||||
|
||||
Future<bool> _saveGroup() async {
|
||||
Future<bool> _saveGroup(String currentUserId) async {
|
||||
if (!_formKey.currentState!.validate()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
// Convertir les emails en IDs
|
||||
final participantIds = await _changeUserEmailById(_participants);
|
||||
|
||||
// Créer la liste des membres incluant le créateur
|
||||
List<String> allMembers = [currentUserId];
|
||||
|
||||
// Ajouter tous les participants (éviter les doublons)
|
||||
for (String participantId in participantIds) {
|
||||
if (!allMembers.contains(participantId)) {
|
||||
allMembers.add(participantId);
|
||||
}
|
||||
}
|
||||
|
||||
final members = await _changeUserEmailById(_participants);
|
||||
print('Membres du groupe: $allMembers');
|
||||
|
||||
final group = Group(
|
||||
id: '',
|
||||
name: _titleController.text.trim(),
|
||||
members: members,
|
||||
members: allMembers, // Contient le créateur + tous les participants
|
||||
);
|
||||
|
||||
final groupService = GroupService();
|
||||
bool success = await groupService.createGroup(group);
|
||||
print('Groupe créé avec succès: $success');
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -474,19 +491,21 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
final userProvider = Provider.of<UserProvider>(context, listen: false);
|
||||
final currentUser = userProvider.currentUser;
|
||||
|
||||
if (currentUser == null) {
|
||||
if (currentUser == null || currentUser.id == null) {
|
||||
throw Exception('Utilisateur non connecté');
|
||||
}
|
||||
|
||||
print('Création du voyage par: ${currentUser.id} (${currentUser.email})');
|
||||
|
||||
// Convertir les emails en IDs utilisateur
|
||||
List<String> participantIds = [];
|
||||
if (currentUser.id != null) {
|
||||
participantIds.add(currentUser.id!);
|
||||
List<String> participantIds = await _changeUserEmailById(_participants);
|
||||
|
||||
// Ajouter le créateur aux participants s'il n'y est pas déjà
|
||||
if (!participantIds.contains(currentUser.id!)) {
|
||||
participantIds.insert(0, currentUser.id!);
|
||||
}
|
||||
|
||||
participantIds = await _changeUserEmailById(_participants);
|
||||
print('Participants IDs (avec créateur): $participantIds');
|
||||
|
||||
// Créer l'objet Trip avec les IDs des participants
|
||||
final trip = Trip(
|
||||
@@ -497,8 +516,8 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
startDate: _startDate!,
|
||||
endDate: _endDate!,
|
||||
budget: double.tryParse(_budgetController.text) ?? 0.0,
|
||||
createdBy: currentUser.id ?? '',
|
||||
participants: participantIds, // Contient uniquement les IDs
|
||||
createdBy: currentUser.id!,
|
||||
participants: participantIds, // Contient le créateur + tous les participants
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
@@ -509,11 +528,11 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
final tripService = TripService();
|
||||
final success = await tripService.addTrip(trip);
|
||||
|
||||
//Créer le groupe associé au voyage
|
||||
final successGroup = await _saveGroup();
|
||||
// Créer le groupe associé au voyage avec le créateur inclus
|
||||
final successGroup = await _saveGroup(currentUser.id!);
|
||||
|
||||
if (success && successGroup && mounted) {
|
||||
print('Voyage créé avec succès !');
|
||||
print('Voyage et groupe créés avec succès !');
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Voyage créé avec succès !'),
|
||||
|
||||
Reference in New Issue
Block a user