feat: Add logger service and improve expense dialog with enhanced receipt management and calculation logic.
This commit is contained in:
@@ -56,6 +56,7 @@
|
||||
/// - Group
|
||||
/// - ExpenseBloc
|
||||
library;
|
||||
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@@ -76,8 +77,10 @@ import '../../models/expense.dart';
|
||||
class AddExpenseDialog extends StatefulWidget {
|
||||
/// The group to which the expense belongs.
|
||||
final Group group;
|
||||
|
||||
/// The user creating or editing the expense.
|
||||
final user_state.UserModel currentUser;
|
||||
|
||||
/// The expense to edit (null for new expense).
|
||||
final Expense? expenseToEdit;
|
||||
|
||||
@@ -103,27 +106,40 @@ class AddExpenseDialog extends StatefulWidget {
|
||||
class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
||||
/// Form key for validating the expense form.
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
/// Controller for the expense description field.
|
||||
final _descriptionController = TextEditingController();
|
||||
|
||||
/// Controller for the expense amount field.
|
||||
final _amountController = TextEditingController();
|
||||
|
||||
/// The selected date for the expense.
|
||||
late DateTime _selectedDate;
|
||||
|
||||
/// The selected category for the expense.
|
||||
late ExpenseCategory _selectedCategory;
|
||||
|
||||
/// The selected currency for the expense.
|
||||
late ExpenseCurrency _selectedCurrency;
|
||||
|
||||
/// The user ID of the payer.
|
||||
late String _paidById;
|
||||
|
||||
/// Map of userId to split amount for each participant.
|
||||
final Map<String, double> _splits = {};
|
||||
|
||||
/// The selected receipt image file, if any.
|
||||
File? _receiptImage;
|
||||
|
||||
/// Whether the dialog is currently submitting data.
|
||||
bool _isLoading = false;
|
||||
|
||||
/// Whether the expense is split equally among participants.
|
||||
bool _splitEqually = true;
|
||||
|
||||
/// Whether the existing receipt has been removed.
|
||||
bool _receiptRemoved = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -172,7 +188,7 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
||||
if (pickedFile != null) {
|
||||
final file = File(pickedFile.path);
|
||||
final fileSize = await file.length();
|
||||
|
||||
|
||||
if (fileSize > 5 * 1024 * 1024) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -199,11 +215,11 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
||||
|
||||
final amount = double.tryParse(_amountController.text) ?? 0;
|
||||
final selectedMembers = _splits.entries.where((e) => e.value >= 0).toList();
|
||||
|
||||
|
||||
if (selectedMembers.isEmpty) return;
|
||||
|
||||
final splitAmount = amount / selectedMembers.length;
|
||||
|
||||
|
||||
setState(() {
|
||||
for (final entry in selectedMembers) {
|
||||
_splits[entry.key] = splitAmount;
|
||||
@@ -221,17 +237,14 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
|
||||
final amount = double.parse(_amountController.text);
|
||||
final selectedSplits = _splits.entries
|
||||
.where((e) => e.value > 0)
|
||||
.map((e) {
|
||||
final member = widget.group.members.firstWhere((m) => m.userId == e.key);
|
||||
return ExpenseSplit(
|
||||
userId: e.key,
|
||||
userName: member.firstName,
|
||||
amount: e.value,
|
||||
);
|
||||
})
|
||||
.toList();
|
||||
final selectedSplits = _splits.entries.where((e) => e.value > 0).map((e) {
|
||||
final member = widget.group.members.firstWhere((m) => m.userId == e.key);
|
||||
return ExpenseSplit(
|
||||
userId: e.key,
|
||||
userName: member.firstName,
|
||||
amount: e.value,
|
||||
);
|
||||
}).toList();
|
||||
|
||||
if (selectedSplits.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -248,11 +261,15 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
||||
try {
|
||||
// Convertir en EUR
|
||||
final amountInEur = context.read<ExpenseBloc>().state is ExpensesLoaded
|
||||
? (context.read<ExpenseBloc>().state as ExpensesLoaded)
|
||||
.exchangeRates[_selectedCurrency]! * amount
|
||||
? ((context.read<ExpenseBloc>().state as ExpensesLoaded)
|
||||
.exchangeRates[_selectedCurrency.code] ??
|
||||
1.0) *
|
||||
amount
|
||||
: amount;
|
||||
|
||||
final payer = widget.group.members.firstWhere((m) => m.userId == _paidById);
|
||||
final payer = widget.group.members.firstWhere(
|
||||
(m) => m.userId == _paidById,
|
||||
);
|
||||
|
||||
final expense = Expense(
|
||||
id: widget.expenseToEdit?.id ?? '',
|
||||
@@ -266,29 +283,29 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
||||
paidByName: payer.firstName,
|
||||
splits: selectedSplits,
|
||||
date: _selectedDate,
|
||||
receiptUrl: widget.expenseToEdit?.receiptUrl,
|
||||
receiptUrl: _receiptRemoved ? null : widget.expenseToEdit?.receiptUrl,
|
||||
createdAt: widget.expenseToEdit?.createdAt ?? DateTime.now(),
|
||||
);
|
||||
|
||||
if (widget.expenseToEdit == null) {
|
||||
context.read<ExpenseBloc>().add(CreateExpense(
|
||||
expense: expense,
|
||||
receiptImage: _receiptImage,
|
||||
));
|
||||
context.read<ExpenseBloc>().add(
|
||||
CreateExpense(expense: expense, receiptImage: _receiptImage),
|
||||
);
|
||||
} else {
|
||||
context.read<ExpenseBloc>().add(UpdateExpense(
|
||||
expense: expense,
|
||||
newReceiptImage: _receiptImage,
|
||||
));
|
||||
context.read<ExpenseBloc>().add(
|
||||
UpdateExpense(expense: expense, newReceiptImage: _receiptImage),
|
||||
);
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(widget.expenseToEdit == null
|
||||
? 'Dépense ajoutée'
|
||||
: 'Dépense modifiée'),
|
||||
content: Text(
|
||||
widget.expenseToEdit == null
|
||||
? 'Dépense ajoutée'
|
||||
: 'Dépense modifiée',
|
||||
),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
@@ -296,10 +313,7 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Erreur: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
SnackBar(content: Text('Erreur: $e'), backgroundColor: Colors.red),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
@@ -314,284 +328,425 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
||||
/// Returns a Dialog widget containing the expense form.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final isDark = theme.brightness == Brightness.dark;
|
||||
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
backgroundColor: isDark ? theme.scaffoldBackgroundColor : Colors.white,
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(maxWidth: 600, maxHeight: 700),
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(widget.expenseToEdit == null
|
||||
? 'Nouvelle dépense'
|
||||
: 'Modifier la dépense'),
|
||||
automaticallyImplyLeading: false,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
constraints: const BoxConstraints(maxWidth: 500, maxHeight: 800),
|
||||
child: Column(
|
||||
children: [
|
||||
// Header
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(24, 24, 16, 16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.expenseToEdit == null
|
||||
? 'Nouvelle dépense'
|
||||
: 'Modifier la dépense',
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
// Description
|
||||
TextFormField(
|
||||
controller: _descriptionController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Description',
|
||||
hintText: 'Ex: Restaurant, Essence...',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.description),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return 'Veuillez entrer une description';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
|
||||
// Montant et devise
|
||||
Row(
|
||||
// Form Content
|
||||
Expanded(
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: TextFormField(
|
||||
controller: _amountController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Montant',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.euro),
|
||||
// Description
|
||||
TextFormField(
|
||||
controller: _descriptionController,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Description',
|
||||
hintText: 'Ex: Restaurant, Essence...',
|
||||
prefixIcon: const Icon(Icons.description_outlined),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
onChanged: (_) => _calculateSplits(),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Requis';
|
||||
}
|
||||
if (double.tryParse(value) == null || double.parse(value) <= 0) {
|
||||
return 'Montant invalide';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<ExpenseCurrency>(
|
||||
initialValue: _selectedCurrency,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Devise',
|
||||
border: OutlineInputBorder(),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 16,
|
||||
),
|
||||
items: ExpenseCurrency.values.map((currency) {
|
||||
return DropdownMenuItem(
|
||||
value: currency,
|
||||
child: Text(currency.code),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() => _selectedCurrency = value);
|
||||
}
|
||||
},
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return 'Requis';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Catégorie
|
||||
DropdownButtonFormField<ExpenseCategory>(
|
||||
initialValue: _selectedCategory,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Catégorie',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.category),
|
||||
),
|
||||
items: ExpenseCategory.values.map((category) {
|
||||
return DropdownMenuItem(
|
||||
value: category,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(category.icon, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Text(category.displayName),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() => _selectedCategory = value);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Date
|
||||
ListTile(
|
||||
leading: const Icon(Icons.calendar_today),
|
||||
title: const Text('Date'),
|
||||
subtitle: Text(DateFormat('dd/MM/yyyy').format(_selectedDate)),
|
||||
shape: RoundedRectangleBorder(
|
||||
side: BorderSide(color: Colors.grey[300]!),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
onTap: () async {
|
||||
final date = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _selectedDate,
|
||||
firstDate: DateTime(2020),
|
||||
lastDate: DateTime.now().add(const Duration(days: 365)),
|
||||
);
|
||||
if (date != null) {
|
||||
setState(() => _selectedDate = date);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Payé par
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: _paidById,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Payé par',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.person),
|
||||
),
|
||||
items: widget.group.members.map((member) {
|
||||
return DropdownMenuItem(
|
||||
value: member.userId,
|
||||
child: Text(member.firstName),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() => _paidById = value);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Division
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
// Montant et Devise
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
'Division',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: TextFormField(
|
||||
controller: _amountController,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Montant',
|
||||
prefixIcon: const Icon(Icons.euro_symbol),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 16,
|
||||
),
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
),
|
||||
onChanged: (_) => _calculateSplits(),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Requis';
|
||||
}
|
||||
if (double.tryParse(value) == null ||
|
||||
double.parse(value) <= 0) {
|
||||
return 'Invalide';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<ExpenseCurrency>(
|
||||
initialValue: _selectedCurrency,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Devise',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 16,
|
||||
),
|
||||
),
|
||||
items: ExpenseCurrency.values.map((currency) {
|
||||
return DropdownMenuItem(
|
||||
value: currency,
|
||||
child: Text(currency.code),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() => _selectedCurrency = value);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Catégorie
|
||||
DropdownButtonFormField<ExpenseCategory>(
|
||||
initialValue: _selectedCategory,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Catégorie',
|
||||
prefixIcon: Icon(_selectedCategory.icon),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 16,
|
||||
),
|
||||
),
|
||||
items: ExpenseCategory.values.map((category) {
|
||||
return DropdownMenuItem(
|
||||
value: category,
|
||||
child: Text(category.displayName),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() => _selectedCategory = value);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Date
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
final date = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _selectedDate,
|
||||
firstDate: DateTime(2020),
|
||||
lastDate: DateTime.now().add(
|
||||
const Duration(days: 365),
|
||||
),
|
||||
);
|
||||
if (date != null) setState(() => _selectedDate = date);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: InputDecorator(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Date',
|
||||
prefixIcon: const Icon(Icons.calendar_today_outlined),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 16,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
DateFormat('dd/MM/yyyy').format(_selectedDate),
|
||||
style: theme.textTheme.bodyLarge,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Payé par
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: _paidById,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Payé par',
|
||||
prefixIcon: const Icon(Icons.person_outline),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 16,
|
||||
),
|
||||
),
|
||||
items: widget.group.members.map((member) {
|
||||
return DropdownMenuItem(
|
||||
value: member.userId,
|
||||
child: Text(member.firstName),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) setState(() => _paidById = value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Division Section
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? Colors.grey[800] : Colors.grey[50],
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: theme.dividerColor),
|
||||
),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
'Division',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'Égale',
|
||||
style: TextStyle(
|
||||
color: isDark
|
||||
? Colors.grey[400]
|
||||
: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Switch(
|
||||
value: _splitEqually,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_splitEqually = value;
|
||||
if (value) _calculateSplits();
|
||||
});
|
||||
},
|
||||
activeThumbColor: theme.colorScheme.primary,
|
||||
),
|
||||
],
|
||||
),
|
||||
const Divider(),
|
||||
...widget.group.members.map((member) {
|
||||
final isSelected =
|
||||
_splits.containsKey(member.userId) &&
|
||||
_splits[member.userId]! >= 0;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
member.firstName,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
if (!_splitEqually && isSelected)
|
||||
SizedBox(
|
||||
width: 100,
|
||||
child: TextFormField(
|
||||
initialValue: _splits[member.userId]
|
||||
?.toStringAsFixed(2),
|
||||
decoration: const InputDecoration(
|
||||
isDense: true,
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 8,
|
||||
),
|
||||
border: OutlineInputBorder(),
|
||||
suffixText: '€',
|
||||
),
|
||||
keyboardType:
|
||||
const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
),
|
||||
onChanged: (value) {
|
||||
final amount =
|
||||
double.tryParse(value) ?? 0;
|
||||
setState(
|
||||
() =>
|
||||
_splits[member.userId] = amount,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Checkbox(
|
||||
value: isSelected,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
if (value == true) {
|
||||
_splits[member.userId] = 0;
|
||||
if (_splitEqually) _calculateSplits();
|
||||
} else {
|
||||
_splits[member.userId] = -1;
|
||||
}
|
||||
});
|
||||
},
|
||||
activeColor: theme.colorScheme.primary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Reçu (Optional - keeping simple for now as per design focus)
|
||||
if (_receiptImage != null ||
|
||||
(widget.expenseToEdit?.receiptUrl != null &&
|
||||
!_receiptRemoved))
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: theme.dividerColor),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.receipt_long, color: Colors.green),
|
||||
const SizedBox(width: 8),
|
||||
const Text('Reçu joint'),
|
||||
const Spacer(),
|
||||
Text(_splitEqually ? 'Égale' : 'Personnalisée'),
|
||||
Switch(
|
||||
value: _splitEqually,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_splitEqually = value;
|
||||
if (value) _calculateSplits();
|
||||
});
|
||||
},
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => setState(() {
|
||||
_receiptImage = null;
|
||||
_receiptRemoved = true;
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Divider(),
|
||||
...widget.group.members.map((member) {
|
||||
final isSelected = _splits.containsKey(member.userId) &&
|
||||
_splits[member.userId]! >= 0;
|
||||
|
||||
return CheckboxListTile(
|
||||
title: Text(member.firstName),
|
||||
subtitle: _splitEqually || !isSelected
|
||||
? null
|
||||
: TextFormField(
|
||||
initialValue: _splits[member.userId]?.toStringAsFixed(2),
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Montant',
|
||||
isDense: true,
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
onChanged: (value) {
|
||||
final amount = double.tryParse(value) ?? 0;
|
||||
setState(() => _splits[member.userId] = amount);
|
||||
},
|
||||
),
|
||||
value: isSelected,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
if (value == true) {
|
||||
_splits[member.userId] = 0;
|
||||
if (_splitEqually) _calculateSplits();
|
||||
} else {
|
||||
_splits[member.userId] = -1;
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Reçu
|
||||
ListTile(
|
||||
leading: const Icon(Icons.receipt),
|
||||
title: Text(_receiptImage != null || widget.expenseToEdit?.receiptUrl != null
|
||||
? 'Reçu ajouté'
|
||||
: 'Ajouter un reçu'),
|
||||
subtitle: _receiptImage != null
|
||||
? const Text('Nouveau reçu sélectionné')
|
||||
: null,
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.add_photo_alternate),
|
||||
onPressed: _pickImage,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
side: BorderSide(color: Colors.grey[300]!),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Boutons
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: _isLoading ? null : () => Navigator.of(context).pop(),
|
||||
child: const Text('Annuler'),
|
||||
)
|
||||
else
|
||||
OutlinedButton.icon(
|
||||
onPressed: _pickImage,
|
||||
icon: const Icon(Icons.camera_alt_outlined),
|
||||
label: const Text('Ajouter un reçu'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: _isLoading ? null : _submit,
|
||||
child: _isLoading
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: Text(widget.expenseToEdit == null ? 'Ajouter' : 'Modifier'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Bottom Button
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: _isLoading ? null : _submit,
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
backgroundColor: theme.colorScheme.primary,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
),
|
||||
child: _isLoading
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
Colors.white,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
widget.expenseToEdit == null
|
||||
? 'Ajouter'
|
||||
: 'Enregistrer',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -7,11 +7,13 @@ import 'expense_detail_dialog.dart';
|
||||
class ExpensesTab extends StatelessWidget {
|
||||
final List<Expense> expenses;
|
||||
final Group group;
|
||||
final String currentUserId;
|
||||
|
||||
const ExpensesTab({
|
||||
super.key,
|
||||
required this.expenses,
|
||||
required this.group,
|
||||
required this.currentUserId,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -48,95 +50,157 @@ class ExpensesTab extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _buildExpenseCard(BuildContext context, Expense expense) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final dateFormat = DateFormat('dd/MM/yyyy');
|
||||
final theme = Theme.of(context);
|
||||
final isDark = theme.brightness == Brightness.dark;
|
||||
final dateFormat = DateFormat('dd/MM');
|
||||
|
||||
return Card(
|
||||
// Logique pour déterminer l'impact sur l'utilisateur
|
||||
bool isPayer = expense.paidById == currentUserId;
|
||||
double amountToDisplay = expense.amount;
|
||||
bool isPositive = isPayer;
|
||||
|
||||
// Si je suis le payeur, je suis en positif (on me doit de l'argent)
|
||||
// Si je ne suis pas le payeur, je suis en négatif (je dois de l'argent)
|
||||
// Note: Pour être précis, il faudrait calculer ma part exacte, mais pour l'instant
|
||||
// on affiche le total avec la couleur indiquant si j'ai payé ou non.
|
||||
|
||||
final amountColor = isPositive ? Colors.green : Colors.red;
|
||||
final prefix = isPositive ? '+' : '-';
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
child: InkWell(
|
||||
onTap: () => _showExpenseDetail(context, expense),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? Colors.blue[900] : Colors.blue[100],
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? theme.cardColor : Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.05),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => _showExpenseDetail(context, expense),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
// Icone circulaire
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: _getCategoryColor(
|
||||
expense.category,
|
||||
).withValues(alpha: 0.2),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
expense.category.icon,
|
||||
color: _getCategoryColor(expense.category),
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
expense.category.icon,
|
||||
color: Colors.blue,
|
||||
const SizedBox(width: 16),
|
||||
|
||||
// Détails
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
expense.description,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
isPayer
|
||||
? 'Payé par vous'
|
||||
: 'Payé par ${expense.paidByName}',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: isDark
|
||||
? Colors.grey[400]
|
||||
: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
' • ${dateFormat.format(expense.date)}',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: isDark
|
||||
? Colors.grey[500]
|
||||
: Colors.grey[500],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
// Montant
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
expense.description,
|
||||
style: const TextStyle(
|
||||
'$prefix${amountToDisplay.toStringAsFixed(2)} ${expense.currency.symbol}',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: amountColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'Payé par ${expense.paidByName}',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
if (expense.currency != ExpenseCurrency.eur)
|
||||
Text(
|
||||
'Total ${expense.amountInEur.toStringAsFixed(2)} €',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: isDark ? Colors.grey[500] : Colors.grey[400],
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
dateFormat.format(expense.date),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isDark ? Colors.grey[500] : Colors.grey[500],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'${expense.amount.toStringAsFixed(2)} ${expense.currency.symbol}',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.green,
|
||||
),
|
||||
),
|
||||
if (expense.currency != ExpenseCurrency.eur)
|
||||
Text(
|
||||
'${expense.amountInEur.toStringAsFixed(2)} €',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color _getCategoryColor(ExpenseCategory category) {
|
||||
switch (category) {
|
||||
case ExpenseCategory.restaurant:
|
||||
return Colors.orange;
|
||||
case ExpenseCategory.transport:
|
||||
return Colors.blue;
|
||||
case ExpenseCategory.accommodation:
|
||||
return Colors.purple;
|
||||
case ExpenseCategory.entertainment:
|
||||
return Colors.pink;
|
||||
case ExpenseCategory.shopping:
|
||||
return Colors.teal;
|
||||
case ExpenseCategory.other:
|
||||
return Colors.grey;
|
||||
}
|
||||
}
|
||||
|
||||
void _showExpenseDetail(BuildContext context, Expense expense) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => ExpenseDetailDialog(
|
||||
expense: expense,
|
||||
group: group,
|
||||
),
|
||||
builder: (context) => ExpenseDetailDialog(expense: expense, group: group),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ import '../../models/group.dart';
|
||||
import 'add_expense_dialog.dart';
|
||||
import 'balances_tab.dart';
|
||||
import 'expenses_tab.dart';
|
||||
import 'settlements_tab.dart';
|
||||
import '../../models/user_balance.dart';
|
||||
import '../../models/expense.dart';
|
||||
|
||||
class GroupExpensesPage extends StatefulWidget {
|
||||
final Account account;
|
||||
@@ -31,13 +32,14 @@ class GroupExpensesPage extends StatefulWidget {
|
||||
|
||||
class _GroupExpensesPageState extends State<GroupExpensesPage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
|
||||
late TabController _tabController;
|
||||
|
||||
ExpenseCategory? _selectedCategory;
|
||||
String? _selectedPayerId;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 3, vsync: this);
|
||||
_tabController = TabController(length: 2, vsync: this);
|
||||
_loadData();
|
||||
}
|
||||
|
||||
@@ -50,39 +52,41 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
||||
void _loadData() {
|
||||
// Charger les dépenses du groupe
|
||||
context.read<ExpenseBloc>().add(LoadExpensesByGroup(widget.group.id));
|
||||
|
||||
|
||||
// Charger les balances du groupe
|
||||
context.read<BalanceBloc>().add(LoadGroupBalances(widget.group.id));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final isDarkMode = theme.brightness == Brightness.dark;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: isDarkMode
|
||||
? theme.scaffoldBackgroundColor
|
||||
: Colors.grey[50],
|
||||
appBar: AppBar(
|
||||
title: Text(widget.account.name),
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
bottom: TabBar(
|
||||
controller: _tabController,
|
||||
indicatorColor: Colors.white,
|
||||
labelColor: Colors.white,
|
||||
unselectedLabelColor: Colors.white70,
|
||||
tabs: const [
|
||||
Tab(
|
||||
icon: Icon(Icons.balance),
|
||||
text: 'Balances',
|
||||
),
|
||||
Tab(
|
||||
icon: Icon(Icons.receipt_long),
|
||||
text: 'Dépenses',
|
||||
),
|
||||
Tab(
|
||||
icon: Icon(Icons.payment),
|
||||
text: 'Règlements',
|
||||
),
|
||||
],
|
||||
title: const Text(
|
||||
'Dépenses du voyage',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
centerTitle: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
foregroundColor: theme.colorScheme.onSurface,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.filter_list),
|
||||
onPressed: () {
|
||||
_showFilterDialog();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: MultiBlocListener(
|
||||
listeners: [
|
||||
@@ -103,56 +107,107 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
} else if (state is ExpensesLoaded) {
|
||||
// Rafraîchir les balances quand les dépenses changent (ex: via stream)
|
||||
context.read<BalanceBloc>().add(
|
||||
RefreshBalance(widget.group.id),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
child: Column(
|
||||
children: [
|
||||
// Onglet Balances
|
||||
// Summary Card
|
||||
BlocBuilder<BalanceBloc, BalanceState>(
|
||||
builder: (context, state) {
|
||||
if (state is BalanceLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is GroupBalancesLoaded) {
|
||||
return BalancesTab(balances: state.balances);
|
||||
} else if (state is BalanceError) {
|
||||
return _buildErrorState('Erreur lors du chargement des balances: ${state.message}');
|
||||
if (state is GroupBalancesLoaded) {
|
||||
return _buildSummaryCard(state.balances, isDarkMode);
|
||||
}
|
||||
return _buildEmptyState('Aucune balance disponible');
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
|
||||
// Onglet Dépenses
|
||||
BlocBuilder<ExpenseBloc, ExpenseState>(
|
||||
builder: (context, state) {
|
||||
if (state is ExpenseLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is ExpensesLoaded) {
|
||||
return ExpensesTab(
|
||||
expenses: state.expenses,
|
||||
group: widget.group,
|
||||
);
|
||||
} else if (state is ExpenseError) {
|
||||
return _buildErrorState('Erreur lors du chargement des dépenses: ${state.message}');
|
||||
}
|
||||
return _buildEmptyState('Aucune dépense trouvée');
|
||||
},
|
||||
|
||||
// Tabs
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(color: theme.dividerColor, width: 1),
|
||||
),
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
labelColor: theme.colorScheme.primary,
|
||||
unselectedLabelColor: theme.colorScheme.onSurface.withValues(
|
||||
alpha: 0.6,
|
||||
),
|
||||
indicatorColor: theme.colorScheme.primary,
|
||||
indicatorWeight: 3,
|
||||
labelStyle: const TextStyle(fontWeight: FontWeight.bold),
|
||||
tabs: const [
|
||||
Tab(text: 'Toutes les dépenses'),
|
||||
Tab(text: 'Mes soldes'),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Onglet Règlements
|
||||
BlocBuilder<BalanceBloc, BalanceState>(
|
||||
builder: (context, state) {
|
||||
if (state is BalanceLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is GroupBalancesLoaded) {
|
||||
return SettlementsTab(settlements: state.settlements);
|
||||
} else if (state is BalanceError) {
|
||||
return _buildErrorState('Erreur lors du chargement des règlements: ${state.message}');
|
||||
}
|
||||
return _buildEmptyState('Aucun règlement nécessaire');
|
||||
},
|
||||
|
||||
// Tab View
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
// Onglet Dépenses
|
||||
BlocBuilder<ExpenseBloc, ExpenseState>(
|
||||
builder: (context, state) {
|
||||
if (state is ExpenseLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is ExpensesLoaded) {
|
||||
final userState = context.read<UserBloc>().state;
|
||||
final currentUserId = userState is user_state.UserLoaded
|
||||
? userState.user.id
|
||||
: '';
|
||||
|
||||
var filteredExpenses = state.expenses;
|
||||
|
||||
if (_selectedCategory != null) {
|
||||
filteredExpenses = filteredExpenses
|
||||
.where((e) => e.category == _selectedCategory)
|
||||
.toList();
|
||||
}
|
||||
|
||||
if (_selectedPayerId != null) {
|
||||
filteredExpenses = filteredExpenses
|
||||
.where((e) => e.paidById == _selectedPayerId)
|
||||
.toList();
|
||||
}
|
||||
|
||||
return ExpensesTab(
|
||||
expenses: filteredExpenses,
|
||||
group: widget.group,
|
||||
currentUserId: currentUserId,
|
||||
);
|
||||
} else if (state is ExpenseError) {
|
||||
return _buildErrorState('Erreur: ${state.message}');
|
||||
}
|
||||
return _buildEmptyState('Aucune dépense trouvée');
|
||||
},
|
||||
),
|
||||
|
||||
// Onglet Balances (Combiné)
|
||||
BlocBuilder<BalanceBloc, BalanceState>(
|
||||
builder: (context, state) {
|
||||
if (state is BalanceLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is GroupBalancesLoaded) {
|
||||
return BalancesTab(balances: state.balances);
|
||||
} else if (state is BalanceError) {
|
||||
return _buildErrorState('Erreur: ${state.message}');
|
||||
}
|
||||
return _buildEmptyState('Aucune balance disponible');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -160,8 +215,109 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _showAddExpenseDialog,
|
||||
heroTag: "add_expense_fab",
|
||||
backgroundColor: Colors.blue,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 4,
|
||||
shape: const CircleBorder(),
|
||||
tooltip: 'Ajouter une dépense',
|
||||
child: const Icon(Icons.add),
|
||||
child: const Icon(Icons.add, size: 32),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSummaryCard(List<UserBalance> balances, bool isDarkMode) {
|
||||
// Trouver la balance de l'utilisateur courant
|
||||
final userState = context.read<UserBloc>().state;
|
||||
double myBalance = 0;
|
||||
|
||||
if (userState is user_state.UserLoaded) {
|
||||
final myBalanceObj = balances.firstWhere(
|
||||
(b) => b.userId == userState.user.id,
|
||||
orElse: () => const UserBalance(
|
||||
userId: '',
|
||||
userName: '',
|
||||
totalPaid: 0,
|
||||
totalOwed: 0,
|
||||
balance: 0,
|
||||
),
|
||||
);
|
||||
myBalance = myBalanceObj.balance;
|
||||
}
|
||||
|
||||
final isPositive = myBalance >= 0;
|
||||
final color = isPositive ? Colors.green : Colors.red;
|
||||
final amountStr = '${myBalance.abs().toStringAsFixed(2)} €';
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: isDarkMode ? Colors.grey[800] : Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Votre solde total',
|
||||
style: TextStyle(
|
||||
color: isDarkMode ? Colors.grey[400] : Colors.grey[600],
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
isPositive ? 'On vous doit ' : 'Vous devez ',
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
amountStr,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
isPositive
|
||||
? 'Vous êtes en positif sur ce voyage.'
|
||||
: 'Vous êtes en négatif sur ce voyage.',
|
||||
style: TextStyle(
|
||||
color: isDarkMode ? Colors.grey[400] : Colors.grey[600],
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
_tabController.animateTo(1); // Aller à l'onglet Balances
|
||||
},
|
||||
child: Text(
|
||||
'Voir le détail des soldes',
|
||||
style: TextStyle(
|
||||
color: Colors.blue[400],
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -171,11 +327,7 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 80,
|
||||
color: Colors.red[300],
|
||||
),
|
||||
Icon(Icons.error_outline, size: 80, color: Colors.red[300]),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Erreur',
|
||||
@@ -190,10 +342,7 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
||||
padding: const EdgeInsets.symmetric(horizontal: 32),
|
||||
child: Text(
|
||||
message,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
style: TextStyle(fontSize: 16, color: Colors.grey[600]),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
@@ -213,11 +362,7 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
size: 80,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
Icon(Icons.info_outline, size: 80, color: Colors.grey[400]),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Aucune donnée',
|
||||
@@ -230,10 +375,7 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
message,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey[500],
|
||||
),
|
||||
style: TextStyle(fontSize: 16, color: Colors.grey[500]),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
@@ -243,14 +385,12 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
||||
|
||||
void _showAddExpenseDialog() {
|
||||
final userState = context.read<UserBloc>().state;
|
||||
|
||||
|
||||
if (userState is user_state.UserLoaded) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AddExpenseDialog(
|
||||
group: widget.group,
|
||||
currentUser: userState.user,
|
||||
),
|
||||
builder: (context) =>
|
||||
AddExpenseDialog(group: widget.group, currentUser: userState.user),
|
||||
);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -261,4 +401,96 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _showFilterDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
return AlertDialog(
|
||||
title: const Text('Filtrer les dépenses'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
DropdownButtonFormField<ExpenseCategory>(
|
||||
// ignore: deprecated_member_use
|
||||
value: _selectedCategory,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Catégorie',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
items: [
|
||||
const DropdownMenuItem<ExpenseCategory>(
|
||||
value: null,
|
||||
child: Text('Toutes'),
|
||||
),
|
||||
...ExpenseCategory.values.map((category) {
|
||||
return DropdownMenuItem(
|
||||
value: category,
|
||||
child: Text(category.displayName),
|
||||
);
|
||||
}),
|
||||
],
|
||||
onChanged: (value) {
|
||||
setState(() => _selectedCategory = value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<String>(
|
||||
// ignore: deprecated_member_use
|
||||
value: _selectedPayerId,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Payé par',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
items: [
|
||||
const DropdownMenuItem<String>(
|
||||
value: null,
|
||||
child: Text('Tous'),
|
||||
),
|
||||
...widget.group.members.map((member) {
|
||||
return DropdownMenuItem(
|
||||
value: member.userId,
|
||||
child: Text(member.firstName),
|
||||
);
|
||||
}),
|
||||
],
|
||||
onChanged: (value) {
|
||||
setState(() => _selectedPayerId = value);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_selectedCategory = null;
|
||||
_selectedPayerId = null;
|
||||
});
|
||||
// Also update parent state
|
||||
this.setState(() {
|
||||
_selectedCategory = null;
|
||||
_selectedPayerId = null;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Réinitialiser'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
// Update parent state
|
||||
this.setState(() {});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Appliquer'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import '../../models/activity.dart';
|
||||
import '../../services/activity_cache_service.dart';
|
||||
|
||||
import '../loading/laoding_content.dart';
|
||||
import '../../blocs/user/user_bloc.dart';
|
||||
import '../../blocs/user/user_state.dart';
|
||||
|
||||
class ActivitiesPage extends StatefulWidget {
|
||||
final Trip trip;
|
||||
@@ -32,8 +34,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
List<Activity> _tripActivities = [];
|
||||
List<Activity> _approvedActivities = [];
|
||||
bool _isLoadingTripActivities = false;
|
||||
int _totalGoogleActivitiesRequested =
|
||||
0; // Compteur pour les recherches progressives
|
||||
|
||||
bool _autoReloadInProgress =
|
||||
false; // Protection contre les rechargements en boucle
|
||||
int _lastAutoReloadTriggerCount =
|
||||
@@ -999,9 +1000,11 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
}
|
||||
|
||||
void _voteForActivity(String activityId, int vote) {
|
||||
// TODO: Récupérer l'ID utilisateur actuel
|
||||
// Pour l'instant, on utilise l'ID du créateur du voyage pour que le vote compte
|
||||
final userId = widget.trip.createdBy;
|
||||
// Récupérer l'ID utilisateur actuel depuis le UserBloc
|
||||
final userState = context.read<UserBloc>().state;
|
||||
final userId = userState is UserLoaded
|
||||
? userState.user.id
|
||||
: widget.trip.createdBy;
|
||||
|
||||
// Vérifier si l'activité existe dans la liste locale pour vérifier le vote
|
||||
// (car l'objet activity passé peut venir d'une liste filtrée ou autre)
|
||||
@@ -1122,7 +1125,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
6; // Activités actuelles + ce qui manque + buffer de 6
|
||||
|
||||
// Mettre à jour le compteur et recharger avec le nouveau total
|
||||
_totalGoogleActivitiesRequested = newTotalToRequest;
|
||||
|
||||
_loadMoreGoogleActivitiesWithTotal(newTotalToRequest);
|
||||
|
||||
// Libérer le verrou après un délai
|
||||
@@ -1135,7 +1138,6 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
}
|
||||
|
||||
void _searchGoogleActivities() {
|
||||
_totalGoogleActivitiesRequested = 6; // Reset du compteur
|
||||
_autoReloadInProgress = false; // Reset des protections
|
||||
_lastAutoReloadTriggerCount = 0;
|
||||
|
||||
@@ -1166,7 +1168,6 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
}
|
||||
|
||||
void _resetAndSearchGoogleActivities() {
|
||||
_totalGoogleActivitiesRequested = 6; // Reset du compteur
|
||||
_autoReloadInProgress = false; // Reset des protections
|
||||
_lastAutoReloadTriggerCount = 0;
|
||||
|
||||
@@ -1203,8 +1204,6 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
final currentCount = currentState.searchResults.length;
|
||||
final newTotal = currentCount + 6;
|
||||
|
||||
_totalGoogleActivitiesRequested = newTotal;
|
||||
|
||||
// Utiliser les coordonnées pré-géolocalisées du voyage si disponibles
|
||||
if (widget.trip.hasCoordinates) {
|
||||
context.read<ActivityBloc>().add(
|
||||
|
||||
@@ -57,7 +57,7 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
height: 4,
|
||||
margin: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.3),
|
||||
color: theme.colorScheme.onSurface.withValues(alpha: 0.3),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -12,7 +12,7 @@ import '../../models/message.dart';
|
||||
import '../../repositories/group_repository.dart';
|
||||
|
||||
/// Chat group content widget for group messaging functionality.
|
||||
///
|
||||
///
|
||||
/// This widget provides a complete chat interface for group members to
|
||||
/// communicate within a travel group. Features include:
|
||||
/// - Real-time message loading and sending
|
||||
@@ -20,7 +20,7 @@ import '../../repositories/group_repository.dart';
|
||||
/// - Message reactions (like/unlike)
|
||||
/// - Scroll-to-bottom functionality
|
||||
/// - Message status indicators
|
||||
///
|
||||
///
|
||||
/// The widget integrates with MessageBloc for state management and
|
||||
/// handles various message operations through the bloc pattern.
|
||||
class ChatGroupContent extends StatefulWidget {
|
||||
@@ -28,13 +28,10 @@ class ChatGroupContent extends StatefulWidget {
|
||||
final Group group;
|
||||
|
||||
/// Creates a chat group content widget.
|
||||
///
|
||||
///
|
||||
/// Args:
|
||||
/// [group]: The group object containing group details and ID
|
||||
const ChatGroupContent({
|
||||
super.key,
|
||||
required this.group,
|
||||
});
|
||||
const ChatGroupContent({super.key, required this.group});
|
||||
|
||||
@override
|
||||
State<ChatGroupContent> createState() => _ChatGroupContentState();
|
||||
@@ -43,16 +40,16 @@ class ChatGroupContent extends StatefulWidget {
|
||||
class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
/// Controller for the message input field
|
||||
final _messageController = TextEditingController();
|
||||
|
||||
|
||||
/// Controller for managing scroll position in the message list
|
||||
final _scrollController = ScrollController();
|
||||
|
||||
|
||||
/// Currently selected message for editing (null if not editing)
|
||||
Message? _editingMessage;
|
||||
|
||||
/// Repository pour gérer les groupes
|
||||
final _groupRepository = GroupRepository();
|
||||
|
||||
|
||||
/// Subscription pour écouter les changements des membres du groupe
|
||||
late StreamSubscription<List<GroupMember>> _membersSubscription;
|
||||
|
||||
@@ -61,18 +58,20 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
super.initState();
|
||||
// Load messages when the widget initializes
|
||||
context.read<MessageBloc>().add(LoadMessages(widget.group.id));
|
||||
|
||||
|
||||
// Écouter les changements des membres du groupe
|
||||
_membersSubscription = _groupRepository.watchGroupMembers(widget.group.id).listen((updatedMembers) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
widget.group.members.clear();
|
||||
widget.group.members.addAll(updatedMembers);
|
||||
_membersSubscription = _groupRepository
|
||||
.watchGroupMembers(widget.group.id)
|
||||
.listen((updatedMembers) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
widget.group.members.clear();
|
||||
widget.group.members.addAll(updatedMembers);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_messageController.dispose();
|
||||
@@ -82,11 +81,11 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
}
|
||||
|
||||
/// Sends a new message or updates an existing message.
|
||||
///
|
||||
///
|
||||
/// Handles both sending new messages and editing existing ones based
|
||||
/// on the current editing state. Validates input and clears the input
|
||||
/// field after successful submission.
|
||||
///
|
||||
///
|
||||
/// Args:
|
||||
/// [currentUser]: The user sending or editing the message
|
||||
void _sendMessage(user_state.UserModel currentUser) {
|
||||
@@ -96,33 +95,33 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
if (_editingMessage != null) {
|
||||
// Edit mode - update existing message
|
||||
context.read<MessageBloc>().add(
|
||||
UpdateMessage(
|
||||
groupId: widget.group.id,
|
||||
messageId: _editingMessage!.id,
|
||||
newText: messageText,
|
||||
),
|
||||
);
|
||||
UpdateMessage(
|
||||
groupId: widget.group.id,
|
||||
messageId: _editingMessage!.id,
|
||||
newText: messageText,
|
||||
),
|
||||
);
|
||||
_cancelEdit();
|
||||
} else {
|
||||
// Send mode - create new message
|
||||
context.read<MessageBloc>().add(
|
||||
SendMessage(
|
||||
groupId: widget.group.id,
|
||||
text: messageText,
|
||||
senderId: currentUser.id,
|
||||
senderName: currentUser.prenom,
|
||||
),
|
||||
);
|
||||
SendMessage(
|
||||
groupId: widget.group.id,
|
||||
text: messageText,
|
||||
senderId: currentUser.id,
|
||||
senderName: currentUser.prenom,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_messageController.clear();
|
||||
}
|
||||
|
||||
/// Initiates editing mode for a selected message.
|
||||
///
|
||||
///
|
||||
/// Sets the message as the currently editing message and populates
|
||||
/// the input field with the message text for modification.
|
||||
///
|
||||
///
|
||||
/// Args:
|
||||
/// [message]: The message to edit
|
||||
void _editMessage(Message message) {
|
||||
@@ -133,7 +132,7 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
}
|
||||
|
||||
/// Cancels the current editing operation.
|
||||
///
|
||||
///
|
||||
/// Resets the editing state and clears the input field,
|
||||
/// returning to normal message sending mode.
|
||||
void _cancelEdit() {
|
||||
@@ -144,46 +143,43 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
}
|
||||
|
||||
/// Deletes a message from the group chat.
|
||||
///
|
||||
///
|
||||
/// Sends a delete event to the MessageBloc to remove the specified
|
||||
/// message from the group's message history.
|
||||
///
|
||||
///
|
||||
/// Args:
|
||||
/// [messageId]: The ID of the message to delete
|
||||
void _deleteMessage(String messageId) {
|
||||
context.read<MessageBloc>().add(
|
||||
DeleteMessage(
|
||||
groupId: widget.group.id,
|
||||
messageId: messageId,
|
||||
),
|
||||
);
|
||||
DeleteMessage(groupId: widget.group.id, messageId: messageId),
|
||||
);
|
||||
}
|
||||
|
||||
void _reactToMessage(String messageId, String userId, String reaction) {
|
||||
context.read<MessageBloc>().add(
|
||||
ReactToMessage(
|
||||
groupId: widget.group.id,
|
||||
messageId: messageId,
|
||||
userId: userId,
|
||||
reaction: reaction,
|
||||
),
|
||||
);
|
||||
ReactToMessage(
|
||||
groupId: widget.group.id,
|
||||
messageId: messageId,
|
||||
userId: userId,
|
||||
reaction: reaction,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _removeReaction(String messageId, String userId) {
|
||||
context.read<MessageBloc>().add(
|
||||
RemoveReaction(
|
||||
groupId: widget.group.id,
|
||||
messageId: messageId,
|
||||
userId: userId,
|
||||
),
|
||||
);
|
||||
RemoveReaction(
|
||||
groupId: widget.group.id,
|
||||
messageId: messageId,
|
||||
userId: userId,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
return BlocBuilder<UserBloc, user_state.UserState>(
|
||||
builder: (context, userState) {
|
||||
if (userState is! user_state.UserLoaded) {
|
||||
@@ -203,7 +199,10 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
Text(widget.group.name, style: const TextStyle(fontSize: 18)),
|
||||
Text(
|
||||
'${widget.group.members.length} membre${widget.group.members.length > 1 ? 's' : ''}',
|
||||
style: const TextStyle(fontSize: 12, fontWeight: FontWeight.normal),
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.normal,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -255,7 +254,8 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
itemBuilder: (context, index) {
|
||||
final message = state.messages[index];
|
||||
final isMe = message.senderId == currentUser.id;
|
||||
final showDate = index == 0 ||
|
||||
final showDate =
|
||||
index == 0 ||
|
||||
!_isSameDay(
|
||||
state.messages[index - 1].timestamp,
|
||||
message.timestamp,
|
||||
@@ -263,8 +263,14 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
if (showDate) _buildDateSeparator(message.timestamp),
|
||||
_buildMessageBubble(message, isMe, isDark, currentUser.id),
|
||||
if (showDate)
|
||||
_buildDateSeparator(message.timestamp),
|
||||
_buildMessageBubble(
|
||||
message,
|
||||
isMe,
|
||||
isDark,
|
||||
currentUser.id,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
@@ -280,14 +286,15 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
if (_editingMessage != null)
|
||||
Container(
|
||||
color: isDark ? Colors.blue[900] : Colors.blue[100],
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.edit, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
const Expanded(
|
||||
child: Text('Modification du message'),
|
||||
),
|
||||
const Expanded(child: Text('Modification du message')),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: _cancelEdit,
|
||||
@@ -315,11 +322,13 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
child: TextField(
|
||||
controller: _messageController,
|
||||
decoration: InputDecoration(
|
||||
hintText: _editingMessage != null
|
||||
? 'Modifier le message...'
|
||||
hintText: _editingMessage != null
|
||||
? 'Modifier le message...'
|
||||
: 'Écrire un message...',
|
||||
filled: true,
|
||||
fillColor: isDark ? Colors.grey[850] : Colors.grey[100],
|
||||
fillColor: isDark
|
||||
? Colors.grey[850]
|
||||
: Colors.grey[100],
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
borderSide: BorderSide.none,
|
||||
@@ -336,9 +345,13 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
onPressed: () => _sendMessage(currentUser),
|
||||
icon: Icon(_editingMessage != null ? Icons.check : Icons.send),
|
||||
icon: Icon(
|
||||
_editingMessage != null ? Icons.check : Icons.send,
|
||||
),
|
||||
style: IconButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
backgroundColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.primary,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.all(12),
|
||||
),
|
||||
@@ -361,27 +374,17 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.chat_bubble_outline,
|
||||
size: 80,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
Icon(Icons.chat_bubble_outline, size: 80, color: Colors.grey[400]),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'Aucun message',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Commencez la conversation !',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -389,10 +392,15 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMessageBubble(Message message, bool isMe, bool isDark, String currentUserId) {
|
||||
Widget _buildMessageBubble(
|
||||
Message message,
|
||||
bool isMe,
|
||||
bool isDark,
|
||||
String currentUserId,
|
||||
) {
|
||||
final Color bubbleColor;
|
||||
final Color textColor;
|
||||
|
||||
|
||||
if (isMe) {
|
||||
bubbleColor = isDark ? const Color(0xFF1E3A5F) : const Color(0xFF90CAF9);
|
||||
textColor = isDark ? Colors.white : Colors.black87;
|
||||
@@ -402,42 +410,48 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
}
|
||||
|
||||
// Trouver le membre qui a envoyé le message pour récupérer son pseudo actuel
|
||||
final senderMember = widget.group.members.firstWhere(
|
||||
(m) => m.userId == message.senderId,
|
||||
orElse: () => null as dynamic,
|
||||
) as dynamic;
|
||||
final senderMember =
|
||||
widget.group.members.firstWhere(
|
||||
(m) => m.userId == message.senderId,
|
||||
orElse: () => null as dynamic,
|
||||
)
|
||||
as dynamic;
|
||||
|
||||
// Utiliser le pseudo actuel du membre, ou le senderName en fallback
|
||||
final displayName = senderMember != null ? senderMember.pseudo : message.senderName;
|
||||
final displayName = senderMember != null
|
||||
? senderMember.pseudo
|
||||
: message.senderName;
|
||||
|
||||
return Align(
|
||||
alignment: isMe ? Alignment.centerRight : Alignment.centerLeft,
|
||||
child: GestureDetector(
|
||||
onLongPress: () => _showMessageOptions(context, message, isMe, currentUserId),
|
||||
onLongPress: () =>
|
||||
_showMessageOptions(context, message, isMe, currentUserId),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
child: Row(
|
||||
mainAxisAlignment: isMe ? MainAxisAlignment.end : MainAxisAlignment.start,
|
||||
mainAxisAlignment: isMe
|
||||
? MainAxisAlignment.end
|
||||
: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
// Avatar du sender (seulement pour les autres messages)
|
||||
if (!isMe) ...[
|
||||
CircleAvatar(
|
||||
radius: 16,
|
||||
backgroundImage: (senderMember != null &&
|
||||
senderMember.profilePictureUrl != null &&
|
||||
senderMember.profilePictureUrl!.isNotEmpty)
|
||||
backgroundImage:
|
||||
(senderMember != null &&
|
||||
senderMember.profilePictureUrl != null &&
|
||||
senderMember.profilePictureUrl!.isNotEmpty)
|
||||
? NetworkImage(senderMember.profilePictureUrl!)
|
||||
: null,
|
||||
child: (senderMember == null ||
|
||||
senderMember.profilePictureUrl == null ||
|
||||
senderMember.profilePictureUrl!.isEmpty)
|
||||
child:
|
||||
(senderMember == null ||
|
||||
senderMember.profilePictureUrl == null ||
|
||||
senderMember.profilePictureUrl!.isEmpty)
|
||||
? Text(
|
||||
displayName.isNotEmpty
|
||||
? displayName[0].toUpperCase()
|
||||
displayName.isNotEmpty
|
||||
? displayName[0].toUpperCase()
|
||||
: '?',
|
||||
style: const TextStyle(fontSize: 12),
|
||||
)
|
||||
@@ -445,10 +459,13 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
|
||||
|
||||
Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 10,
|
||||
),
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: MediaQuery.of(context).size.width * 0.65,
|
||||
),
|
||||
@@ -462,7 +479,9 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: isMe ? CrossAxisAlignment.end : CrossAxisAlignment.start,
|
||||
crossAxisAlignment: isMe
|
||||
? CrossAxisAlignment.end
|
||||
: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (!isMe) ...[
|
||||
Text(
|
||||
@@ -476,11 +495,17 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
const SizedBox(height: 4),
|
||||
],
|
||||
Text(
|
||||
message.isDeleted ? 'a supprimé un message' : message.text,
|
||||
message.isDeleted
|
||||
? 'a supprimé un message'
|
||||
: message.text,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
color: message.isDeleted ? textColor.withValues(alpha: 0.5) : textColor,
|
||||
fontStyle: message.isDeleted ? FontStyle.italic : FontStyle.normal,
|
||||
color: message.isDeleted
|
||||
? textColor.withValues(alpha: 0.5)
|
||||
: textColor,
|
||||
fontStyle: message.isDeleted
|
||||
? FontStyle.italic
|
||||
: FontStyle.normal,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
@@ -528,7 +553,7 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
|
||||
List<Widget> _buildReactionChips(Message message, String currentUserId) {
|
||||
final reactionCounts = <String, List<String>>{};
|
||||
|
||||
|
||||
// Grouper les réactions par emoji
|
||||
message.reactions.forEach((userId, emoji) {
|
||||
reactionCounts.putIfAbsent(emoji, () => []).add(userId);
|
||||
@@ -550,7 +575,7 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: hasReacted
|
||||
color: hasReacted
|
||||
? Colors.blue.withValues(alpha: 0.3)
|
||||
: Colors.grey.withValues(alpha: 0.3),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
@@ -565,7 +590,10 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
'${userIds.length}',
|
||||
style: const TextStyle(fontSize: 10, fontWeight: FontWeight.bold),
|
||||
style: const TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -574,7 +602,12 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
void _showMessageOptions(BuildContext context, Message message, bool isMe, String currentUserId) {
|
||||
void _showMessageOptions(
|
||||
BuildContext context,
|
||||
Message message,
|
||||
bool isMe,
|
||||
String currentUserId,
|
||||
) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => SafeArea(
|
||||
@@ -609,7 +642,10 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.delete, color: Colors.red),
|
||||
title: const Text('Supprimer', style: TextStyle(color: Colors.red)),
|
||||
title: const Text(
|
||||
'Supprimer',
|
||||
style: TextStyle(color: Colors.red),
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_showDeleteConfirmation(context, message.id);
|
||||
@@ -712,20 +748,23 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
final member = widget.group.members[index];
|
||||
final initials = member.pseudo.isNotEmpty
|
||||
? member.pseudo[0].toUpperCase()
|
||||
: (member.firstName.isNotEmpty
|
||||
? member.firstName[0].toUpperCase()
|
||||
: '?');
|
||||
|
||||
: (member.firstName.isNotEmpty
|
||||
? member.firstName[0].toUpperCase()
|
||||
: '?');
|
||||
|
||||
// Construire le nom complet
|
||||
final fullName = '${member.firstName} ${member.lastName}'.trim();
|
||||
|
||||
|
||||
return ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundImage: (member.profilePictureUrl != null &&
|
||||
member.profilePictureUrl!.isNotEmpty)
|
||||
backgroundImage:
|
||||
(member.profilePictureUrl != null &&
|
||||
member.profilePictureUrl!.isNotEmpty)
|
||||
? NetworkImage(member.profilePictureUrl!)
|
||||
: null,
|
||||
child: (member.profilePictureUrl == null || member.profilePictureUrl!.isEmpty)
|
||||
child:
|
||||
(member.profilePictureUrl == null ||
|
||||
member.profilePictureUrl!.isEmpty)
|
||||
? Text(initials)
|
||||
: null,
|
||||
),
|
||||
@@ -743,8 +782,11 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
),
|
||||
],
|
||||
),
|
||||
subtitle: member.role == 'admin'
|
||||
? const Text('Administrateur', style: TextStyle(fontSize: 12))
|
||||
subtitle: member.role == 'admin'
|
||||
? const Text(
|
||||
'Administrateur',
|
||||
style: TextStyle(fontSize: 12),
|
||||
)
|
||||
: null,
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.edit, size: 18),
|
||||
@@ -774,7 +816,8 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: theme.dialogBackgroundColor,
|
||||
backgroundColor:
|
||||
theme.dialogTheme.backgroundColor ?? theme.colorScheme.surface,
|
||||
title: Text(
|
||||
'Changer le pseudo',
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
@@ -785,9 +828,7 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
controller: pseudoController,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Nouveau pseudo',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
@@ -825,11 +866,11 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
try {
|
||||
final updatedMember = member.copyWith(pseudo: newPseudo);
|
||||
await _groupRepository.addMember(widget.group.id, updatedMember);
|
||||
|
||||
|
||||
if (mounted) {
|
||||
// Le stream listener va automatiquement mettre à jour les membres
|
||||
// Pas besoin de fermer le dialog ou de faire un refresh manuel
|
||||
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Pseudo modifié en "$newPseudo"'),
|
||||
@@ -848,4 +889,4 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,12 +144,9 @@ class _GroupContentState extends State<GroupContent> {
|
||||
final color = colors[group.name.hashCode.abs() % colors.length];
|
||||
|
||||
// Membres de manière simple
|
||||
String memberInfo = '${group.members.length} membre(s)';
|
||||
String memberInfo = '${group.memberIds.length} membre(s)';
|
||||
if (group.members.isNotEmpty) {
|
||||
final names = group.members
|
||||
.take(2)
|
||||
.map((m) => m.firstName)
|
||||
.join(', ');
|
||||
final names = group.members.take(2).map((m) => m.firstName).join(', ');
|
||||
memberInfo += '\n$names';
|
||||
}
|
||||
|
||||
|
||||
@@ -290,10 +290,13 @@ class _CalendarPageState extends State<CalendarPage> {
|
||||
),
|
||||
// Zone de drop pour le calendrier
|
||||
DragTarget<Activity>(
|
||||
onWillAccept: (data) => true,
|
||||
onAccept: (activity) {
|
||||
onWillAcceptWithDetails: (details) => true,
|
||||
onAcceptWithDetails: (details) {
|
||||
if (_selectedDay != null) {
|
||||
_selectTimeAndSchedule(activity, _selectedDay!);
|
||||
_selectTimeAndSchedule(
|
||||
details.data,
|
||||
_selectedDay!,
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, candidateData, rejectedData) {
|
||||
|
||||
@@ -22,9 +22,10 @@ import 'package:http/http.dart' as http;
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import '../../services/place_image_service.dart';
|
||||
import '../../services/trip_geocoding_service.dart';
|
||||
import '../../services/logger_service.dart';
|
||||
|
||||
/// Create trip content widget for trip creation and editing functionality.
|
||||
///
|
||||
///
|
||||
/// This widget provides a comprehensive form interface for creating new trips
|
||||
/// or editing existing ones. Key features include:
|
||||
/// - Trip creation with validation
|
||||
@@ -34,22 +35,19 @@ import '../../services/trip_geocoding_service.dart';
|
||||
/// - Group creation and member management
|
||||
/// - Account setup for expense tracking
|
||||
/// - Integration with mapping services for location selection
|
||||
///
|
||||
///
|
||||
/// The widget handles both creation and editing modes based on the
|
||||
/// provided tripToEdit parameter.
|
||||
class CreateTripContent extends StatefulWidget {
|
||||
/// Optional trip to edit. If null, creates a new trip
|
||||
final Trip? tripToEdit;
|
||||
|
||||
|
||||
/// Creates a create trip content widget.
|
||||
///
|
||||
///
|
||||
/// Args:
|
||||
/// [tripToEdit]: Optional trip to edit. If provided, the form will
|
||||
/// be populated with existing trip data for editing
|
||||
const CreateTripContent({
|
||||
super.key,
|
||||
this.tripToEdit,
|
||||
});
|
||||
const CreateTripContent({super.key, this.tripToEdit});
|
||||
|
||||
@override
|
||||
State<CreateTripContent> createState() => _CreateTripContentState();
|
||||
@@ -58,17 +56,17 @@ class CreateTripContent extends StatefulWidget {
|
||||
class _CreateTripContentState extends State<CreateTripContent> {
|
||||
/// Service for handling and displaying errors
|
||||
final _errorService = ErrorService();
|
||||
|
||||
|
||||
/// Form validation key
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
|
||||
/// Text controllers for form fields
|
||||
final _titleController = TextEditingController();
|
||||
final _descriptionController = TextEditingController();
|
||||
final _locationController = TextEditingController();
|
||||
final _budgetController = TextEditingController();
|
||||
final _participantController = TextEditingController();
|
||||
|
||||
|
||||
/// Services for user and group operations
|
||||
final _userService = UserService();
|
||||
final _groupRepository = GroupRepository();
|
||||
@@ -79,7 +77,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
/// Trip date variables
|
||||
DateTime? _startDate;
|
||||
DateTime? _endDate;
|
||||
|
||||
|
||||
/// Loading and state management variables
|
||||
bool _isLoading = false;
|
||||
String? _createdTripId;
|
||||
@@ -127,7 +125,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
|
||||
void _onLocationChanged() {
|
||||
final query = _locationController.text.trim();
|
||||
|
||||
|
||||
if (query.length < 2) {
|
||||
_hideSuggestions();
|
||||
return;
|
||||
@@ -151,14 +149,14 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
'?input=${Uri.encodeComponent(query)}'
|
||||
'&types=(cities)'
|
||||
'&language=fr'
|
||||
'&key=$_apiKey'
|
||||
'&key=$_apiKey',
|
||||
);
|
||||
|
||||
final response = await http.get(url);
|
||||
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = json.decode(response.body);
|
||||
|
||||
|
||||
if (data['status'] == 'OK') {
|
||||
final predictions = data['predictions'] as List;
|
||||
setState(() {
|
||||
@@ -170,7 +168,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
}).toList();
|
||||
_isLoadingSuggestions = false;
|
||||
});
|
||||
|
||||
|
||||
if (_placeSuggestions.isNotEmpty) {
|
||||
_showSuggestions();
|
||||
} else {
|
||||
@@ -202,12 +200,14 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
// Nouvelle méthode pour afficher les suggestions
|
||||
void _showSuggestions() {
|
||||
_hideSuggestions(); // Masquer d'abord les suggestions existantes
|
||||
|
||||
|
||||
if (_placeSuggestions.isEmpty) return;
|
||||
|
||||
_suggestionsOverlay = OverlayEntry(
|
||||
builder: (context) => Positioned(
|
||||
width: MediaQuery.of(context).size.width - 32, // Largeur du champ avec padding
|
||||
width:
|
||||
MediaQuery.of(context).size.width -
|
||||
32, // Largeur du champ avec padding
|
||||
child: CompositedTransformFollower(
|
||||
link: _layerLink,
|
||||
showWhenUnlinked: false,
|
||||
@@ -258,26 +258,32 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
setState(() {
|
||||
_placeSuggestions = [];
|
||||
});
|
||||
|
||||
|
||||
// Charger l'image du lieu sélectionné
|
||||
_loadPlaceImage(suggestion.description);
|
||||
}
|
||||
|
||||
/// Charge l'image du lieu depuis Google Places API
|
||||
Future<void> _loadPlaceImage(String location) async {
|
||||
print('CreateTripContent: Chargement de l\'image pour: $location');
|
||||
LoggerService.info(
|
||||
'CreateTripContent: Chargement de l\'image pour: $location',
|
||||
);
|
||||
|
||||
try {
|
||||
final imageUrl = await _placeImageService.getPlaceImageUrl(location);
|
||||
print('CreateTripContent: Image URL reçue: $imageUrl');
|
||||
LoggerService.info('CreateTripContent: Image URL reçue: $imageUrl');
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_selectedImageUrl = imageUrl;
|
||||
});
|
||||
print('CreateTripContent: État mis à jour avec imageUrl: $_selectedImageUrl');
|
||||
LoggerService.info(
|
||||
'CreateTripContent: État mis à jour avec imageUrl: $_selectedImageUrl',
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
print('CreateTripContent: Erreur lors du chargement de l\'image: $e');
|
||||
LoggerService.error(
|
||||
'CreateTripContent: Erreur lors du chargement de l\'image: $e',
|
||||
);
|
||||
if (mounted) {
|
||||
_errorService.logError(
|
||||
'create_trip_content.dart',
|
||||
@@ -337,7 +343,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
}) {
|
||||
final theme = Theme.of(context);
|
||||
final isDarkMode = theme.brightness == Brightness.dark;
|
||||
|
||||
|
||||
return TextFormField(
|
||||
controller: controller,
|
||||
validator: validator,
|
||||
@@ -349,42 +355,36 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
decoration: InputDecoration(
|
||||
hintText: label,
|
||||
hintStyle: theme.textTheme.bodyLarge?.copyWith(
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.5),
|
||||
color: theme.colorScheme.onSurface.withValues(alpha: 0.5),
|
||||
),
|
||||
prefixIcon: Icon(
|
||||
icon,
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.5),
|
||||
color: theme.colorScheme.onSurface.withValues(alpha: 0.5),
|
||||
),
|
||||
suffixIcon: suffixIcon,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: isDarkMode
|
||||
? Colors.white.withOpacity(0.2)
|
||||
: Colors.black.withOpacity(0.2),
|
||||
color: isDarkMode
|
||||
? Colors.white.withValues(alpha: 0.2)
|
||||
: Colors.black.withValues(alpha: 0.2),
|
||||
),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: isDarkMode
|
||||
? Colors.white.withOpacity(0.2)
|
||||
: Colors.black.withOpacity(0.2),
|
||||
color: isDarkMode
|
||||
? Colors.white.withValues(alpha: 0.2)
|
||||
: Colors.black.withValues(alpha: 0.2),
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.teal,
|
||||
width: 2,
|
||||
),
|
||||
borderSide: BorderSide(color: Colors.teal, width: 2),
|
||||
),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(
|
||||
color: Colors.red,
|
||||
width: 2,
|
||||
),
|
||||
borderSide: const BorderSide(color: Colors.red, width: 2),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: theme.cardColor,
|
||||
@@ -403,7 +403,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
}) {
|
||||
final theme = Theme.of(context);
|
||||
final isDarkMode = theme.brightness == Brightness.dark;
|
||||
|
||||
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
@@ -413,27 +413,27 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
color: theme.cardColor,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: isDarkMode
|
||||
? Colors.white.withOpacity(0.2)
|
||||
: Colors.black.withOpacity(0.2),
|
||||
color: isDarkMode
|
||||
? Colors.white.withValues(alpha: 0.2)
|
||||
: Colors.black.withValues(alpha: 0.2),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.calendar_today,
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.5),
|
||||
color: theme.colorScheme.onSurface.withValues(alpha: 0.5),
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
date != null
|
||||
? '${date.day.toString().padLeft(2, '0')}/${date.month.toString().padLeft(2, '0')}/${date.year}'
|
||||
: 'mm/dd/yyyy',
|
||||
date != null
|
||||
? '${date.day.toString().padLeft(2, '0')}/${date.month.toString().padLeft(2, '0')}/${date.year}'
|
||||
: 'mm/dd/yyyy',
|
||||
style: theme.textTheme.bodyLarge?.copyWith(
|
||||
color: date != null
|
||||
? theme.colorScheme.onSurface
|
||||
: theme.colorScheme.onSurface.withOpacity(0.5),
|
||||
color: date != null
|
||||
? theme.colorScheme.onSurface
|
||||
: theme.colorScheme.onSurface.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -442,11 +442,11 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final isDarkMode = theme.brightness == Brightness.dark;
|
||||
|
||||
|
||||
return BlocListener<TripBloc, TripState>(
|
||||
listener: (context, tripState) {
|
||||
if (tripState is TripCreated) {
|
||||
@@ -454,7 +454,10 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
_createGroupAndAccountForTrip(_createdTripId!);
|
||||
} else if (tripState is TripOperationSuccess) {
|
||||
if (mounted) {
|
||||
_errorService.showSnackbar(message: tripState.message, isError: false);
|
||||
_errorService.showSnackbar(
|
||||
message: tripState.message,
|
||||
isError: false,
|
||||
);
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
@@ -465,7 +468,10 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
}
|
||||
} else if (tripState is TripError) {
|
||||
if (mounted) {
|
||||
_errorService.showSnackbar(message: tripState.message, isError: true);
|
||||
_errorService.showSnackbar(
|
||||
message: tripState.message,
|
||||
isError: true,
|
||||
);
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
@@ -478,7 +484,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
return Scaffold(
|
||||
backgroundColor: theme.scaffoldBackgroundColor,
|
||||
appBar: AppBar(
|
||||
title: Text(isEditing ? 'Modifier le voyage' : 'Créer un voyage'),
|
||||
title: Text(
|
||||
isEditing ? 'Modifier le voyage' : 'Créer un voyage',
|
||||
),
|
||||
backgroundColor: theme.appBarTheme.backgroundColor,
|
||||
foregroundColor: theme.appBarTheme.foregroundColor,
|
||||
),
|
||||
@@ -506,7 +514,10 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: Icon(Icons.arrow_back, color: theme.colorScheme.onSurface),
|
||||
icon: Icon(
|
||||
Icons.arrow_back,
|
||||
color: theme.colorScheme.onSurface,
|
||||
),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
),
|
||||
@@ -519,7 +530,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(isDarkMode ? 0.3 : 0.1),
|
||||
color: Colors.black.withValues(
|
||||
alpha: isDarkMode ? 0.3 : 0.1,
|
||||
),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 5),
|
||||
),
|
||||
@@ -544,7 +557,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
Text(
|
||||
'Donne un nom à ton voyage',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.7),
|
||||
color: theme.colorScheme.onSurface.withValues(
|
||||
alpha: 0.7,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
@@ -588,7 +603,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
@@ -667,7 +684,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
controller: _budgetController,
|
||||
label: 'Ex : 500',
|
||||
icon: Icons.euro,
|
||||
keyboardType: TextInputType.numberWithOptions(decimal: true),
|
||||
keyboardType: TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
@@ -701,7 +720,10 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
),
|
||||
child: IconButton(
|
||||
onPressed: _addParticipant,
|
||||
icon: const Icon(Icons.add, color: Colors.white),
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -720,7 +742,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
vertical: 8,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.teal.withOpacity(0.1),
|
||||
color: Colors.teal.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Row(
|
||||
@@ -728,10 +750,11 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
children: [
|
||||
Text(
|
||||
email,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: Colors.teal,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
style: theme.textTheme.bodySmall
|
||||
?.copyWith(
|
||||
color: Colors.teal,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
GestureDetector(
|
||||
@@ -758,7 +781,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
width: double.infinity,
|
||||
height: 56,
|
||||
child: ElevatedButton(
|
||||
onPressed: _isLoading ? null : () => _saveTrip(userState.user),
|
||||
onPressed: _isLoading
|
||||
? null
|
||||
: () => _saveTrip(userState.user),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.teal,
|
||||
foregroundColor: Colors.white,
|
||||
@@ -773,15 +798,20 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
Colors.white,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
isEditing ? 'Modifier le voyage' : 'Créer le voyage',
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
isEditing
|
||||
? 'Modifier le voyage'
|
||||
: 'Créer le voyage',
|
||||
style: theme.textTheme.titleMedium
|
||||
?.copyWith(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -846,15 +876,18 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
final emailRegex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
|
||||
if (!emailRegex.hasMatch(email)) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Email invalide')));
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('Email invalide')));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (_participants.contains(email)) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(content: Text('Ce participant est déjà ajouté')));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Ce participant est déjà ajouté')),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -879,7 +912,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
) async {
|
||||
final groupBloc = context.read<GroupBloc>();
|
||||
final accountBloc = context.read<AccountBloc>();
|
||||
|
||||
|
||||
try {
|
||||
final group = await _groupRepository.getGroupByTripId(tripId);
|
||||
|
||||
@@ -900,7 +933,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
final currentMemberIds = currentMembers.map((m) => m.userId).toSet();
|
||||
final newMemberIds = newMembers.map((m) => m.userId).toSet();
|
||||
|
||||
final membersToAdd = newMembers.where((m) => !currentMemberIds.contains(m.userId)).toList();
|
||||
final membersToAdd = newMembers
|
||||
.where((m) => !currentMemberIds.contains(m.userId))
|
||||
.toList();
|
||||
|
||||
final membersToRemove = currentMembers
|
||||
.where((m) => !newMemberIds.contains(m.userId) && m.role != 'admin')
|
||||
@@ -961,14 +996,16 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
role: 'admin',
|
||||
profilePictureUrl: currentUser.profilePictureUrl,
|
||||
),
|
||||
...participantsData.map((p) => GroupMember(
|
||||
userId: p['id'] as String,
|
||||
firstName: p['firstName'] as String,
|
||||
lastName: p['lastName'] as String? ?? '',
|
||||
pseudo: p['firstName'] as String,
|
||||
role: 'member',
|
||||
profilePictureUrl: p['profilePictureUrl'] as String?,
|
||||
)),
|
||||
...participantsData.map(
|
||||
(p) => GroupMember(
|
||||
userId: p['id'] as String,
|
||||
firstName: p['firstName'] as String,
|
||||
lastName: p['lastName'] as String? ?? '',
|
||||
pseudo: p['firstName'] as String,
|
||||
role: 'member',
|
||||
profilePictureUrl: p['profilePictureUrl'] as String?,
|
||||
),
|
||||
),
|
||||
];
|
||||
return groupMembers;
|
||||
}
|
||||
@@ -976,9 +1013,8 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
Future<void> _createGroupAndAccountForTrip(String tripId) async {
|
||||
final groupBloc = context.read<GroupBloc>();
|
||||
final accountBloc = context.read<AccountBloc>();
|
||||
|
||||
|
||||
try {
|
||||
|
||||
final userState = context.read<UserBloc>().state;
|
||||
if (userState is! user_state.UserLoaded) {
|
||||
throw Exception('Utilisateur non connecté');
|
||||
@@ -998,21 +1034,19 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
throw Exception('Erreur lors de la création des membres du groupe');
|
||||
}
|
||||
|
||||
groupBloc.add(CreateGroupWithMembers(
|
||||
group: group,
|
||||
members: groupMembers,
|
||||
));
|
||||
groupBloc.add(
|
||||
CreateGroupWithMembers(group: group, members: groupMembers),
|
||||
);
|
||||
final account = Account(
|
||||
id: '',
|
||||
tripId: tripId,
|
||||
name: _titleController.text.trim(),
|
||||
);
|
||||
|
||||
accountBloc.add(CreateAccountWithMembers(
|
||||
account: account,
|
||||
members: groupMembers,
|
||||
));
|
||||
|
||||
accountBloc.add(
|
||||
CreateAccountWithMembers(account: account, members: groupMembers),
|
||||
);
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
@@ -1025,7 +1059,6 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
});
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
_errorService.logError(
|
||||
'create_trip_content.dart',
|
||||
@@ -1034,10 +1067,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Erreur: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
SnackBar(content: Text('Erreur: $e'), backgroundColor: Colors.red),
|
||||
);
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
@@ -1046,8 +1076,6 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Future<void> _saveTrip(user_state.UserModel currentUser) async {
|
||||
if (!_formKey.currentState!.validate()) {
|
||||
return;
|
||||
@@ -1070,7 +1098,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
|
||||
try {
|
||||
final participantsData = await _getParticipantsData(_participants);
|
||||
List<String> participantIds = participantsData.map((p) => p['id'] as String).toList();
|
||||
List<String> participantIds = participantsData
|
||||
.map((p) => p['id'] as String)
|
||||
.toList();
|
||||
|
||||
if (!participantIds.contains(currentUser.id)) {
|
||||
participantIds.insert(0, currentUser.id);
|
||||
@@ -1101,7 +1131,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Voyage créé sans géolocalisation (pas d\'impact sur les fonctionnalités)'),
|
||||
content: Text(
|
||||
'Voyage créé sans géolocalisation (pas d\'impact sur les fonctionnalités)',
|
||||
),
|
||||
backgroundColor: Colors.orange,
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
@@ -1114,16 +1146,21 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
tripBloc.add(TripUpdateRequested(trip: tripWithCoordinates));
|
||||
|
||||
// Mettre à jour le groupe ET les comptes avec les nouveaux participants
|
||||
if (widget.tripToEdit != null && widget.tripToEdit!.id != null && widget.tripToEdit!.id!.isNotEmpty) {
|
||||
print('🔄 [CreateTrip] Mise à jour du groupe et du compte pour le voyage ID: ${widget.tripToEdit!.id}');
|
||||
print('👥 Participants: ${participantsData.map((p) => p['id']).toList()}');
|
||||
if (widget.tripToEdit != null &&
|
||||
widget.tripToEdit!.id != null &&
|
||||
widget.tripToEdit!.id!.isNotEmpty) {
|
||||
LoggerService.info(
|
||||
'🔄 [CreateTrip] Mise à jour du groupe et du compte pour le voyage ID: ${widget.tripToEdit!.id}',
|
||||
);
|
||||
LoggerService.info(
|
||||
'👥 Participants: ${participantsData.map((p) => p['id']).toList()}',
|
||||
);
|
||||
await _updateGroupAndAccountMembers(
|
||||
widget.tripToEdit!.id!,
|
||||
currentUser,
|
||||
participantsData,
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
// Mode création - Le groupe sera créé dans le listener TripCreated
|
||||
tripBloc.add(TripCreateRequested(trip: tripWithCoordinates));
|
||||
@@ -1131,10 +1168,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Erreur: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
SnackBar(content: Text('Erreur: $e'), backgroundColor: Colors.red),
|
||||
);
|
||||
|
||||
setState(() {
|
||||
@@ -1144,7 +1178,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> _getParticipantsData(List<String> emails) async {
|
||||
Future<List<Map<String, dynamic>>> _getParticipantsData(
|
||||
List<String> emails,
|
||||
) async {
|
||||
List<Map<String, dynamic>> participantsData = [];
|
||||
|
||||
for (String email in emails) {
|
||||
@@ -1188,8 +1224,5 @@ class PlaceSuggestion {
|
||||
final String placeId;
|
||||
final String description;
|
||||
|
||||
PlaceSuggestion({
|
||||
required this.placeId,
|
||||
required this.description,
|
||||
});
|
||||
}
|
||||
PlaceSuggestion({required this.placeId, required this.description});
|
||||
}
|
||||
|
||||
@@ -100,7 +100,8 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
backgroundColor: theme.dialogBackgroundColor,
|
||||
backgroundColor:
|
||||
theme.dialogTheme.backgroundColor ?? theme.colorScheme.surface,
|
||||
title: Text(
|
||||
'Ouvrir la carte',
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
@@ -612,7 +613,8 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: theme.dialogBackgroundColor,
|
||||
backgroundColor:
|
||||
theme.dialogTheme.backgroundColor ?? theme.colorScheme.surface,
|
||||
title: Text(
|
||||
'Confirmer la suppression',
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
@@ -814,7 +816,8 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
backgroundColor: theme.dialogBackgroundColor,
|
||||
backgroundColor:
|
||||
theme.dialogTheme.backgroundColor ?? theme.colorScheme.surface,
|
||||
title: Text(
|
||||
'Ajouter un participant',
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
|
||||
@@ -57,7 +57,7 @@ class _LoadingContentState extends State<LoadingContent>
|
||||
widget.onComplete!();
|
||||
}
|
||||
} catch (e) {
|
||||
print('Erreur lors de la tâche en arrière-plan: $e');
|
||||
debugPrint('Erreur lors de la tâche en arrière-plan: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,19 +21,20 @@ class _MapContentState extends State<MapContent> {
|
||||
bool _isLoadingLocation = false;
|
||||
bool _isSearching = false;
|
||||
Position? _currentPosition;
|
||||
|
||||
|
||||
final Set<Marker> _markers = {};
|
||||
final Set<Circle> _circles = {};
|
||||
|
||||
|
||||
List<PlaceSuggestion> _suggestions = [];
|
||||
|
||||
|
||||
static final String _apiKey = dotenv.env['GOOGLE_MAPS_API_KEY'] ?? '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Si une recherche initiale est fournie, la pré-remplir et lancer la recherche
|
||||
if (widget.initialSearchQuery != null && widget.initialSearchQuery!.isNotEmpty) {
|
||||
if (widget.initialSearchQuery != null &&
|
||||
widget.initialSearchQuery!.isNotEmpty) {
|
||||
_searchController.text = widget.initialSearchQuery!;
|
||||
// Lancer la recherche automatiquement après un court délai pour laisser l'interface se charger
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
@@ -65,17 +66,19 @@ class _MapContentState extends State<MapContent> {
|
||||
'https://maps.googleapis.com/maps/api/place/autocomplete/json'
|
||||
'?input=${Uri.encodeComponent(query)}'
|
||||
'&key=$_apiKey'
|
||||
'&language=fr'
|
||||
'&language=fr',
|
||||
);
|
||||
|
||||
final response = await http.get(url);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = json.decode(response.body);
|
||||
|
||||
|
||||
if (data['status'] == 'OK') {
|
||||
final predictions = data['predictions'] as List;
|
||||
|
||||
|
||||
if (predictions.isNotEmpty) {
|
||||
// Prendre automatiquement la première suggestion
|
||||
final firstPrediction = predictions.first;
|
||||
@@ -83,7 +86,7 @@ class _MapContentState extends State<MapContent> {
|
||||
placeId: firstPrediction['place_id'],
|
||||
description: firstPrediction['description'],
|
||||
);
|
||||
|
||||
|
||||
// Effectuer la sélection automatique
|
||||
await _selectPlaceForInitialSearch(suggestion);
|
||||
} else {
|
||||
@@ -117,9 +120,11 @@ class _MapContentState extends State<MapContent> {
|
||||
|
||||
final response = await http.get(url);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = json.decode(response.body);
|
||||
|
||||
|
||||
if (data['status'] == 'OK') {
|
||||
final location = data['result']['geometry']['location'];
|
||||
final lat = location['lat'];
|
||||
@@ -132,7 +137,7 @@ class _MapContentState extends State<MapContent> {
|
||||
setState(() {
|
||||
// Garder le marqueur de position utilisateur s'il existe
|
||||
_markers.removeWhere((m) => m.markerId.value != 'user_location');
|
||||
|
||||
|
||||
// Ajouter le nouveau marqueur de lieu
|
||||
_markers.add(
|
||||
Marker(
|
||||
@@ -230,9 +235,7 @@ class _MapContentState extends State<MapContent> {
|
||||
const size = 120.0;
|
||||
|
||||
// Dessiner l'icône person_pin_circle en bleu
|
||||
final iconPainter = TextPainter(
|
||||
textDirection: TextDirection.ltr,
|
||||
);
|
||||
final iconPainter = TextPainter(textDirection: TextDirection.ltr);
|
||||
iconPainter.text = TextSpan(
|
||||
text: String.fromCharCode(Icons.person_pin_circle.codePoint),
|
||||
style: TextStyle(
|
||||
@@ -242,26 +245,20 @@ class _MapContentState extends State<MapContent> {
|
||||
),
|
||||
);
|
||||
iconPainter.layout();
|
||||
iconPainter.paint(
|
||||
canvas,
|
||||
Offset(
|
||||
(size - iconPainter.width) / 2,
|
||||
0,
|
||||
),
|
||||
);
|
||||
iconPainter.paint(canvas, Offset((size - iconPainter.width) / 2, 0));
|
||||
|
||||
final picture = pictureRecorder.endRecording();
|
||||
final image = await picture.toImage(size.toInt(), size.toInt());
|
||||
final bytes = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||
|
||||
return BitmapDescriptor.fromBytes(bytes!.buffer.asUint8List());
|
||||
return BitmapDescriptor.bytes(bytes!.buffer.asUint8List());
|
||||
}
|
||||
|
||||
// Ajouter le marqueur avec l'icône personnalisée
|
||||
Future<void> _addUserLocationMarker(LatLng position) async {
|
||||
_markers.clear();
|
||||
_circles.clear();
|
||||
|
||||
|
||||
// Ajouter un cercle de précision
|
||||
_circles.add(
|
||||
Circle(
|
||||
@@ -284,10 +281,14 @@ class _MapContentState extends State<MapContent> {
|
||||
markerId: const MarkerId('user_location'),
|
||||
position: position,
|
||||
icon: icon,
|
||||
anchor: const Offset(0.5, 0.85), // Ancrer au bas de l'icône (le point du pin)
|
||||
anchor: const Offset(
|
||||
0.5,
|
||||
0.85,
|
||||
), // Ancrer au bas de l'icône (le point du pin)
|
||||
infoWindow: InfoWindow(
|
||||
title: 'Ma position',
|
||||
snippet: 'Lat: ${position.latitude.toStringAsFixed(4)}, Lng: ${position.longitude.toStringAsFixed(4)}',
|
||||
snippet:
|
||||
'Lat: ${position.latitude.toStringAsFixed(4)}, Lng: ${position.longitude.toStringAsFixed(4)}',
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -311,23 +312,27 @@ class _MapContentState extends State<MapContent> {
|
||||
'https://maps.googleapis.com/maps/api/place/autocomplete/json'
|
||||
'?input=${Uri.encodeComponent(query)}'
|
||||
'&key=$_apiKey'
|
||||
'&language=fr'
|
||||
'&language=fr',
|
||||
);
|
||||
|
||||
final response = await http.get(url);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = json.decode(response.body);
|
||||
|
||||
|
||||
if (data['status'] == 'OK') {
|
||||
final predictions = data['predictions'] as List;
|
||||
|
||||
|
||||
setState(() {
|
||||
_suggestions = predictions
|
||||
.map((p) => PlaceSuggestion(
|
||||
placeId: p['place_id'],
|
||||
description: p['description'],
|
||||
))
|
||||
.map(
|
||||
(p) => PlaceSuggestion(
|
||||
placeId: p['place_id'],
|
||||
description: p['description'],
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
_isSearching = false;
|
||||
});
|
||||
@@ -363,9 +368,11 @@ class _MapContentState extends State<MapContent> {
|
||||
|
||||
final response = await http.get(url);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = json.decode(response.body);
|
||||
|
||||
|
||||
if (data['status'] == 'OK') {
|
||||
final location = data['result']['geometry']['location'];
|
||||
final lat = location['lat'];
|
||||
@@ -378,7 +385,7 @@ class _MapContentState extends State<MapContent> {
|
||||
setState(() {
|
||||
// Garder le marqueur de position utilisateur
|
||||
_markers.removeWhere((m) => m.markerId.value != 'user_location');
|
||||
|
||||
|
||||
// Ajouter le nouveau marqueur de lieu
|
||||
_markers.add(
|
||||
Marker(
|
||||
@@ -394,7 +401,9 @@ class _MapContentState extends State<MapContent> {
|
||||
CameraUpdate.newLatLngZoom(newPosition, 15),
|
||||
);
|
||||
|
||||
FocusScope.of(context).unfocus();
|
||||
if (mounted) {
|
||||
FocusScope.of(context).unfocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -545,7 +554,10 @@ class _MapContentState extends State<MapContent> {
|
||||
: Icon(Icons.search, color: Colors.grey[700]),
|
||||
suffixIcon: _searchController.text.isNotEmpty
|
||||
? IconButton(
|
||||
icon: Icon(Icons.clear, color: Colors.grey[700]),
|
||||
icon: Icon(
|
||||
Icons.clear,
|
||||
color: Colors.grey[700],
|
||||
),
|
||||
onPressed: () {
|
||||
_searchController.clear();
|
||||
setState(() {
|
||||
@@ -567,7 +579,8 @@ class _MapContentState extends State<MapContent> {
|
||||
),
|
||||
onChanged: (value) {
|
||||
// Ne pas rechercher si c'est juste le remplissage initial
|
||||
if (widget.initialSearchQuery != null && value == widget.initialSearchQuery) {
|
||||
if (widget.initialSearchQuery != null &&
|
||||
value == widget.initialSearchQuery) {
|
||||
return;
|
||||
}
|
||||
_searchPlaces(value);
|
||||
@@ -601,10 +614,8 @@ class _MapContentState extends State<MapContent> {
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: _suggestions.length,
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
height: 1,
|
||||
color: Colors.grey[300],
|
||||
),
|
||||
separatorBuilder: (context, index) =>
|
||||
Divider(height: 1, color: Colors.grey[300]),
|
||||
itemBuilder: (context, index) {
|
||||
final suggestion = _suggestions[index];
|
||||
return InkWell(
|
||||
@@ -664,8 +675,5 @@ class PlaceSuggestion {
|
||||
final String placeId;
|
||||
final String description;
|
||||
|
||||
PlaceSuggestion({
|
||||
required this.placeId,
|
||||
required this.description,
|
||||
});
|
||||
}
|
||||
PlaceSuggestion({required this.placeId, required this.description});
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../../../blocs/user/user_bloc.dart';
|
||||
import '../../../blocs/user/user_state.dart' as user_state;
|
||||
import '../../../blocs/user/user_event.dart' as user_event;
|
||||
import '../../../services/auth_service.dart';
|
||||
import '../../../services/logger_service.dart';
|
||||
|
||||
class ProfileContent extends StatelessWidget {
|
||||
ProfileContent({super.key});
|
||||
@@ -19,7 +20,8 @@ class ProfileContent extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return UserStateWrapper(
|
||||
builder: (context, user) {
|
||||
final isEmailAuth = user.authMethod == 'email' || user.authMethod == null;
|
||||
final isEmailAuth =
|
||||
user.authMethod == 'email' || user.authMethod == null;
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
@@ -40,10 +42,12 @@ class ProfileContent extends StatelessWidget {
|
||||
color: Colors.black.withValues(alpha: 0.1),
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 2),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
child: user.profilePictureUrl != null && user.profilePictureUrl!.isNotEmpty
|
||||
child:
|
||||
user.profilePictureUrl != null &&
|
||||
user.profilePictureUrl!.isNotEmpty
|
||||
? CircleAvatar(
|
||||
radius: 50,
|
||||
backgroundImage: NetworkImage(
|
||||
@@ -57,7 +61,9 @@ class ProfileContent extends StatelessWidget {
|
||||
)
|
||||
: CircleAvatar(
|
||||
radius: 50,
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
backgroundColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.primary,
|
||||
child: Text(
|
||||
user.prenom.isNotEmpty
|
||||
? user.prenom[0].toUpperCase()
|
||||
@@ -88,10 +94,7 @@ class ProfileContent extends StatelessWidget {
|
||||
// Email
|
||||
Text(
|
||||
user.email,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
|
||||
@@ -99,7 +102,10 @@ class ProfileContent extends StatelessWidget {
|
||||
|
||||
// Badge de méthode de connexion
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 6,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: _getAuthMethodColor(user.authMethod, context),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
@@ -120,7 +126,10 @@ class ProfileContent extends StatelessWidget {
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _getAuthMethodTextColor(user.authMethod, context),
|
||||
color: _getAuthMethodTextColor(
|
||||
user.authMethod,
|
||||
context,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -314,17 +323,13 @@ class ProfileContent extends StatelessWidget {
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: isDestructive
|
||||
? Colors.red
|
||||
color: isDestructive
|
||||
? Colors.red
|
||||
: (isDarkMode ? Colors.white : Colors.black87),
|
||||
),
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 16,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
Icon(Icons.arrow_forward_ios, size: 16, color: Colors.grey[400]),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -355,7 +360,7 @@ class ProfileContent extends StatelessWidget {
|
||||
|
||||
Color _getAuthMethodColor(String? authMethod, BuildContext context) {
|
||||
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
switch (authMethod) {
|
||||
case 'apple':
|
||||
return isDarkMode ? Colors.white : Colors.black87;
|
||||
@@ -368,7 +373,7 @@ class ProfileContent extends StatelessWidget {
|
||||
|
||||
Color _getAuthMethodTextColor(String? authMethod, BuildContext context) {
|
||||
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
switch (authMethod) {
|
||||
case 'apple':
|
||||
return isDarkMode ? Colors.black87 : Colors.white;
|
||||
@@ -401,7 +406,9 @@ class ProfileContent extends StatelessWidget {
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 50,
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
backgroundColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.primary,
|
||||
child: Text(
|
||||
prenomController.text.isNotEmpty
|
||||
? prenomController.text[0].toUpperCase()
|
||||
@@ -422,7 +429,11 @@ class ProfileContent extends StatelessWidget {
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
child: IconButton(
|
||||
icon: Icon(Icons.camera_alt, color: Colors.white, size: 20),
|
||||
icon: Icon(
|
||||
Icons.camera_alt,
|
||||
color: Colors.white,
|
||||
size: 20,
|
||||
),
|
||||
onPressed: () {
|
||||
_showPhotoPickerDialog(dialogContext);
|
||||
},
|
||||
@@ -511,60 +522,66 @@ class ProfileContent extends StatelessWidget {
|
||||
void _showPhotoPickerDialog(BuildContext context) {
|
||||
// Récupérer les références AVANT que le modal ne se ferme
|
||||
final userBloc = context.read<UserBloc>();
|
||||
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (BuildContext sheetContext) {
|
||||
return Container(
|
||||
child: Wrap(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: Icon(Icons.photo_library),
|
||||
title: Text('Galerie'),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_pickImageFromGallery(context, userBloc);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.camera_alt),
|
||||
title: Text('Caméra'),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_pickImageFromCamera(context, userBloc);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.close),
|
||||
title: Text('Annuler'),
|
||||
onTap: () => Navigator.pop(sheetContext),
|
||||
),
|
||||
],
|
||||
),
|
||||
return Wrap(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: Icon(Icons.photo_library),
|
||||
title: Text('Galerie'),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_pickImageFromGallery(context, userBloc);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.camera_alt),
|
||||
title: Text('Caméra'),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_pickImageFromCamera(context, userBloc);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.close),
|
||||
title: Text('Annuler'),
|
||||
onTap: () => Navigator.pop(sheetContext),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _pickImageFromGallery(BuildContext context, UserBloc userBloc) async {
|
||||
Future<void> _pickImageFromGallery(
|
||||
BuildContext context,
|
||||
UserBloc userBloc,
|
||||
) async {
|
||||
try {
|
||||
final ImagePicker picker = ImagePicker();
|
||||
final XFile? image = await picker.pickImage(source: ImageSource.gallery);
|
||||
|
||||
if (image != null) {
|
||||
if (image != null && context.mounted) {
|
||||
await _uploadProfilePicture(context, image.path, userBloc);
|
||||
}
|
||||
} catch (e) {
|
||||
_errorService.showError(message: 'Erreur lors de la sélection de l\'image');
|
||||
_errorService.showError(
|
||||
message: 'Erreur lors de la sélection de l\'image',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pickImageFromCamera(BuildContext context, UserBloc userBloc) async {
|
||||
Future<void> _pickImageFromCamera(
|
||||
BuildContext context,
|
||||
UserBloc userBloc,
|
||||
) async {
|
||||
try {
|
||||
final ImagePicker picker = ImagePicker();
|
||||
final XFile? image = await picker.pickImage(source: ImageSource.camera);
|
||||
|
||||
if (image != null) {
|
||||
if (image != null && context.mounted) {
|
||||
await _uploadProfilePicture(context, image.path, userBloc);
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -572,17 +589,23 @@ class ProfileContent extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _uploadProfilePicture(BuildContext context, String imagePath, UserBloc userBloc) async {
|
||||
Future<void> _uploadProfilePicture(
|
||||
BuildContext context,
|
||||
String imagePath,
|
||||
UserBloc userBloc,
|
||||
) async {
|
||||
try {
|
||||
final File imageFile = File(imagePath);
|
||||
|
||||
|
||||
// Vérifier que le fichier existe
|
||||
if (!await imageFile.exists()) {
|
||||
_errorService.showError(message: 'Le fichier image n\'existe pas');
|
||||
return;
|
||||
}
|
||||
|
||||
print('DEBUG: Taille du fichier: ${imageFile.lengthSync()} bytes');
|
||||
LoggerService.info(
|
||||
'DEBUG: Taille du fichier: ${imageFile.lengthSync()} bytes',
|
||||
);
|
||||
|
||||
final userState = userBloc.state;
|
||||
if (userState is! user_state.UserLoaded) {
|
||||
@@ -591,30 +614,35 @@ class ProfileContent extends StatelessWidget {
|
||||
}
|
||||
|
||||
final user = userState.user;
|
||||
|
||||
|
||||
// Créer un nom unique pour la photo
|
||||
final String fileName = 'profile_${user.id}_${DateTime.now().millisecondsSinceEpoch}.jpg';
|
||||
final String fileName =
|
||||
'profile_${user.id}_${DateTime.now().millisecondsSinceEpoch}.jpg';
|
||||
final Reference storageRef = FirebaseStorage.instance
|
||||
.ref()
|
||||
.child('profile_pictures')
|
||||
.child(fileName);
|
||||
|
||||
print('DEBUG: Chemin Storage: ${storageRef.fullPath}');
|
||||
print('DEBUG: Upload en cours pour $fileName');
|
||||
LoggerService.info('DEBUG: Chemin Storage: ${storageRef.fullPath}');
|
||||
LoggerService.info('DEBUG: Upload en cours pour $fileName');
|
||||
|
||||
// Uploader l'image avec gestion d'erreur détaillée
|
||||
try {
|
||||
final uploadTask = storageRef.putFile(imageFile);
|
||||
|
||||
|
||||
// Écouter la progression
|
||||
uploadTask.snapshotEvents.listen((TaskSnapshot snapshot) {
|
||||
print('DEBUG: Progression: ${snapshot.bytesTransferred}/${snapshot.totalBytes}');
|
||||
LoggerService.info(
|
||||
'DEBUG: Progression: ${snapshot.bytesTransferred}/${snapshot.totalBytes}',
|
||||
);
|
||||
});
|
||||
|
||||
final snapshot = await uploadTask;
|
||||
print('DEBUG: Upload terminé. État: ${snapshot.state}');
|
||||
LoggerService.info('DEBUG: Upload terminé. État: ${snapshot.state}');
|
||||
} on FirebaseException catch (e) {
|
||||
print('DEBUG: FirebaseException lors de l\'upload: ${e.code} - ${e.message}');
|
||||
LoggerService.error(
|
||||
'DEBUG: FirebaseException lors de l\'upload: ${e.code} - ${e.message}',
|
||||
);
|
||||
if (context.mounted) {
|
||||
_errorService.showError(
|
||||
message: 'Erreur Firebase: ${e.code}\n${e.message}',
|
||||
@@ -623,26 +651,22 @@ class ProfileContent extends StatelessWidget {
|
||||
return;
|
||||
}
|
||||
|
||||
print('DEBUG: Upload terminé, récupération de l\'URL');
|
||||
LoggerService.info('DEBUG: Upload terminé, récupération de l\'URL');
|
||||
|
||||
// Récupérer l'URL
|
||||
final String downloadUrl = await storageRef.getDownloadURL();
|
||||
|
||||
print('DEBUG: URL obtenue: $downloadUrl');
|
||||
LoggerService.info('DEBUG: URL obtenue: $downloadUrl');
|
||||
|
||||
// Mettre à jour le profil avec l'URL en utilisant la référence sauvegardée du BLoC
|
||||
print('DEBUG: Envoi de UserUpdated event au BLoC');
|
||||
userBloc.add(
|
||||
user_event.UserUpdated({
|
||||
'profilePictureUrl': downloadUrl,
|
||||
}),
|
||||
);
|
||||
LoggerService.info('DEBUG: Envoi de UserUpdated event au BLoC');
|
||||
userBloc.add(user_event.UserUpdated({'profilePictureUrl': downloadUrl}));
|
||||
|
||||
// Attendre un peu que Firestore se mette à jour
|
||||
await Future.delayed(Duration(milliseconds: 500));
|
||||
|
||||
if (context.mounted) {
|
||||
print('DEBUG: Affichage du succès');
|
||||
LoggerService.info('DEBUG: Affichage du succès');
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Photo de profil mise à jour !'),
|
||||
@@ -651,8 +675,8 @@ class ProfileContent extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
print('DEBUG: Erreur lors de l\'upload: $e');
|
||||
print('DEBUG: Stack trace: $stackTrace');
|
||||
LoggerService.error('DEBUG: Erreur lors de l\'upload: $e');
|
||||
LoggerService.error('DEBUG: Stack trace: $stackTrace');
|
||||
_errorService.logError(
|
||||
'ProfileContent - _uploadProfilePicture',
|
||||
'Erreur lors de l\'upload de la photo: $e\n$stackTrace',
|
||||
@@ -738,13 +762,15 @@ class ProfileContent extends StatelessWidget {
|
||||
email: user.email,
|
||||
);
|
||||
|
||||
Navigator.of(dialogContext).pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Mot de passe changé !'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
if (context.mounted) {
|
||||
Navigator.of(dialogContext).pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Mot de passe changé !'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
_errorService.showError(
|
||||
message: 'Erreur: Mot de passe actuel incorrect',
|
||||
@@ -801,13 +827,15 @@ class ProfileContent extends StatelessWidget {
|
||||
email: user.email,
|
||||
);
|
||||
|
||||
Navigator.of(dialogContext).pop();
|
||||
context.read<UserBloc>().add(user_event.UserLoggedOut());
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
context,
|
||||
'/login',
|
||||
(route) => false,
|
||||
);
|
||||
if (context.mounted) {
|
||||
Navigator.of(dialogContext).pop();
|
||||
context.read<UserBloc>().add(user_event.UserLoggedOut());
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
context,
|
||||
'/login',
|
||||
(route) => false,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
_errorService.showError(
|
||||
message: 'Erreur: Mot de passe incorrect',
|
||||
|
||||
Reference in New Issue
Block a user