Compare commits
10 Commits
41402e1b2c
...
bf796a661c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf796a661c | ||
|
|
272fce2e59 | ||
|
|
fd710b8cb8 | ||
|
|
cad9d42128 | ||
|
|
9198493dd5 | ||
|
|
f7eeb7c6f1 | ||
|
|
258f10b42b | ||
|
|
79cf3f4655 | ||
|
|
c322bc079a | ||
|
|
9101a94691 |
55
.github/workflows/deploy-playstore.yml
vendored
Normal file
55
.github/workflows/deploy-playstore.yml
vendored
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
name: Deploy to Play Store
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- release # L'action se déclenche uniquement sur la branche 'release'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_and_deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# 1. Récupérer le code
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# 2. Installer Java (requis pour Android build)
|
||||||
|
- uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'zulu'
|
||||||
|
java-version: '17'
|
||||||
|
|
||||||
|
# 3. Installer Flutter
|
||||||
|
- uses: subosito/flutter-action@v2
|
||||||
|
with:
|
||||||
|
channel: 'stable'
|
||||||
|
|
||||||
|
# 4. Gérer les dépendances
|
||||||
|
- run: flutter pub get
|
||||||
|
|
||||||
|
# 5. Créer le Keystore depuis le secret (Décodage)
|
||||||
|
- name: Decode Keystore
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 --decode > android/app/upload-keystore.jks
|
||||||
|
|
||||||
|
# 6. Créer le fichier key.properties pour que Gradle trouve la clé
|
||||||
|
- name: Create key.properties
|
||||||
|
run: |
|
||||||
|
echo "storePassword=${{ secrets.ANDROID_KEYSTORE_PASSWORD }}" > android/key.properties
|
||||||
|
echo "keyPassword=${{ secrets.ANDROID_KEY_PASSWORD }}" >> android/key.properties
|
||||||
|
echo "keyAlias=${{ secrets.ANDROID_KEY_ALIAS }}" >> android/key.properties
|
||||||
|
echo "storeFile=upload-keystore.jks" >> android/key.properties
|
||||||
|
|
||||||
|
# 7. Construire l'AppBundle (.aab)
|
||||||
|
- name: Build AppBundle
|
||||||
|
run: flutter build appbundle --release
|
||||||
|
|
||||||
|
# 8. Uploader sur le Play Store (Track: alpha = Test fermé)
|
||||||
|
- name: Upload to Play Store
|
||||||
|
uses: r0adkll/upload-google-play@v1
|
||||||
|
with:
|
||||||
|
serviceAccountJsonPlainText: ${{ secrets.PLAY_STORE_CONFIG_JSON }}
|
||||||
|
packageName: be.devdayronvl.travel_mate
|
||||||
|
releaseFiles: build/app/outputs/bundle/release/app-release.aab
|
||||||
|
track: alpha # 'alpha' correspond souvent au Test Fermé. Sinon 'internal' ou 'beta'.
|
||||||
|
status: completed
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -44,7 +44,9 @@ app.*.map.json
|
|||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/android/app/release
|
||||||
.vscode
|
.vscode
|
||||||
.VSCodeCounter
|
.VSCodeCounter/*
|
||||||
.env
|
.env
|
||||||
.env.local
|
.env.local
|
||||||
.env.*.local
|
.env.*.local
|
||||||
|
firestore.rules
|
||||||
|
storage.rules
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "com.example.travel_mate"
|
namespace = "be.davdayronvl.travel_mate"
|
||||||
compileSdk = flutter.compileSdkVersion
|
compileSdk = flutter.compileSdkVersion
|
||||||
ndkVersion = flutter.ndkVersion
|
ndkVersion = flutter.ndkVersion
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||||
applicationId = "com.example.travel_mate"
|
applicationId = "be.davdayronvl.travel_mate"
|
||||||
// You can update the following values to match your application needs.
|
// You can update the following values to match your application needs.
|
||||||
// For more information, see: https://flutter.dev/to/review-gradle-config.
|
// For more information, see: https://flutter.dev/to/review-gradle-config.
|
||||||
minSdk = flutter.minSdkVersion
|
minSdk = flutter.minSdkVersion
|
||||||
@@ -32,12 +32,18 @@ android {
|
|||||||
versionCode = flutter.versionCode
|
versionCode = flutter.versionCode
|
||||||
versionName = flutter.versionName
|
versionName = flutter.versionName
|
||||||
}
|
}
|
||||||
|
signingConfigs {
|
||||||
|
release {
|
||||||
|
keyAlias = keystoreProperties['keyAlias']
|
||||||
|
keyPassword = keystoreProperties['keyPassword']
|
||||||
|
storeFile = keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
|
||||||
|
storePassword = keystoreProperties['storePassword']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
// TODO: Add your own signing config for the release build.
|
signingConfig = signingConfigs.release
|
||||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
|
||||||
signingConfig = signingConfigs.getByName("debug")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<!-- Permissions pour écrire dans le stockage -->
|
<!-- Permissions pour écrire dans le stockage -->
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
<application
|
<application
|
||||||
android:label="travel_mate"
|
android:label="Travel Mate"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
android:icon="@mipmap/ic_launcher">
|
android:icon="@mipmap/ic_launcher">
|
||||||
<activity
|
<activity
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
|||||||
on<_AccountsUpdated>(_onAccountsUpdated);
|
on<_AccountsUpdated>(_onAccountsUpdated);
|
||||||
on<CreateAccount>(_onCreateAccount);
|
on<CreateAccount>(_onCreateAccount);
|
||||||
on<CreateAccountWithMembers>(_onCreateAccountWithMembers);
|
on<CreateAccountWithMembers>(_onCreateAccountWithMembers);
|
||||||
|
on<AddMemberToAccount>(_onAddMemberToAccount);
|
||||||
|
on<RemoveMemberFromAccount>(_onRemoveMemberFromAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onLoadAccountsByUserId(
|
Future<void> _onLoadAccountsByUserId(
|
||||||
@@ -109,6 +111,34 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _onAddMemberToAccount(
|
||||||
|
AddMemberToAccount event,
|
||||||
|
Emitter<AccountState> emit,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
emit(AccountLoading());
|
||||||
|
await _repository.addMemberToAccount(event.accountId, event.member);
|
||||||
|
emit(AccountOperationSuccess('Membre ajouté avec succès'));
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
_errorService.logError(e.toString(), stackTrace);
|
||||||
|
emit(AccountError('Erreur lors de l\'ajout du membre: ${e.toString()}'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onRemoveMemberFromAccount(
|
||||||
|
RemoveMemberFromAccount event,
|
||||||
|
Emitter<AccountState> emit,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
emit(AccountLoading());
|
||||||
|
await _repository.removeMemberFromAccount(event.accountId, event.memberId);
|
||||||
|
emit(AccountOperationSuccess('Membre supprimé avec succès'));
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
_errorService.logError(e.toString(), stackTrace);
|
||||||
|
emit(AccountError('Erreur lors de la suppression du membre: ${e.toString()}'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> close() {
|
Future<void> close() {
|
||||||
_accountsSubscription?.cancel();
|
_accountsSubscription?.cancel();
|
||||||
|
|||||||
@@ -85,4 +85,32 @@ class CreateAccountWithMembers extends AccountEvent {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [account, members];
|
List<Object?> get props => [account, members];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Event to add a member to an existing account.
|
||||||
|
///
|
||||||
|
/// This event is dispatched when a new member needs to be added to
|
||||||
|
/// an account, typically when editing a trip and adding new participants.
|
||||||
|
class AddMemberToAccount extends AccountEvent {
|
||||||
|
final String accountId;
|
||||||
|
final GroupMember member;
|
||||||
|
|
||||||
|
const AddMemberToAccount(this.accountId, this.member);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [accountId, member];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Event to remove a member from an existing account.
|
||||||
|
///
|
||||||
|
/// This event is dispatched when a member needs to be removed from
|
||||||
|
/// an account, typically when editing a trip and removing participants.
|
||||||
|
class RemoveMemberFromAccount extends AccountEvent {
|
||||||
|
final String accountId;
|
||||||
|
final String memberId;
|
||||||
|
|
||||||
|
const RemoveMemberFromAccount(this.accountId, this.memberId);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [accountId, memberId];
|
||||||
}
|
}
|
||||||
@@ -17,13 +17,14 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
required ActivityRepository repository,
|
required ActivityRepository repository,
|
||||||
required ActivityPlacesService placesService,
|
required ActivityPlacesService placesService,
|
||||||
required ErrorService errorService,
|
required ErrorService errorService,
|
||||||
}) : _repository = repository,
|
}) : _repository = repository,
|
||||||
_placesService = placesService,
|
_placesService = placesService,
|
||||||
_errorService = errorService,
|
_errorService = errorService,
|
||||||
super(const ActivityInitial()) {
|
super(const ActivityInitial()) {
|
||||||
|
|
||||||
on<LoadActivities>(_onLoadActivities);
|
on<LoadActivities>(_onLoadActivities);
|
||||||
on<LoadTripActivitiesPreservingSearch>(_onLoadTripActivitiesPreservingSearch);
|
on<LoadTripActivitiesPreservingSearch>(
|
||||||
|
_onLoadTripActivitiesPreservingSearch,
|
||||||
|
);
|
||||||
on<SearchActivities>(_onSearchActivities);
|
on<SearchActivities>(_onSearchActivities);
|
||||||
on<SearchActivitiesWithCoordinates>(_onSearchActivitiesWithCoordinates);
|
on<SearchActivitiesWithCoordinates>(_onSearchActivitiesWithCoordinates);
|
||||||
on<SearchActivitiesByText>(_onSearchActivitiesByText);
|
on<SearchActivitiesByText>(_onSearchActivitiesByText);
|
||||||
@@ -39,6 +40,7 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
on<RestoreCachedSearchResults>(_onRestoreCachedSearchResults);
|
on<RestoreCachedSearchResults>(_onRestoreCachedSearchResults);
|
||||||
on<RemoveFromSearchResults>(_onRemoveFromSearchResults);
|
on<RemoveFromSearchResults>(_onRemoveFromSearchResults);
|
||||||
on<AddActivityAndRemoveFromSearch>(_onAddActivityAndRemoveFromSearch);
|
on<AddActivityAndRemoveFromSearch>(_onAddActivityAndRemoveFromSearch);
|
||||||
|
on<UpdateActivityDate>(_onUpdateActivityDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles loading activities for a trip
|
/// Handles loading activities for a trip
|
||||||
@@ -48,15 +50,17 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
emit(const ActivityLoading());
|
emit(const ActivityLoading());
|
||||||
|
|
||||||
final activities = await _repository.getActivitiesByTrip(event.tripId);
|
final activities = await _repository.getActivitiesByTrip(event.tripId);
|
||||||
|
|
||||||
emit(ActivityLoaded(
|
emit(
|
||||||
activities: activities,
|
ActivityLoaded(activities: activities, filteredActivities: activities),
|
||||||
filteredActivities: activities,
|
);
|
||||||
));
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('activity_bloc', 'Erreur chargement activités: $e');
|
_errorService.logError(
|
||||||
|
'activity_bloc',
|
||||||
|
'Erreur chargement activités: $e',
|
||||||
|
);
|
||||||
emit(const ActivityError('Impossible de charger les activités'));
|
emit(const ActivityError('Impossible de charger les activités'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,24 +72,52 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
final activities = await _repository.getActivitiesByTrip(event.tripId);
|
final activities = await _repository.getActivitiesByTrip(event.tripId);
|
||||||
|
|
||||||
// Si on a un état de recherche actif, on le préserve
|
// Si on a un état de recherche actif, on le préserve
|
||||||
if (state is ActivitySearchResults) {
|
if (state is ActivitySearchResults) {
|
||||||
// On garde l'état de recherche inchangé, pas besoin d'émettre
|
// On garde l'état de recherche inchangé, pas besoin d'émettre
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sinon, on charge normalement
|
// Sinon, on charge normalement
|
||||||
emit(ActivityLoaded(
|
emit(
|
||||||
activities: activities,
|
ActivityLoaded(activities: activities, filteredActivities: activities),
|
||||||
filteredActivities: activities,
|
);
|
||||||
));
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('activity_bloc', 'Erreur chargement activités: $e');
|
_errorService.logError(
|
||||||
|
'activity_bloc',
|
||||||
|
'Erreur chargement activités: $e',
|
||||||
|
);
|
||||||
emit(const ActivityError('Impossible de charger les activités'));
|
emit(const ActivityError('Impossible de charger les activités'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _onUpdateActivityDate(
|
||||||
|
UpdateActivityDate event,
|
||||||
|
Emitter<ActivityState> emit,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
final activity = await _repository.getActivity(
|
||||||
|
event.tripId,
|
||||||
|
event.activityId,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (activity != null) {
|
||||||
|
final updatedActivity = activity.copyWith(
|
||||||
|
date: event.date,
|
||||||
|
clearDate: event.date == null,
|
||||||
|
);
|
||||||
|
await _repository.updateActivity(updatedActivity);
|
||||||
|
|
||||||
|
// Recharger les activités pour mettre à jour l'UI
|
||||||
|
add(LoadActivities(event.tripId));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
_errorService.logError('activity_bloc', 'Erreur mise à jour date: $e');
|
||||||
|
emit(const ActivityError('Impossible de mettre à jour la date'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Handles searching activities using Google Places API
|
/// Handles searching activities using Google Places API
|
||||||
Future<void> _onSearchActivities(
|
Future<void> _onSearchActivities(
|
||||||
SearchActivities event,
|
SearchActivities event,
|
||||||
@@ -99,17 +131,19 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
} else {
|
} else {
|
||||||
emit(const ActivitySearching());
|
emit(const ActivitySearching());
|
||||||
}
|
}
|
||||||
|
|
||||||
final searchResults = await _placesService.searchActivities(
|
final searchResults = await _placesService.searchActivities(
|
||||||
destination: event.destination,
|
destination: event.destination,
|
||||||
tripId: event.tripId,
|
tripId: event.tripId,
|
||||||
category: event.category,
|
category: event.category,
|
||||||
maxResults: event.maxResults ?? 20, // Par défaut 20, ou utiliser la valeur spécifiée
|
maxResults:
|
||||||
|
event.maxResults ??
|
||||||
|
20, // Par défaut 20, ou utiliser la valeur spécifiée
|
||||||
offset: event.offset ?? 0, // Par défaut 0
|
offset: event.offset ?? 0, // Par défaut 0
|
||||||
);
|
);
|
||||||
|
|
||||||
List<Activity> finalResults;
|
List<Activity> finalResults;
|
||||||
|
|
||||||
// Si on doit ajouter aux résultats existants
|
// Si on doit ajouter aux résultats existants
|
||||||
if (event.appendToExisting && state is ActivitySearchResults) {
|
if (event.appendToExisting && state is ActivitySearchResults) {
|
||||||
final currentState = state as ActivitySearchResults;
|
final currentState = state as ActivitySearchResults;
|
||||||
@@ -117,15 +151,17 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
} else {
|
} else {
|
||||||
finalResults = searchResults;
|
finalResults = searchResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mettre en cache les résultats
|
// Mettre en cache les résultats
|
||||||
ActivityCacheService().setCachedActivities(event.tripId, finalResults);
|
ActivityCacheService().setCachedActivities(event.tripId, finalResults);
|
||||||
|
|
||||||
emit(ActivitySearchResults(
|
emit(
|
||||||
searchResults: finalResults,
|
ActivitySearchResults(
|
||||||
query: event.category?.displayName ?? 'Toutes les activités',
|
searchResults: finalResults,
|
||||||
isLoading: false,
|
query: event.category?.displayName ?? 'Toutes les activités',
|
||||||
));
|
isLoading: false,
|
||||||
|
),
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('activity_bloc', 'Erreur recherche activités: $e');
|
_errorService.logError('activity_bloc', 'Erreur recherche activités: $e');
|
||||||
emit(const ActivityError('Impossible de rechercher les activités'));
|
emit(const ActivityError('Impossible de rechercher les activités'));
|
||||||
@@ -145,7 +181,7 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
} else {
|
} else {
|
||||||
emit(const ActivitySearching());
|
emit(const ActivitySearching());
|
||||||
}
|
}
|
||||||
|
|
||||||
final searchResults = await _placesService.searchActivitiesPaginated(
|
final searchResults = await _placesService.searchActivitiesPaginated(
|
||||||
latitude: event.latitude,
|
latitude: event.latitude,
|
||||||
longitude: event.longitude,
|
longitude: event.longitude,
|
||||||
@@ -153,10 +189,10 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
category: event.category,
|
category: event.category,
|
||||||
pageSize: event.maxResults ?? 20,
|
pageSize: event.maxResults ?? 20,
|
||||||
);
|
);
|
||||||
|
|
||||||
final activities = searchResults['activities'] as List<Activity>;
|
final activities = searchResults['activities'] as List<Activity>;
|
||||||
List<Activity> finalResults;
|
List<Activity> finalResults;
|
||||||
|
|
||||||
// Si on doit ajouter aux résultats existants
|
// Si on doit ajouter aux résultats existants
|
||||||
if (event.appendToExisting && state is ActivitySearchResults) {
|
if (event.appendToExisting && state is ActivitySearchResults) {
|
||||||
final currentState = state as ActivitySearchResults;
|
final currentState = state as ActivitySearchResults;
|
||||||
@@ -164,17 +200,22 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
} else {
|
} else {
|
||||||
finalResults = activities;
|
finalResults = activities;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mettre en cache les résultats
|
// Mettre en cache les résultats
|
||||||
ActivityCacheService().setCachedActivities(event.tripId, finalResults);
|
ActivityCacheService().setCachedActivities(event.tripId, finalResults);
|
||||||
|
|
||||||
emit(ActivitySearchResults(
|
emit(
|
||||||
searchResults: finalResults,
|
ActivitySearchResults(
|
||||||
query: event.category?.displayName ?? 'Toutes les activités',
|
searchResults: finalResults,
|
||||||
isLoading: false,
|
query: event.category?.displayName ?? 'Toutes les activités',
|
||||||
));
|
isLoading: false,
|
||||||
|
),
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('activity_bloc', 'Erreur recherche activités avec coordonnées: $e');
|
_errorService.logError(
|
||||||
|
'activity_bloc',
|
||||||
|
'Erreur recherche activités avec coordonnées: $e',
|
||||||
|
);
|
||||||
emit(const ActivityError('Impossible de rechercher les activités'));
|
emit(const ActivityError('Impossible de rechercher les activités'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,20 +227,19 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
emit(const ActivitySearching());
|
emit(const ActivitySearching());
|
||||||
|
|
||||||
final searchResults = await _placesService.searchActivitiesByText(
|
final searchResults = await _placesService.searchActivitiesByText(
|
||||||
query: event.query,
|
query: event.query,
|
||||||
destination: event.destination,
|
destination: event.destination,
|
||||||
tripId: event.tripId,
|
tripId: event.tripId,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Mettre en cache les résultats
|
// Mettre en cache les résultats
|
||||||
ActivityCacheService().setCachedActivities(event.tripId, searchResults);
|
ActivityCacheService().setCachedActivities(event.tripId, searchResults);
|
||||||
|
|
||||||
emit(ActivitySearchResults(
|
emit(
|
||||||
searchResults: searchResults,
|
ActivitySearchResults(searchResults: searchResults, query: event.query),
|
||||||
query: event.query,
|
);
|
||||||
));
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('activity_bloc', 'Erreur recherche textuelle: $e');
|
_errorService.logError('activity_bloc', 'Erreur recherche textuelle: $e');
|
||||||
emit(const ActivityError('Impossible de rechercher les activités'));
|
emit(const ActivityError('Impossible de rechercher les activités'));
|
||||||
@@ -218,7 +258,7 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
event.activity.tripId,
|
event.activity.tripId,
|
||||||
event.activity.placeId!,
|
event.activity.placeId!,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
emit(const ActivityError('Cette activité a déjà été ajoutée'));
|
emit(const ActivityError('Cette activité a déjà été ajoutée'));
|
||||||
return;
|
return;
|
||||||
@@ -226,20 +266,27 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final activityId = await _repository.addActivity(event.activity);
|
final activityId = await _repository.addActivity(event.activity);
|
||||||
|
|
||||||
if (activityId != null) {
|
if (activityId != null) {
|
||||||
// Si on est en état de recherche (suggestions Google), préserver cet état
|
// Si on est en état de recherche (suggestions Google), préserver cet état
|
||||||
if (state is ActivitySearchResults) {
|
if (state is ActivitySearchResults) {
|
||||||
// On ne change rien à l'état de recherche, on le garde tel quel
|
final currentState = state as ActivitySearchResults;
|
||||||
// La suppression de l'activité des résultats se fait dans _onRemoveFromSearchResults
|
// On garde l'état de recherche inchangé mais on ajoute l'info de l'activité ajoutée
|
||||||
|
emit(
|
||||||
|
currentState.copyWith(
|
||||||
|
newlyAddedActivity: event.activity.copyWith(id: activityId),
|
||||||
|
),
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sinon, émettre l'état d'ajout réussi
|
// Sinon, émettre l'état d'ajout réussi
|
||||||
emit(ActivityAdded(
|
emit(
|
||||||
activity: event.activity.copyWith(id: activityId),
|
ActivityAdded(
|
||||||
message: 'Activité ajoutée avec succès',
|
activity: event.activity.copyWith(id: activityId),
|
||||||
));
|
message: 'Activité ajoutée avec succès',
|
||||||
|
),
|
||||||
|
);
|
||||||
// Reload activities while preserving search results
|
// Reload activities while preserving search results
|
||||||
add(LoadTripActivitiesPreservingSearch(event.activity.tripId));
|
add(LoadTripActivitiesPreservingSearch(event.activity.tripId));
|
||||||
} else {
|
} else {
|
||||||
@@ -263,7 +310,7 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
event.activity.tripId,
|
event.activity.tripId,
|
||||||
event.activity.placeId!,
|
event.activity.placeId!,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
emit(const ActivityError('Cette activité a déjà été ajoutée'));
|
emit(const ActivityError('Cette activité a déjà été ajoutée'));
|
||||||
return;
|
return;
|
||||||
@@ -271,7 +318,7 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final activityId = await _repository.addActivity(event.activity);
|
final activityId = await _repository.addActivity(event.activity);
|
||||||
|
|
||||||
if (activityId != null) {
|
if (activityId != null) {
|
||||||
// Si on est en état de recherche (suggestions Google), préserver cet état
|
// Si on est en état de recherche (suggestions Google), préserver cet état
|
||||||
// en supprimant l'activité des résultats
|
// en supprimant l'activité des résultats
|
||||||
@@ -280,20 +327,24 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
final updatedResults = currentState.searchResults
|
final updatedResults = currentState.searchResults
|
||||||
.where((activity) => activity.id != event.googleActivityId)
|
.where((activity) => activity.id != event.googleActivityId)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
emit(ActivitySearchResults(
|
emit(
|
||||||
searchResults: updatedResults,
|
ActivitySearchResults(
|
||||||
query: currentState.query,
|
searchResults: updatedResults,
|
||||||
isLoading: false,
|
query: currentState.query,
|
||||||
));
|
isLoading: false,
|
||||||
|
),
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sinon, émettre l'état d'ajout réussi
|
// Sinon, émettre l'état d'ajout réussi
|
||||||
emit(ActivityAdded(
|
emit(
|
||||||
activity: event.activity.copyWith(id: activityId),
|
ActivityAdded(
|
||||||
message: 'Activité ajoutée avec succès',
|
activity: event.activity.copyWith(id: activityId),
|
||||||
));
|
message: 'Activité ajoutée avec succès',
|
||||||
|
),
|
||||||
|
);
|
||||||
// Reload activities while preserving search results
|
// Reload activities while preserving search results
|
||||||
add(LoadTripActivitiesPreservingSearch(event.activity.tripId));
|
add(LoadTripActivitiesPreservingSearch(event.activity.tripId));
|
||||||
} else {
|
} else {
|
||||||
@@ -313,35 +364,39 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
try {
|
try {
|
||||||
// Filter out existing activities
|
// Filter out existing activities
|
||||||
final filteredActivities = <Activity>[];
|
final filteredActivities = <Activity>[];
|
||||||
|
|
||||||
emit(ActivityBatchAdding(
|
emit(
|
||||||
activitiesToAdd: event.activities,
|
ActivityBatchAdding(
|
||||||
progress: 0,
|
activitiesToAdd: event.activities,
|
||||||
total: event.activities.length,
|
progress: 0,
|
||||||
));
|
total: event.activities.length,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
for (int i = 0; i < event.activities.length; i++) {
|
for (int i = 0; i < event.activities.length; i++) {
|
||||||
final activity = event.activities[i];
|
final activity = event.activities[i];
|
||||||
|
|
||||||
if (activity.placeId != null) {
|
if (activity.placeId != null) {
|
||||||
final existing = await _repository.findExistingActivity(
|
final existing = await _repository.findExistingActivity(
|
||||||
activity.tripId,
|
activity.tripId,
|
||||||
activity.placeId!,
|
activity.placeId!,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
filteredActivities.add(activity);
|
filteredActivities.add(activity);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
filteredActivities.add(activity);
|
filteredActivities.add(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update progress
|
// Update progress
|
||||||
emit(ActivityBatchAdding(
|
emit(
|
||||||
activitiesToAdd: event.activities,
|
ActivityBatchAdding(
|
||||||
progress: i + 1,
|
activitiesToAdd: event.activities,
|
||||||
total: event.activities.length,
|
progress: i + 1,
|
||||||
));
|
total: event.activities.length,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filteredActivities.isEmpty) {
|
if (filteredActivities.isEmpty) {
|
||||||
@@ -350,12 +405,14 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final addedIds = await _repository.addActivitiesBatch(filteredActivities);
|
final addedIds = await _repository.addActivitiesBatch(filteredActivities);
|
||||||
|
|
||||||
if (addedIds.isNotEmpty) {
|
if (addedIds.isNotEmpty) {
|
||||||
emit(ActivityOperationSuccess(
|
emit(
|
||||||
'${addedIds.length} activité(s) ajoutée(s) avec succès',
|
ActivityOperationSuccess(
|
||||||
operationType: 'batch_add',
|
'${addedIds.length} activité(s) ajoutée(s) avec succès',
|
||||||
));
|
operationType: 'batch_add',
|
||||||
|
),
|
||||||
|
);
|
||||||
// Reload activities
|
// Reload activities
|
||||||
add(LoadActivities(event.activities.first.tripId));
|
add(LoadActivities(event.activities.first.tripId));
|
||||||
} else {
|
} else {
|
||||||
@@ -376,10 +433,12 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
// Show voting state
|
// Show voting state
|
||||||
if (state is ActivityLoaded) {
|
if (state is ActivityLoaded) {
|
||||||
final currentState = state as ActivityLoaded;
|
final currentState = state as ActivityLoaded;
|
||||||
emit(ActivityVoting(
|
emit(
|
||||||
activityId: event.activityId,
|
ActivityVoting(
|
||||||
activities: currentState.activities,
|
activityId: event.activityId,
|
||||||
));
|
activities: currentState.activities,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final success = await _repository.voteForActivity(
|
final success = await _repository.voteForActivity(
|
||||||
@@ -387,31 +446,35 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
event.userId,
|
event.userId,
|
||||||
event.vote,
|
event.vote,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
emit(ActivityVoteRecorded(
|
emit(
|
||||||
activityId: event.activityId,
|
ActivityVoteRecorded(
|
||||||
vote: event.vote,
|
activityId: event.activityId,
|
||||||
userId: event.userId,
|
vote: event.vote,
|
||||||
));
|
userId: event.userId,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// Reload activities to reflect the new vote
|
// Reload activities to reflect the new vote
|
||||||
if (state is ActivityLoaded) {
|
if (state is ActivityLoaded) {
|
||||||
final currentState = state as ActivityLoaded;
|
final currentState = state as ActivityLoaded;
|
||||||
final activities = await _repository.getActivitiesByTrip(
|
final activities = await _repository.getActivitiesByTrip(
|
||||||
currentState.activities.first.tripId,
|
currentState.activities.first.tripId,
|
||||||
);
|
);
|
||||||
|
|
||||||
emit(currentState.copyWith(
|
emit(
|
||||||
activities: activities,
|
currentState.copyWith(
|
||||||
filteredActivities: _applyFilters(
|
activities: activities,
|
||||||
activities,
|
filteredActivities: _applyFilters(
|
||||||
currentState.activeFilter,
|
activities,
|
||||||
currentState.minRating,
|
currentState.activeFilter,
|
||||||
currentState.showVotedOnly,
|
currentState.minRating,
|
||||||
event.userId,
|
currentState.showVotedOnly,
|
||||||
|
event.userId,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
emit(const ActivityError('Impossible d\'enregistrer le vote'));
|
emit(const ActivityError('Impossible d\'enregistrer le vote'));
|
||||||
@@ -429,13 +492,15 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
final success = await _repository.deleteActivity(event.activityId);
|
final success = await _repository.deleteActivity(event.activityId);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
emit(ActivityDeleted(
|
emit(
|
||||||
activityId: event.activityId,
|
ActivityDeleted(
|
||||||
message: 'Activité supprimée avec succès',
|
activityId: event.activityId,
|
||||||
));
|
message: 'Activité supprimée avec succès',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// Reload if we're on the activity list
|
// Reload if we're on the activity list
|
||||||
if (state is ActivityLoaded) {
|
if (state is ActivityLoaded) {
|
||||||
final currentState = state as ActivityLoaded;
|
final currentState = state as ActivityLoaded;
|
||||||
@@ -459,7 +524,7 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
) async {
|
) async {
|
||||||
if (state is ActivityLoaded) {
|
if (state is ActivityLoaded) {
|
||||||
final currentState = state as ActivityLoaded;
|
final currentState = state as ActivityLoaded;
|
||||||
|
|
||||||
final filteredActivities = _applyFilters(
|
final filteredActivities = _applyFilters(
|
||||||
currentState.activities,
|
currentState.activities,
|
||||||
event.category,
|
event.category,
|
||||||
@@ -467,13 +532,15 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
event.showVotedOnly ?? false,
|
event.showVotedOnly ?? false,
|
||||||
'', // UserId would be needed for showVotedOnly filter
|
'', // UserId would be needed for showVotedOnly filter
|
||||||
);
|
);
|
||||||
|
|
||||||
emit(currentState.copyWith(
|
emit(
|
||||||
filteredActivities: filteredActivities,
|
currentState.copyWith(
|
||||||
activeFilter: event.category,
|
filteredActivities: filteredActivities,
|
||||||
minRating: event.minRating,
|
activeFilter: event.category,
|
||||||
showVotedOnly: event.showVotedOnly ?? false,
|
minRating: event.minRating,
|
||||||
));
|
showVotedOnly: event.showVotedOnly ?? false,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,20 +570,24 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
try {
|
try {
|
||||||
if (state is ActivityLoaded) {
|
if (state is ActivityLoaded) {
|
||||||
final currentState = state as ActivityLoaded;
|
final currentState = state as ActivityLoaded;
|
||||||
emit(ActivityUpdating(
|
emit(
|
||||||
activityId: event.activity.id,
|
ActivityUpdating(
|
||||||
activities: currentState.activities,
|
activityId: event.activity.id,
|
||||||
));
|
activities: currentState.activities,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final success = await _repository.updateActivity(event.activity);
|
final success = await _repository.updateActivity(event.activity);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
emit(const ActivityOperationSuccess(
|
emit(
|
||||||
'Activité mise à jour avec succès',
|
const ActivityOperationSuccess(
|
||||||
operationType: 'update',
|
'Activité mise à jour avec succès',
|
||||||
));
|
operationType: 'update',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// Reload activities
|
// Reload activities
|
||||||
add(LoadActivities(event.activity.tripId));
|
add(LoadActivities(event.activity.tripId));
|
||||||
} else {
|
} else {
|
||||||
@@ -536,11 +607,13 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
try {
|
try {
|
||||||
// This would require extending the Activity model to include favorites
|
// This would require extending the Activity model to include favorites
|
||||||
// For now, we'll use the voting system as a favorite system
|
// For now, we'll use the voting system as a favorite system
|
||||||
add(VoteForActivity(
|
add(
|
||||||
activityId: event.activityId,
|
VoteForActivity(
|
||||||
userId: event.userId,
|
activityId: event.activityId,
|
||||||
vote: 1,
|
userId: event.userId,
|
||||||
));
|
vote: 1,
|
||||||
|
),
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('activity_bloc', 'Erreur favori: $e');
|
_errorService.logError('activity_bloc', 'Erreur favori: $e');
|
||||||
emit(const ActivityError('Impossible de modifier les favoris'));
|
emit(const ActivityError('Impossible de modifier les favoris'));
|
||||||
@@ -558,7 +631,25 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
var filtered = activities;
|
var filtered = activities;
|
||||||
|
|
||||||
if (category != null) {
|
if (category != null) {
|
||||||
filtered = filtered.where((a) => a.category == category).toList();
|
filtered = filtered.where((a) {
|
||||||
|
// Check exact match (internal value)
|
||||||
|
if (a.category == category) return true;
|
||||||
|
|
||||||
|
// Check display name match
|
||||||
|
// Find the enum that matches the filter category (which is a display name)
|
||||||
|
try {
|
||||||
|
final categoryEnum = ActivityCategory.values.firstWhere(
|
||||||
|
(e) => e.displayName == category,
|
||||||
|
);
|
||||||
|
// Check if activity category matches the enum's google type or display name
|
||||||
|
return a.category == categoryEnum.googlePlaceType ||
|
||||||
|
a.category == categoryEnum.displayName ||
|
||||||
|
a.category.toLowerCase() == categoryEnum.name.toLowerCase();
|
||||||
|
} catch (_) {
|
||||||
|
// If no matching enum found, fallback to simple string comparison
|
||||||
|
return a.category.toLowerCase() == category.toLowerCase();
|
||||||
|
}
|
||||||
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minRating != null) {
|
if (minRating != null) {
|
||||||
@@ -580,18 +671,20 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
// Si on est actuellement dans un état de résultats de recherche
|
// Si on est actuellement dans un état de résultats de recherche
|
||||||
if (state is ActivitySearchResults) {
|
if (state is ActivitySearchResults) {
|
||||||
final currentState = state as ActivitySearchResults;
|
final currentState = state as ActivitySearchResults;
|
||||||
|
|
||||||
// Filtrer l'activité à retirer
|
// Filtrer l'activité à retirer
|
||||||
final updatedResults = currentState.searchResults
|
final updatedResults = currentState.searchResults
|
||||||
.where((activity) => activity.id != event.activityId)
|
.where((activity) => activity.id != event.activityId)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
// Émettre le nouvel état avec l'activité retirée
|
// Émettre le nouvel état avec l'activité retirée
|
||||||
emit(ActivitySearchResults(
|
emit(
|
||||||
searchResults: updatedResults,
|
ActivitySearchResults(
|
||||||
query: currentState.query,
|
searchResults: updatedResults,
|
||||||
isLoading: false,
|
query: currentState.query,
|
||||||
));
|
isLoading: false,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -600,10 +693,12 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
RestoreCachedSearchResults event,
|
RestoreCachedSearchResults event,
|
||||||
Emitter<ActivityState> emit,
|
Emitter<ActivityState> emit,
|
||||||
) async {
|
) async {
|
||||||
emit(ActivitySearchResults(
|
emit(
|
||||||
searchResults: event.searchResults,
|
ActivitySearchResults(
|
||||||
query: 'cached',
|
searchResults: event.searchResults,
|
||||||
isLoading: false,
|
query: 'cached',
|
||||||
));
|
isLoading: false,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,15 @@ class SearchActivities extends ActivityEvent {
|
|||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [tripId, destination, category, maxResults, offset, reset, appendToExisting];
|
List<Object?> get props => [
|
||||||
|
tripId,
|
||||||
|
destination,
|
||||||
|
category,
|
||||||
|
maxResults,
|
||||||
|
offset,
|
||||||
|
reset,
|
||||||
|
appendToExisting,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Event to search activities using coordinates directly (bypasses geocoding)
|
/// Event to search activities using coordinates directly (bypasses geocoding)
|
||||||
@@ -76,7 +84,16 @@ class SearchActivitiesWithCoordinates extends ActivityEvent {
|
|||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [tripId, latitude, longitude, category, maxResults, offset, reset, appendToExisting];
|
List<Object?> get props => [
|
||||||
|
tripId,
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
category,
|
||||||
|
maxResults,
|
||||||
|
offset,
|
||||||
|
reset,
|
||||||
|
appendToExisting,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Event to search activities by text query
|
/// Event to search activities by text query
|
||||||
@@ -95,6 +112,21 @@ class SearchActivitiesByText extends ActivityEvent {
|
|||||||
List<Object> get props => [tripId, destination, query];
|
List<Object> get props => [tripId, destination, query];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UpdateActivityDate extends ActivityEvent {
|
||||||
|
final String tripId;
|
||||||
|
final String activityId;
|
||||||
|
final DateTime? date;
|
||||||
|
|
||||||
|
const UpdateActivityDate({
|
||||||
|
required this.tripId,
|
||||||
|
required this.activityId,
|
||||||
|
this.date,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [tripId, activityId, date];
|
||||||
|
}
|
||||||
|
|
||||||
/// Event to add a single activity to the trip
|
/// Event to add a single activity to the trip
|
||||||
class AddActivity extends ActivityEvent {
|
class AddActivity extends ActivityEvent {
|
||||||
final Activity activity;
|
final Activity activity;
|
||||||
@@ -147,11 +179,7 @@ class FilterActivities extends ActivityEvent {
|
|||||||
final double? minRating;
|
final double? minRating;
|
||||||
final bool? showVotedOnly;
|
final bool? showVotedOnly;
|
||||||
|
|
||||||
const FilterActivities({
|
const FilterActivities({this.category, this.minRating, this.showVotedOnly});
|
||||||
this.category,
|
|
||||||
this.minRating,
|
|
||||||
this.showVotedOnly,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [category, minRating, showVotedOnly];
|
List<Object?> get props => [category, minRating, showVotedOnly];
|
||||||
@@ -228,4 +256,4 @@ class AddActivityAndRemoveFromSearch extends ActivityEvent {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [activity, googleActivityId];
|
List<Object> get props => [activity, googleActivityId];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,9 @@ class ActivityLoaded extends ActivityState {
|
|||||||
|
|
||||||
/// Gets activities by category
|
/// Gets activities by category
|
||||||
List<Activity> getActivitiesByCategory(String category) {
|
List<Activity> getActivitiesByCategory(String category) {
|
||||||
return activities.where((activity) => activity.category == category).toList();
|
return activities
|
||||||
|
.where((activity) => activity.category == category)
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets top rated activities
|
/// Gets top rated activities
|
||||||
@@ -77,14 +79,14 @@ class ActivityLoaded extends ActivityState {
|
|||||||
sorted.sort((a, b) {
|
sorted.sort((a, b) {
|
||||||
final aScore = a.totalVotes;
|
final aScore = a.totalVotes;
|
||||||
final bScore = b.totalVotes;
|
final bScore = b.totalVotes;
|
||||||
|
|
||||||
if (aScore != bScore) {
|
if (aScore != bScore) {
|
||||||
return bScore.compareTo(aScore);
|
return bScore.compareTo(aScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (b.rating ?? 0).compareTo(a.rating ?? 0);
|
return (b.rating ?? 0).compareTo(a.rating ?? 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
return sorted.take(limit).toList();
|
return sorted.take(limit).toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,26 +96,35 @@ class ActivitySearchResults extends ActivityState {
|
|||||||
final List<Activity> searchResults;
|
final List<Activity> searchResults;
|
||||||
final String query;
|
final String query;
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
|
final Activity? newlyAddedActivity;
|
||||||
|
|
||||||
const ActivitySearchResults({
|
const ActivitySearchResults({
|
||||||
required this.searchResults,
|
required this.searchResults,
|
||||||
required this.query,
|
required this.query,
|
||||||
this.isLoading = false,
|
this.isLoading = false,
|
||||||
|
this.newlyAddedActivity,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [searchResults, query, isLoading];
|
List<Object?> get props => [
|
||||||
|
searchResults,
|
||||||
|
query,
|
||||||
|
isLoading,
|
||||||
|
newlyAddedActivity,
|
||||||
|
];
|
||||||
|
|
||||||
/// Creates a copy with optional modifications
|
/// Creates a copy with optional modifications
|
||||||
ActivitySearchResults copyWith({
|
ActivitySearchResults copyWith({
|
||||||
List<Activity>? searchResults,
|
List<Activity>? searchResults,
|
||||||
String? query,
|
String? query,
|
||||||
bool? isLoading,
|
bool? isLoading,
|
||||||
|
Activity? newlyAddedActivity,
|
||||||
}) {
|
}) {
|
||||||
return ActivitySearchResults(
|
return ActivitySearchResults(
|
||||||
searchResults: searchResults ?? this.searchResults,
|
searchResults: searchResults ?? this.searchResults,
|
||||||
query: query ?? this.query,
|
query: query ?? this.query,
|
||||||
isLoading: isLoading ?? this.isLoading,
|
isLoading: isLoading ?? this.isLoading,
|
||||||
|
newlyAddedActivity: newlyAddedActivity ?? this.newlyAddedActivity,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,10 +134,7 @@ class ActivityOperationSuccess extends ActivityState {
|
|||||||
final String message;
|
final String message;
|
||||||
final String? operationType;
|
final String? operationType;
|
||||||
|
|
||||||
const ActivityOperationSuccess(
|
const ActivityOperationSuccess(this.message, {this.operationType});
|
||||||
this.message, {
|
|
||||||
this.operationType,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [message, operationType];
|
List<Object?> get props => [message, operationType];
|
||||||
@@ -138,11 +146,7 @@ class ActivityError extends ActivityState {
|
|||||||
final String? errorCode;
|
final String? errorCode;
|
||||||
final dynamic error;
|
final dynamic error;
|
||||||
|
|
||||||
const ActivityError(
|
const ActivityError(this.message, {this.errorCode, this.error});
|
||||||
this.message, {
|
|
||||||
this.errorCode,
|
|
||||||
this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [message, errorCode, error];
|
List<Object?> get props => [message, errorCode, error];
|
||||||
@@ -153,10 +157,7 @@ class ActivityVoting extends ActivityState {
|
|||||||
final String activityId;
|
final String activityId;
|
||||||
final List<Activity> activities;
|
final List<Activity> activities;
|
||||||
|
|
||||||
const ActivityVoting({
|
const ActivityVoting({required this.activityId, required this.activities});
|
||||||
required this.activityId,
|
|
||||||
required this.activities,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [activityId, activities];
|
List<Object> get props => [activityId, activities];
|
||||||
@@ -167,10 +168,7 @@ class ActivityUpdating extends ActivityState {
|
|||||||
final String activityId;
|
final String activityId;
|
||||||
final List<Activity> activities;
|
final List<Activity> activities;
|
||||||
|
|
||||||
const ActivityUpdating({
|
const ActivityUpdating({required this.activityId, required this.activities});
|
||||||
required this.activityId,
|
|
||||||
required this.activities,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [activityId, activities];
|
List<Object> get props => [activityId, activities];
|
||||||
@@ -200,10 +198,7 @@ class ActivityAdded extends ActivityState {
|
|||||||
final Activity activity;
|
final Activity activity;
|
||||||
final String message;
|
final String message;
|
||||||
|
|
||||||
const ActivityAdded({
|
const ActivityAdded({required this.activity, required this.message});
|
||||||
required this.activity,
|
|
||||||
required this.message,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [activity, message];
|
List<Object> get props => [activity, message];
|
||||||
@@ -214,10 +209,7 @@ class ActivityDeleted extends ActivityState {
|
|||||||
final String activityId;
|
final String activityId;
|
||||||
final String message;
|
final String message;
|
||||||
|
|
||||||
const ActivityDeleted({
|
const ActivityDeleted({required this.activityId, required this.message});
|
||||||
required this.activityId,
|
|
||||||
required this.message,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [activityId, message];
|
List<Object> get props => [activityId, message];
|
||||||
@@ -237,4 +229,4 @@ class ActivityVoteRecorded extends ActivityState {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [activityId, vote, userId];
|
List<Object> get props => [activityId, vote, userId];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,10 @@
|
|||||||
/// balanceRepository: balanceRepository,
|
/// balanceRepository: balanceRepository,
|
||||||
/// expenseRepository: expenseRepository,
|
/// expenseRepository: expenseRepository,
|
||||||
/// );
|
/// );
|
||||||
///
|
///
|
||||||
/// // Load balances for a group
|
/// // Load balances for a group
|
||||||
/// balanceBloc.add(LoadGroupBalances('groupId123'));
|
/// balanceBloc.add(LoadGroupBalances('groupId123'));
|
||||||
///
|
///
|
||||||
/// // Mark a settlement as completed
|
/// // Mark a settlement as completed
|
||||||
/// balanceBloc.add(MarkSettlementAsCompleted(
|
/// balanceBloc.add(MarkSettlementAsCompleted(
|
||||||
/// groupId: 'groupId123',
|
/// groupId: 'groupId123',
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
/// ));
|
/// ));
|
||||||
/// ```
|
/// ```
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import '../../repositories/balance_repository.dart';
|
import '../../repositories/balance_repository.dart';
|
||||||
import '../../repositories/expense_repository.dart';
|
import '../../repositories/expense_repository.dart';
|
||||||
@@ -46,10 +47,10 @@ class BalanceBloc extends Bloc<BalanceEvent, BalanceState> {
|
|||||||
final ErrorService _errorService;
|
final ErrorService _errorService;
|
||||||
|
|
||||||
/// Constructor for BalanceBloc.
|
/// Constructor for BalanceBloc.
|
||||||
///
|
///
|
||||||
/// Initializes the bloc with required repositories and optional services.
|
/// Initializes the bloc with required repositories and optional services.
|
||||||
/// Sets up event handlers for balance-related operations.
|
/// Sets up event handlers for balance-related operations.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [balanceRepository]: Repository for balance data operations
|
/// [balanceRepository]: Repository for balance data operations
|
||||||
/// [expenseRepository]: Repository for expense data operations
|
/// [expenseRepository]: Repository for expense data operations
|
||||||
@@ -61,7 +62,12 @@ class BalanceBloc extends Bloc<BalanceEvent, BalanceState> {
|
|||||||
BalanceService? balanceService,
|
BalanceService? balanceService,
|
||||||
ErrorService? errorService,
|
ErrorService? errorService,
|
||||||
}) : _balanceRepository = balanceRepository,
|
}) : _balanceRepository = balanceRepository,
|
||||||
_balanceService = balanceService ?? BalanceService(balanceRepository: balanceRepository, expenseRepository: expenseRepository),
|
_balanceService =
|
||||||
|
balanceService ??
|
||||||
|
BalanceService(
|
||||||
|
balanceRepository: balanceRepository,
|
||||||
|
expenseRepository: expenseRepository,
|
||||||
|
),
|
||||||
_errorService = errorService ?? ErrorService(),
|
_errorService = errorService ?? ErrorService(),
|
||||||
super(BalanceInitial()) {
|
super(BalanceInitial()) {
|
||||||
on<LoadGroupBalances>(_onLoadGroupBalance);
|
on<LoadGroupBalances>(_onLoadGroupBalance);
|
||||||
@@ -70,11 +76,11 @@ class BalanceBloc extends Bloc<BalanceEvent, BalanceState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [LoadGroupBalances] events.
|
/// Handles [LoadGroupBalances] events.
|
||||||
///
|
///
|
||||||
/// Loads and calculates user balances for a specific group along with
|
/// Loads and calculates user balances for a specific group along with
|
||||||
/// optimal settlement recommendations. This provides a complete overview
|
/// optimal settlement recommendations. This provides a complete overview
|
||||||
/// of who owes money to whom and the most efficient payment strategy.
|
/// of who owes money to whom and the most efficient payment strategy.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [event]: The LoadGroupBalances event containing the group ID
|
/// [event]: The LoadGroupBalances event containing the group ID
|
||||||
/// [emit]: State emitter function
|
/// [emit]: State emitter function
|
||||||
@@ -83,18 +89,22 @@ class BalanceBloc extends Bloc<BalanceEvent, BalanceState> {
|
|||||||
Emitter<BalanceState> emit,
|
Emitter<BalanceState> emit,
|
||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
emit(BalanceLoading());
|
// Emit empty state initially to avoid infinite spinner
|
||||||
|
emit(const GroupBalancesLoaded(balances: [], settlements: []));
|
||||||
|
|
||||||
// Calculate group user balances
|
// Calculate group user balances
|
||||||
final userBalances = await _balanceRepository.calculateGroupUserBalances(event.groupId);
|
final userBalances = await _balanceRepository.calculateGroupUserBalances(
|
||||||
|
event.groupId,
|
||||||
|
);
|
||||||
|
|
||||||
// Calculate optimal settlements
|
// Calculate optimal settlements
|
||||||
final settlements = await _balanceService.calculateOptimalSettlements(event.groupId);
|
final settlements = await _balanceService.calculateOptimalSettlements(
|
||||||
|
event.groupId,
|
||||||
emit(GroupBalancesLoaded(
|
);
|
||||||
balances: userBalances,
|
|
||||||
settlements: settlements,
|
emit(
|
||||||
));
|
GroupBalancesLoaded(balances: userBalances, settlements: settlements),
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('BalanceBloc', 'Error loading balance: $e');
|
_errorService.logError('BalanceBloc', 'Error loading balance: $e');
|
||||||
emit(BalanceError(e.toString()));
|
emit(BalanceError(e.toString()));
|
||||||
@@ -102,11 +112,11 @@ class BalanceBloc extends Bloc<BalanceEvent, BalanceState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [RefreshBalance] events.
|
/// Handles [RefreshBalance] events.
|
||||||
///
|
///
|
||||||
/// Refreshes the balance data for a group while trying to maintain the current
|
/// Refreshes the balance data for a group while trying to maintain the current
|
||||||
/// state when possible to provide a smoother user experience. Only shows loading
|
/// state when possible to provide a smoother user experience. Only shows loading
|
||||||
/// state if there's no existing balance data.
|
/// state if there's no existing balance data.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [event]: The RefreshBalance event containing the group ID
|
/// [event]: The RefreshBalance event containing the group ID
|
||||||
/// [emit]: State emitter function
|
/// [emit]: State emitter function
|
||||||
@@ -119,17 +129,20 @@ class BalanceBloc extends Bloc<BalanceEvent, BalanceState> {
|
|||||||
if (state is! GroupBalancesLoaded) {
|
if (state is! GroupBalancesLoaded) {
|
||||||
emit(BalanceLoading());
|
emit(BalanceLoading());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate group user balances
|
// Calculate group user balances
|
||||||
final userBalances = await _balanceRepository.calculateGroupUserBalances(event.groupId);
|
final userBalances = await _balanceRepository.calculateGroupUserBalances(
|
||||||
|
event.groupId,
|
||||||
|
);
|
||||||
|
|
||||||
// Calculate optimal settlements
|
// Calculate optimal settlements
|
||||||
final settlements = await _balanceService.calculateOptimalSettlements(event.groupId);
|
final settlements = await _balanceService.calculateOptimalSettlements(
|
||||||
|
event.groupId,
|
||||||
emit(GroupBalancesLoaded(
|
);
|
||||||
balances: userBalances,
|
|
||||||
settlements: settlements,
|
emit(
|
||||||
));
|
GroupBalancesLoaded(balances: userBalances, settlements: settlements),
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('BalanceBloc', 'Error refreshing balance: $e');
|
_errorService.logError('BalanceBloc', 'Error refreshing balance: $e');
|
||||||
emit(BalanceError(e.toString()));
|
emit(BalanceError(e.toString()));
|
||||||
@@ -137,11 +150,11 @@ class BalanceBloc extends Bloc<BalanceEvent, BalanceState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [MarkSettlementAsCompleted] events.
|
/// Handles [MarkSettlementAsCompleted] events.
|
||||||
///
|
///
|
||||||
/// Records a settlement transaction between two users, marking that
|
/// Records a settlement transaction between two users, marking that
|
||||||
/// a debt has been paid. This updates the balance calculations and
|
/// a debt has been paid. This updates the balance calculations and
|
||||||
/// automatically refreshes the group balance data to reflect the change.
|
/// automatically refreshes the group balance data to reflect the change.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [event]: The MarkSettlementAsCompleted event containing settlement details
|
/// [event]: The MarkSettlementAsCompleted event containing settlement details
|
||||||
/// [emit]: State emitter function
|
/// [emit]: State emitter function
|
||||||
@@ -156,9 +169,9 @@ class BalanceBloc extends Bloc<BalanceEvent, BalanceState> {
|
|||||||
toUserId: event.toUserId,
|
toUserId: event.toUserId,
|
||||||
amount: event.amount,
|
amount: event.amount,
|
||||||
);
|
);
|
||||||
|
|
||||||
emit(const BalanceOperationSuccess('Settlement marked as completed'));
|
emit(const BalanceOperationSuccess('Settlement marked as completed'));
|
||||||
|
|
||||||
// Reload balance after settlement
|
// Reload balance after settlement
|
||||||
add(RefreshBalance(event.groupId));
|
add(RefreshBalance(event.groupId));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -166,4 +179,4 @@ class BalanceBloc extends Bloc<BalanceEvent, BalanceState> {
|
|||||||
emit(BalanceError(e.toString()));
|
emit(BalanceError(e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import 'expense_event.dart';
|
|||||||
import 'expense_state.dart';
|
import 'expense_state.dart';
|
||||||
|
|
||||||
/// BLoC for managing expense operations and state.
|
/// BLoC for managing expense operations and state.
|
||||||
///
|
///
|
||||||
/// This BLoC handles expense-related operations including loading expenses,
|
/// This BLoC handles expense-related operations including loading expenses,
|
||||||
/// creating new expenses, updating existing ones, deleting expenses, and
|
/// creating new expenses, updating existing ones, deleting expenses, and
|
||||||
/// managing expense splits. It coordinates with the expense repository and
|
/// managing expense splits. It coordinates with the expense repository and
|
||||||
@@ -15,18 +15,18 @@ import 'expense_state.dart';
|
|||||||
class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
||||||
/// Repository for expense data operations.
|
/// Repository for expense data operations.
|
||||||
final ExpenseRepository _expenseRepository;
|
final ExpenseRepository _expenseRepository;
|
||||||
|
|
||||||
/// Service for expense business logic and validation.
|
/// Service for expense business logic and validation.
|
||||||
final ExpenseService _expenseService;
|
final ExpenseService _expenseService;
|
||||||
|
|
||||||
/// Service for error handling and logging.
|
/// Service for error handling and logging.
|
||||||
final ErrorService _errorService;
|
final ErrorService _errorService;
|
||||||
|
|
||||||
/// Subscription to the expenses stream for real-time updates.
|
/// Subscription to the expenses stream for real-time updates.
|
||||||
StreamSubscription? _expensesSubscription;
|
StreamSubscription? _expensesSubscription;
|
||||||
|
|
||||||
/// Creates a new [ExpenseBloc] with required dependencies.
|
/// Creates a new [ExpenseBloc] with required dependencies.
|
||||||
///
|
///
|
||||||
/// [expenseRepository] is required for data operations.
|
/// [expenseRepository] is required for data operations.
|
||||||
/// [expenseService] and [errorService] have default implementations if not provided.
|
/// [expenseService] and [errorService] have default implementations if not provided.
|
||||||
ExpenseBloc({
|
ExpenseBloc({
|
||||||
@@ -34,10 +34,11 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
ExpenseService? expenseService,
|
ExpenseService? expenseService,
|
||||||
ErrorService? errorService,
|
ErrorService? errorService,
|
||||||
}) : _expenseRepository = expenseRepository,
|
}) : _expenseRepository = expenseRepository,
|
||||||
_expenseService = expenseService ?? ExpenseService(expenseRepository: expenseRepository),
|
_expenseService =
|
||||||
|
expenseService ??
|
||||||
|
ExpenseService(expenseRepository: expenseRepository),
|
||||||
_errorService = errorService ?? ErrorService(),
|
_errorService = errorService ?? ErrorService(),
|
||||||
super(ExpenseInitial()) {
|
super(ExpenseInitial()) {
|
||||||
|
|
||||||
on<LoadExpensesByGroup>(_onLoadExpensesByGroup);
|
on<LoadExpensesByGroup>(_onLoadExpensesByGroup);
|
||||||
on<ExpensesUpdated>(_onExpensesUpdated);
|
on<ExpensesUpdated>(_onExpensesUpdated);
|
||||||
on<CreateExpense>(_onCreateExpense);
|
on<CreateExpense>(_onCreateExpense);
|
||||||
@@ -48,7 +49,7 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [LoadExpensesByGroup] events.
|
/// Handles [LoadExpensesByGroup] events.
|
||||||
///
|
///
|
||||||
/// Sets up a stream subscription to receive real-time updates for expenses
|
/// Sets up a stream subscription to receive real-time updates for expenses
|
||||||
/// in the specified group. Cancels any existing subscription before creating a new one.
|
/// in the specified group. Cancels any existing subscription before creating a new one.
|
||||||
Future<void> _onLoadExpensesByGroup(
|
Future<void> _onLoadExpensesByGroup(
|
||||||
@@ -56,15 +57,18 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
Emitter<ExpenseState> emit,
|
Emitter<ExpenseState> emit,
|
||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
emit(ExpenseLoading());
|
// Emit empty state initially to avoid infinite spinner
|
||||||
|
// The stream will update with actual data when available
|
||||||
|
emit(const ExpensesLoaded(expenses: []));
|
||||||
|
|
||||||
await _expensesSubscription?.cancel();
|
await _expensesSubscription?.cancel();
|
||||||
|
|
||||||
_expensesSubscription = _expenseRepository
|
_expensesSubscription = _expenseRepository
|
||||||
.getExpensesStream(event.groupId)
|
.getExpensesStream(event.groupId)
|
||||||
.listen(
|
.listen(
|
||||||
(expenses) => add(ExpensesUpdated(expenses)),
|
(expenses) => add(ExpensesUpdated(expenses)),
|
||||||
onError: (error) => add(ExpensesUpdated([], error: error.toString())),
|
onError: (error) =>
|
||||||
|
add(ExpensesUpdated([], error: error.toString())),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('ExpenseBloc', 'Error loading expenses: $e');
|
_errorService.logError('ExpenseBloc', 'Error loading expenses: $e');
|
||||||
@@ -73,10 +77,10 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [ExpensesUpdated] events.
|
/// Handles [ExpensesUpdated] events.
|
||||||
///
|
///
|
||||||
/// Processes real-time updates from the expense stream, either emitting
|
/// Processes real-time updates from the expense stream, either emitting
|
||||||
/// the updated expense list or an error state if the stream encountered an error.
|
/// the updated expense list or an error state if the stream encountered an error.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [event]: The ExpensesUpdated event containing expenses or error information
|
/// [event]: The ExpensesUpdated event containing expenses or error information
|
||||||
/// [emit]: State emitter function
|
/// [emit]: State emitter function
|
||||||
@@ -92,11 +96,11 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [CreateExpense] events.
|
/// Handles [CreateExpense] events.
|
||||||
///
|
///
|
||||||
/// Creates a new expense with validation and optional receipt image upload.
|
/// Creates a new expense with validation and optional receipt image upload.
|
||||||
/// Uses the expense service to handle business logic and validation,
|
/// Uses the expense service to handle business logic and validation,
|
||||||
/// including currency conversion and split calculations.
|
/// including currency conversion and split calculations.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [event]: The CreateExpense event containing expense data and optional receipt
|
/// [event]: The CreateExpense event containing expense data and optional receipt
|
||||||
/// [emit]: State emitter function
|
/// [emit]: State emitter function
|
||||||
@@ -105,7 +109,10 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
Emitter<ExpenseState> emit,
|
Emitter<ExpenseState> emit,
|
||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
await _expenseService.createExpenseWithValidation(event.expense, event.receiptImage);
|
await _expenseService.createExpenseWithValidation(
|
||||||
|
event.expense,
|
||||||
|
event.receiptImage,
|
||||||
|
);
|
||||||
emit(const ExpenseOperationSuccess('Expense created successfully'));
|
emit(const ExpenseOperationSuccess('Expense created successfully'));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('ExpenseBloc', 'Error creating expense: $e');
|
_errorService.logError('ExpenseBloc', 'Error creating expense: $e');
|
||||||
@@ -114,11 +121,11 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [UpdateExpense] events.
|
/// Handles [UpdateExpense] events.
|
||||||
///
|
///
|
||||||
/// Updates an existing expense with validation and optional new receipt image.
|
/// Updates an existing expense with validation and optional new receipt image.
|
||||||
/// Uses the expense service to handle business logic, validation, and
|
/// Uses the expense service to handle business logic, validation, and
|
||||||
/// recalculation of splits if expense details change.
|
/// recalculation of splits if expense details change.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [event]: The UpdateExpense event containing updated expense data and optional new receipt
|
/// [event]: The UpdateExpense event containing updated expense data and optional new receipt
|
||||||
/// [emit]: State emitter function
|
/// [emit]: State emitter function
|
||||||
@@ -127,7 +134,10 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
Emitter<ExpenseState> emit,
|
Emitter<ExpenseState> emit,
|
||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
await _expenseService.updateExpenseWithValidation(event.expense, event.newReceiptImage);
|
await _expenseService.updateExpenseWithValidation(
|
||||||
|
event.expense,
|
||||||
|
event.newReceiptImage,
|
||||||
|
);
|
||||||
emit(const ExpenseOperationSuccess('Expense updated successfully'));
|
emit(const ExpenseOperationSuccess('Expense updated successfully'));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('ExpenseBloc', 'Error updating expense: $e');
|
_errorService.logError('ExpenseBloc', 'Error updating expense: $e');
|
||||||
@@ -136,10 +146,10 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [DeleteExpense] events.
|
/// Handles [DeleteExpense] events.
|
||||||
///
|
///
|
||||||
/// Permanently deletes an expense from the database. This action
|
/// Permanently deletes an expense from the database. This action
|
||||||
/// cannot be undone and will affect group balance calculations.
|
/// cannot be undone and will affect group balance calculations.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [event]: The DeleteExpense event containing the expense ID to delete
|
/// [event]: The DeleteExpense event containing the expense ID to delete
|
||||||
/// [emit]: State emitter function
|
/// [emit]: State emitter function
|
||||||
@@ -157,11 +167,11 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [MarkSplitAsPaid] events.
|
/// Handles [MarkSplitAsPaid] events.
|
||||||
///
|
///
|
||||||
/// Marks a user's portion of an expense split as paid, updating the
|
/// Marks a user's portion of an expense split as paid, updating the
|
||||||
/// expense's split information and affecting balance calculations.
|
/// expense's split information and affecting balance calculations.
|
||||||
/// This helps track who has settled their portion of shared expenses.
|
/// This helps track who has settled their portion of shared expenses.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [event]: The MarkSplitAsPaid event containing expense ID and user ID
|
/// [event]: The MarkSplitAsPaid event containing expense ID and user ID
|
||||||
/// [emit]: State emitter function
|
/// [emit]: State emitter function
|
||||||
@@ -179,11 +189,11 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [ArchiveExpense] events.
|
/// Handles [ArchiveExpense] events.
|
||||||
///
|
///
|
||||||
/// Archives an expense, moving it out of the active expense list
|
/// Archives an expense, moving it out of the active expense list
|
||||||
/// while preserving it for historical records and audit purposes.
|
/// while preserving it for historical records and audit purposes.
|
||||||
/// Archived expenses are not included in current balance calculations.
|
/// Archived expenses are not included in current balance calculations.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [event]: The ArchiveExpense event containing the expense ID to archive
|
/// [event]: The ArchiveExpense event containing the expense ID to archive
|
||||||
/// [emit]: State emitter function
|
/// [emit]: State emitter function
|
||||||
@@ -201,7 +211,7 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Cleans up resources when the bloc is closed.
|
/// Cleans up resources when the bloc is closed.
|
||||||
///
|
///
|
||||||
/// Cancels the expense stream subscription to prevent memory leaks
|
/// Cancels the expense stream subscription to prevent memory leaks
|
||||||
/// and ensure proper disposal of resources.
|
/// and ensure proper disposal of resources.
|
||||||
@override
|
@override
|
||||||
@@ -209,4 +219,4 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
_expensesSubscription?.cancel();
|
_expensesSubscription?.cancel();
|
||||||
return super.close();
|
return super.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ import '../../blocs/account/account_state.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:travel_mate/components/error/error_content.dart';
|
import 'package:travel_mate/components/error/error_content.dart';
|
||||||
import '../../blocs/user/user_state.dart' as user_state;
|
import '../../blocs/user/user_state.dart' as user_state;
|
||||||
import '../../repositories/group_repository.dart'; // Ajouter cet import
|
import '../../repositories/group_repository.dart';
|
||||||
import 'group_expenses_page.dart'; // Ajouter cet import
|
import '../widgets/user_state_widget.dart';
|
||||||
|
import 'group_expenses_page.dart';
|
||||||
|
|
||||||
/// Widget that displays the account content page with account management functionality.
|
/// Widget that displays the account content page with account management functionality.
|
||||||
class AccountContent extends StatefulWidget {
|
class AccountContent extends StatefulWidget {
|
||||||
@@ -132,33 +133,13 @@ class _AccountContentState extends State<AccountContent> {
|
|||||||
/// Widget representing the complete account page UI
|
/// Widget representing the complete account page UI
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<UserBloc, user_state.UserState>(
|
return UserStateWrapper(
|
||||||
builder: (context, userState) {
|
builder: (context, user) {
|
||||||
if (userState is user_state.UserLoading) {
|
|
||||||
return const Scaffold(
|
|
||||||
body: Center(child: CircularProgressIndicator()),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userState is user_state.UserError) {
|
|
||||||
return ErrorContent(
|
|
||||||
message: 'User error: ${userState.message}',
|
|
||||||
onRetry: () {},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userState is! user_state.UserLoaded) {
|
|
||||||
return const Scaffold(
|
|
||||||
body: Center(child: Text('User not connected')),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final user = userState.user;
|
|
||||||
|
|
||||||
return BlocConsumer<AccountBloc, AccountState>(
|
return BlocConsumer<AccountBloc, AccountState>(
|
||||||
listener: (context, accountState) {
|
listener: (context, accountState) {
|
||||||
if (accountState is AccountError) {
|
if (accountState is AccountError) {
|
||||||
ErrorContent(
|
ErrorContent(
|
||||||
message: 'Account loading error: ${accountState.message}',
|
message: 'Erreur de chargement des comptes : ${accountState.message}',
|
||||||
onRetry: () {
|
onRetry: () {
|
||||||
context.read<AccountBloc>().add(LoadAccountsByUserId(user.id));
|
context.read<AccountBloc>().add(LoadAccountsByUserId(user.id));
|
||||||
},
|
},
|
||||||
@@ -167,11 +148,21 @@ class _AccountContentState extends State<AccountContent> {
|
|||||||
},
|
},
|
||||||
builder: (context, accountState) {
|
builder: (context, accountState) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: SafeArea(child: _buildContent(accountState, user.id))
|
body: SafeArea(child: _buildContent(accountState, user.id)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
loadingWidget: const Scaffold(
|
||||||
|
body: Center(child: CircularProgressIndicator()),
|
||||||
|
),
|
||||||
|
errorWidget: ErrorContent(
|
||||||
|
message: 'User error',
|
||||||
|
onRetry: () {},
|
||||||
|
),
|
||||||
|
noUserWidget: const Scaffold(
|
||||||
|
body: Center(child: Text('Utilisateur non connecté')),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +187,7 @@ class _AccountContentState extends State<AccountContent> {
|
|||||||
children: [
|
children: [
|
||||||
CircularProgressIndicator(),
|
CircularProgressIndicator(),
|
||||||
SizedBox(height: 16),
|
SizedBox(height: 16),
|
||||||
Text('Loading accounts...'),
|
Text('Chargement des comptes...'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -204,7 +195,7 @@ class _AccountContentState extends State<AccountContent> {
|
|||||||
|
|
||||||
if (accountState is AccountError) {
|
if (accountState is AccountError) {
|
||||||
return ErrorContent(
|
return ErrorContent(
|
||||||
message: 'Account loading error...',
|
message: 'Erreur de chargement des comptes...',
|
||||||
onRetry: () {
|
onRetry: () {
|
||||||
context.read<AccountBloc>().add(LoadAccountsByUserId(userId));
|
context.read<AccountBloc>().add(LoadAccountsByUserId(userId));
|
||||||
},
|
},
|
||||||
@@ -222,13 +213,13 @@ class _AccountContentState extends State<AccountContent> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
const Text('Unknown state'),
|
const Text('État inconnu'),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
context.read<AccountBloc>().add(LoadAccountsByUserId(userId));
|
context.read<AccountBloc>().add(LoadAccountsByUserId(userId));
|
||||||
},
|
},
|
||||||
child: const Text('Load accounts'),
|
child: const Text('Charger les comptes'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -258,7 +249,7 @@ class _AccountContentState extends State<AccountContent> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
const Text(
|
const Text(
|
||||||
'Accounts are automatically created when you create a trip',
|
'Les comptes sont créés automatiquement lorsque vous créez des voyages.',
|
||||||
style: TextStyle(fontSize: 14, color: Colors.grey),
|
style: TextStyle(fontSize: 14, color: Colors.grey),
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
@@ -289,18 +280,7 @@ class _AccountContentState extends State<AccountContent> {
|
|||||||
child: ListView(
|
child: ListView(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
children: [
|
children: [
|
||||||
const Text(
|
...accounts.map((account) {
|
||||||
'My accounts',
|
|
||||||
style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Text(
|
|
||||||
'Manage your travel accounts',
|
|
||||||
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
|
|
||||||
...accounts.map((account) {
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 12),
|
padding: const EdgeInsets.only(bottom: 12),
|
||||||
child: _buildSimpleAccountCard(account),
|
child: _buildSimpleAccountCard(account),
|
||||||
|
|||||||
@@ -56,6 +56,7 @@
|
|||||||
/// - Group
|
/// - Group
|
||||||
/// - ExpenseBloc
|
/// - ExpenseBloc
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
@@ -76,8 +77,10 @@ import '../../models/expense.dart';
|
|||||||
class AddExpenseDialog extends StatefulWidget {
|
class AddExpenseDialog extends StatefulWidget {
|
||||||
/// The group to which the expense belongs.
|
/// The group to which the expense belongs.
|
||||||
final Group group;
|
final Group group;
|
||||||
|
|
||||||
/// The user creating or editing the expense.
|
/// The user creating or editing the expense.
|
||||||
final user_state.UserModel currentUser;
|
final user_state.UserModel currentUser;
|
||||||
|
|
||||||
/// The expense to edit (null for new expense).
|
/// The expense to edit (null for new expense).
|
||||||
final Expense? expenseToEdit;
|
final Expense? expenseToEdit;
|
||||||
|
|
||||||
@@ -103,27 +106,40 @@ class AddExpenseDialog extends StatefulWidget {
|
|||||||
class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
||||||
/// Form key for validating the expense form.
|
/// Form key for validating the expense form.
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
/// Controller for the expense description field.
|
/// Controller for the expense description field.
|
||||||
final _descriptionController = TextEditingController();
|
final _descriptionController = TextEditingController();
|
||||||
|
|
||||||
/// Controller for the expense amount field.
|
/// Controller for the expense amount field.
|
||||||
final _amountController = TextEditingController();
|
final _amountController = TextEditingController();
|
||||||
|
|
||||||
/// The selected date for the expense.
|
/// The selected date for the expense.
|
||||||
late DateTime _selectedDate;
|
late DateTime _selectedDate;
|
||||||
|
|
||||||
/// The selected category for the expense.
|
/// The selected category for the expense.
|
||||||
late ExpenseCategory _selectedCategory;
|
late ExpenseCategory _selectedCategory;
|
||||||
|
|
||||||
/// The selected currency for the expense.
|
/// The selected currency for the expense.
|
||||||
late ExpenseCurrency _selectedCurrency;
|
late ExpenseCurrency _selectedCurrency;
|
||||||
|
|
||||||
/// The user ID of the payer.
|
/// The user ID of the payer.
|
||||||
late String _paidById;
|
late String _paidById;
|
||||||
|
|
||||||
/// Map of userId to split amount for each participant.
|
/// Map of userId to split amount for each participant.
|
||||||
final Map<String, double> _splits = {};
|
final Map<String, double> _splits = {};
|
||||||
|
|
||||||
/// The selected receipt image file, if any.
|
/// The selected receipt image file, if any.
|
||||||
File? _receiptImage;
|
File? _receiptImage;
|
||||||
|
|
||||||
/// Whether the dialog is currently submitting data.
|
/// Whether the dialog is currently submitting data.
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
|
|
||||||
/// Whether the expense is split equally among participants.
|
/// Whether the expense is split equally among participants.
|
||||||
bool _splitEqually = true;
|
bool _splitEqually = true;
|
||||||
|
|
||||||
|
/// Whether the existing receipt has been removed.
|
||||||
|
bool _receiptRemoved = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -172,7 +188,7 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
|||||||
if (pickedFile != null) {
|
if (pickedFile != null) {
|
||||||
final file = File(pickedFile.path);
|
final file = File(pickedFile.path);
|
||||||
final fileSize = await file.length();
|
final fileSize = await file.length();
|
||||||
|
|
||||||
if (fileSize > 5 * 1024 * 1024) {
|
if (fileSize > 5 * 1024 * 1024) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
@@ -199,11 +215,11 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
|||||||
|
|
||||||
final amount = double.tryParse(_amountController.text) ?? 0;
|
final amount = double.tryParse(_amountController.text) ?? 0;
|
||||||
final selectedMembers = _splits.entries.where((e) => e.value >= 0).toList();
|
final selectedMembers = _splits.entries.where((e) => e.value >= 0).toList();
|
||||||
|
|
||||||
if (selectedMembers.isEmpty) return;
|
if (selectedMembers.isEmpty) return;
|
||||||
|
|
||||||
final splitAmount = amount / selectedMembers.length;
|
final splitAmount = amount / selectedMembers.length;
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
for (final entry in selectedMembers) {
|
for (final entry in selectedMembers) {
|
||||||
_splits[entry.key] = splitAmount;
|
_splits[entry.key] = splitAmount;
|
||||||
@@ -221,17 +237,14 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
|||||||
if (!_formKey.currentState!.validate()) return;
|
if (!_formKey.currentState!.validate()) return;
|
||||||
|
|
||||||
final amount = double.parse(_amountController.text);
|
final amount = double.parse(_amountController.text);
|
||||||
final selectedSplits = _splits.entries
|
final selectedSplits = _splits.entries.where((e) => e.value > 0).map((e) {
|
||||||
.where((e) => e.value > 0)
|
final member = widget.group.members.firstWhere((m) => m.userId == e.key);
|
||||||
.map((e) {
|
return ExpenseSplit(
|
||||||
final member = widget.group.members.firstWhere((m) => m.userId == e.key);
|
userId: e.key,
|
||||||
return ExpenseSplit(
|
userName: member.firstName,
|
||||||
userId: e.key,
|
amount: e.value,
|
||||||
userName: member.firstName,
|
);
|
||||||
amount: e.value,
|
}).toList();
|
||||||
);
|
|
||||||
})
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
if (selectedSplits.isEmpty) {
|
if (selectedSplits.isEmpty) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
@@ -248,11 +261,15 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
|||||||
try {
|
try {
|
||||||
// Convertir en EUR
|
// Convertir en EUR
|
||||||
final amountInEur = context.read<ExpenseBloc>().state is ExpensesLoaded
|
final amountInEur = context.read<ExpenseBloc>().state is ExpensesLoaded
|
||||||
? (context.read<ExpenseBloc>().state as ExpensesLoaded)
|
? ((context.read<ExpenseBloc>().state as ExpensesLoaded)
|
||||||
.exchangeRates[_selectedCurrency]! * amount
|
.exchangeRates[_selectedCurrency.code] ??
|
||||||
|
1.0) *
|
||||||
|
amount
|
||||||
: 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(
|
final expense = Expense(
|
||||||
id: widget.expenseToEdit?.id ?? '',
|
id: widget.expenseToEdit?.id ?? '',
|
||||||
@@ -266,29 +283,29 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
|||||||
paidByName: payer.firstName,
|
paidByName: payer.firstName,
|
||||||
splits: selectedSplits,
|
splits: selectedSplits,
|
||||||
date: _selectedDate,
|
date: _selectedDate,
|
||||||
receiptUrl: widget.expenseToEdit?.receiptUrl,
|
receiptUrl: _receiptRemoved ? null : widget.expenseToEdit?.receiptUrl,
|
||||||
createdAt: widget.expenseToEdit?.createdAt ?? DateTime.now(),
|
createdAt: widget.expenseToEdit?.createdAt ?? DateTime.now(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (widget.expenseToEdit == null) {
|
if (widget.expenseToEdit == null) {
|
||||||
context.read<ExpenseBloc>().add(CreateExpense(
|
context.read<ExpenseBloc>().add(
|
||||||
expense: expense,
|
CreateExpense(expense: expense, receiptImage: _receiptImage),
|
||||||
receiptImage: _receiptImage,
|
);
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
context.read<ExpenseBloc>().add(UpdateExpense(
|
context.read<ExpenseBloc>().add(
|
||||||
expense: expense,
|
UpdateExpense(expense: expense, newReceiptImage: _receiptImage),
|
||||||
newReceiptImage: _receiptImage,
|
);
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(widget.expenseToEdit == null
|
content: Text(
|
||||||
? 'Dépense ajoutée'
|
widget.expenseToEdit == null
|
||||||
: 'Dépense modifiée'),
|
? 'Dépense ajoutée'
|
||||||
|
: 'Dépense modifiée',
|
||||||
|
),
|
||||||
backgroundColor: Colors.green,
|
backgroundColor: Colors.green,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -296,10 +313,7 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(content: Text('Erreur: $e'), backgroundColor: Colors.red),
|
||||||
content: Text('Erreur: $e'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -314,284 +328,425 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
|||||||
/// Returns a Dialog widget containing the expense form.
|
/// Returns a Dialog widget containing the expense form.
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final isDark = theme.brightness == Brightness.dark;
|
||||||
|
|
||||||
return Dialog(
|
return Dialog(
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
|
backgroundColor: isDark ? theme.scaffoldBackgroundColor : Colors.white,
|
||||||
|
insetPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
|
||||||
child: Container(
|
child: Container(
|
||||||
constraints: const BoxConstraints(maxWidth: 600, maxHeight: 700),
|
constraints: const BoxConstraints(maxWidth: 500, maxHeight: 800),
|
||||||
child: Scaffold(
|
child: Column(
|
||||||
appBar: AppBar(
|
children: [
|
||||||
title: Text(widget.expenseToEdit == null
|
// Header
|
||||||
? 'Nouvelle dépense'
|
Padding(
|
||||||
: 'Modifier la dépense'),
|
padding: const EdgeInsets.fromLTRB(24, 24, 16, 16),
|
||||||
automaticallyImplyLeading: false,
|
child: Row(
|
||||||
actions: [
|
children: [
|
||||||
IconButton(
|
Expanded(
|
||||||
icon: const Icon(Icons.close),
|
child: Text(
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
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(),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
const Divider(height: 1),
|
||||||
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),
|
|
||||||
|
|
||||||
// Montant et devise
|
// Form Content
|
||||||
Row(
|
Expanded(
|
||||||
|
child: Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: ListView(
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
// Description
|
||||||
flex: 2,
|
TextFormField(
|
||||||
child: TextFormField(
|
controller: _descriptionController,
|
||||||
controller: _amountController,
|
decoration: InputDecoration(
|
||||||
decoration: const InputDecoration(
|
labelText: 'Description',
|
||||||
labelText: 'Montant',
|
hintText: 'Ex: Restaurant, Essence...',
|
||||||
border: OutlineInputBorder(),
|
prefixIcon: const Icon(Icons.description_outlined),
|
||||||
prefixIcon: Icon(Icons.euro),
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
contentPadding: const EdgeInsets.symmetric(
|
||||||
onChanged: (_) => _calculateSplits(),
|
horizontal: 16,
|
||||||
validator: (value) {
|
vertical: 16,
|
||||||
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(),
|
|
||||||
),
|
),
|
||||||
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
|
// Montant et Devise
|
||||||
DropdownButtonFormField<ExpenseCategory>(
|
Row(
|
||||||
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(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Expanded(
|
||||||
children: [
|
flex: 2,
|
||||||
const Text(
|
child: TextFormField(
|
||||||
'Division',
|
controller: _amountController,
|
||||||
style: TextStyle(
|
decoration: InputDecoration(
|
||||||
fontSize: 16,
|
labelText: 'Montant',
|
||||||
fontWeight: FontWeight.bold,
|
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(),
|
const Spacer(),
|
||||||
Text(_splitEqually ? 'Égale' : 'Personnalisée'),
|
IconButton(
|
||||||
Switch(
|
icon: const Icon(Icons.close),
|
||||||
value: _splitEqually,
|
onPressed: () => setState(() {
|
||||||
onChanged: (value) {
|
_receiptImage = null;
|
||||||
setState(() {
|
_receiptRemoved = true;
|
||||||
_splitEqually = value;
|
}),
|
||||||
if (value) _calculateSplits();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const Divider(),
|
)
|
||||||
...widget.group.members.map((member) {
|
else
|
||||||
final isSelected = _splits.containsKey(member.userId) &&
|
OutlinedButton.icon(
|
||||||
_splits[member.userId]! >= 0;
|
onPressed: _pickImage,
|
||||||
|
icon: const Icon(Icons.camera_alt_outlined),
|
||||||
return CheckboxListTile(
|
label: const Text('Ajouter un reçu'),
|
||||||
title: Text(member.firstName),
|
style: OutlinedButton.styleFrom(
|
||||||
subtitle: _splitEqually || !isSelected
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||||
? null
|
shape: RoundedRectangleBorder(
|
||||||
: TextFormField(
|
borderRadius: BorderRadius.circular(8),
|
||||||
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'),
|
|
||||||
),
|
),
|
||||||
),
|
|
||||||
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 {
|
class ExpensesTab extends StatelessWidget {
|
||||||
final List<Expense> expenses;
|
final List<Expense> expenses;
|
||||||
final Group group;
|
final Group group;
|
||||||
|
final String currentUserId;
|
||||||
|
|
||||||
const ExpensesTab({
|
const ExpensesTab({
|
||||||
super.key,
|
super.key,
|
||||||
required this.expenses,
|
required this.expenses,
|
||||||
required this.group,
|
required this.group,
|
||||||
|
required this.currentUserId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -48,95 +50,157 @@ class ExpensesTab extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildExpenseCard(BuildContext context, Expense expense) {
|
Widget _buildExpenseCard(BuildContext context, Expense expense) {
|
||||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
final theme = Theme.of(context);
|
||||||
final dateFormat = DateFormat('dd/MM/yyyy');
|
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),
|
margin: const EdgeInsets.only(bottom: 12),
|
||||||
child: InkWell(
|
decoration: BoxDecoration(
|
||||||
onTap: () => _showExpenseDetail(context, expense),
|
color: isDark ? theme.cardColor : Colors.white,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(16),
|
||||||
child: Padding(
|
boxShadow: [
|
||||||
padding: const EdgeInsets.all(16),
|
BoxShadow(
|
||||||
child: Row(
|
color: Colors.black.withValues(alpha: 0.05),
|
||||||
children: [
|
blurRadius: 8,
|
||||||
Container(
|
offset: const Offset(0, 2),
|
||||||
width: 48,
|
),
|
||||||
height: 48,
|
],
|
||||||
decoration: BoxDecoration(
|
),
|
||||||
color: isDark ? Colors.blue[900] : Colors.blue[100],
|
child: Material(
|
||||||
borderRadius: BorderRadius.circular(12),
|
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(
|
const SizedBox(width: 16),
|
||||||
expense.category.icon,
|
|
||||||
color: Colors.blue,
|
// 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),
|
// Montant
|
||||||
Expanded(
|
Column(
|
||||||
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
expense.description,
|
'$prefix${amountToDisplay.toStringAsFixed(2)} ${expense.currency.symbol}',
|
||||||
style: const TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
|
color: amountColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
if (expense.currency != ExpenseCurrency.eur)
|
||||||
Text(
|
Text(
|
||||||
'Payé par ${expense.paidByName}',
|
'Total ${expense.amountInEur.toStringAsFixed(2)} €',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 11,
|
||||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
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) {
|
void _showExpenseDetail(BuildContext context, Expense expense) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => ExpenseDetailDialog(
|
builder: (context) => ExpenseDetailDialog(expense: expense, group: group),
|
||||||
expense: expense,
|
|
||||||
group: group,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ import '../../models/group.dart';
|
|||||||
import 'add_expense_dialog.dart';
|
import 'add_expense_dialog.dart';
|
||||||
import 'balances_tab.dart';
|
import 'balances_tab.dart';
|
||||||
import 'expenses_tab.dart';
|
import 'expenses_tab.dart';
|
||||||
import 'settlements_tab.dart';
|
import '../../models/user_balance.dart';
|
||||||
|
import '../../models/expense.dart';
|
||||||
|
|
||||||
class GroupExpensesPage extends StatefulWidget {
|
class GroupExpensesPage extends StatefulWidget {
|
||||||
final Account account;
|
final Account account;
|
||||||
@@ -31,13 +32,14 @@ class GroupExpensesPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _GroupExpensesPageState extends State<GroupExpensesPage>
|
class _GroupExpensesPageState extends State<GroupExpensesPage>
|
||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
|
|
||||||
late TabController _tabController;
|
late TabController _tabController;
|
||||||
|
ExpenseCategory? _selectedCategory;
|
||||||
|
String? _selectedPayerId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_tabController = TabController(length: 3, vsync: this);
|
_tabController = TabController(length: 2, vsync: this);
|
||||||
_loadData();
|
_loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,39 +52,41 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
|||||||
void _loadData() {
|
void _loadData() {
|
||||||
// Charger les dépenses du groupe
|
// Charger les dépenses du groupe
|
||||||
context.read<ExpenseBloc>().add(LoadExpensesByGroup(widget.group.id));
|
context.read<ExpenseBloc>().add(LoadExpensesByGroup(widget.group.id));
|
||||||
|
|
||||||
// Charger les balances du groupe
|
// Charger les balances du groupe
|
||||||
context.read<BalanceBloc>().add(LoadGroupBalances(widget.group.id));
|
context.read<BalanceBloc>().add(LoadGroupBalances(widget.group.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final isDarkMode = theme.brightness == Brightness.dark;
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
backgroundColor: isDarkMode
|
||||||
|
? theme.scaffoldBackgroundColor
|
||||||
|
: Colors.grey[50],
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(widget.account.name),
|
title: const Text(
|
||||||
backgroundColor: Theme.of(context).primaryColor,
|
'Dépenses du voyage',
|
||||||
foregroundColor: Colors.white,
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
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',
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
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(
|
body: MultiBlocListener(
|
||||||
listeners: [
|
listeners: [
|
||||||
@@ -103,56 +107,107 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
|||||||
backgroundColor: Colors.red,
|
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(
|
child: Column(
|
||||||
controller: _tabController,
|
|
||||||
children: [
|
children: [
|
||||||
// Onglet Balances
|
// Summary Card
|
||||||
BlocBuilder<BalanceBloc, BalanceState>(
|
BlocBuilder<BalanceBloc, BalanceState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is BalanceLoading) {
|
if (state is GroupBalancesLoaded) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return _buildSummaryCard(state.balances, isDarkMode);
|
||||||
} 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}');
|
|
||||||
}
|
}
|
||||||
return _buildEmptyState('Aucune balance disponible');
|
return const SizedBox.shrink();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
// Onglet Dépenses
|
// Tabs
|
||||||
BlocBuilder<ExpenseBloc, ExpenseState>(
|
Container(
|
||||||
builder: (context, state) {
|
decoration: BoxDecoration(
|
||||||
if (state is ExpenseLoading) {
|
border: Border(
|
||||||
return const Center(child: CircularProgressIndicator());
|
bottom: BorderSide(color: theme.dividerColor, width: 1),
|
||||||
} else if (state is ExpensesLoaded) {
|
),
|
||||||
return ExpensesTab(
|
),
|
||||||
expenses: state.expenses,
|
child: TabBar(
|
||||||
group: widget.group,
|
controller: _tabController,
|
||||||
);
|
labelColor: theme.colorScheme.primary,
|
||||||
} else if (state is ExpenseError) {
|
unselectedLabelColor: theme.colorScheme.onSurface.withValues(
|
||||||
return _buildErrorState('Erreur lors du chargement des dépenses: ${state.message}');
|
alpha: 0.6,
|
||||||
}
|
),
|
||||||
return _buildEmptyState('Aucune dépense trouvée');
|
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
|
// Tab View
|
||||||
BlocBuilder<BalanceBloc, BalanceState>(
|
Expanded(
|
||||||
builder: (context, state) {
|
child: TabBarView(
|
||||||
if (state is BalanceLoading) {
|
controller: _tabController,
|
||||||
return const Center(child: CircularProgressIndicator());
|
children: [
|
||||||
} else if (state is GroupBalancesLoaded) {
|
// Onglet Dépenses
|
||||||
return SettlementsTab(settlements: state.settlements);
|
BlocBuilder<ExpenseBloc, ExpenseState>(
|
||||||
} else if (state is BalanceError) {
|
builder: (context, state) {
|
||||||
return _buildErrorState('Erreur lors du chargement des règlements: ${state.message}');
|
if (state is ExpenseLoading) {
|
||||||
}
|
return const Center(child: CircularProgressIndicator());
|
||||||
return _buildEmptyState('Aucun règlement nécessaire');
|
} 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(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: _showAddExpenseDialog,
|
onPressed: _showAddExpenseDialog,
|
||||||
heroTag: "add_expense_fab",
|
heroTag: "add_expense_fab",
|
||||||
|
backgroundColor: Colors.blue,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
elevation: 4,
|
||||||
|
shape: const CircleBorder(),
|
||||||
tooltip: 'Ajouter une dépense',
|
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(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(Icons.error_outline, size: 80, color: Colors.red[300]),
|
||||||
Icons.error_outline,
|
|
||||||
size: 80,
|
|
||||||
color: Colors.red[300],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Text(
|
Text(
|
||||||
'Erreur',
|
'Erreur',
|
||||||
@@ -190,10 +342,7 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
|||||||
padding: const EdgeInsets.symmetric(horizontal: 32),
|
padding: const EdgeInsets.symmetric(horizontal: 32),
|
||||||
child: Text(
|
child: Text(
|
||||||
message,
|
message,
|
||||||
style: TextStyle(
|
style: TextStyle(fontSize: 16, color: Colors.grey[600]),
|
||||||
fontSize: 16,
|
|
||||||
color: Colors.grey[600],
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -213,11 +362,7 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(Icons.info_outline, size: 80, color: Colors.grey[400]),
|
||||||
Icons.info_outline,
|
|
||||||
size: 80,
|
|
||||||
color: Colors.grey[400],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Text(
|
Text(
|
||||||
'Aucune donnée',
|
'Aucune donnée',
|
||||||
@@ -230,10 +375,7 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
|||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
message,
|
message,
|
||||||
style: TextStyle(
|
style: TextStyle(fontSize: 16, color: Colors.grey[500]),
|
||||||
fontSize: 16,
|
|
||||||
color: Colors.grey[500],
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -243,14 +385,12 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
|||||||
|
|
||||||
void _showAddExpenseDialog() {
|
void _showAddExpenseDialog() {
|
||||||
final userState = context.read<UserBloc>().state;
|
final userState = context.read<UserBloc>().state;
|
||||||
|
|
||||||
if (userState is user_state.UserLoaded) {
|
if (userState is user_state.UserLoaded) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AddExpenseDialog(
|
builder: (context) =>
|
||||||
group: widget.group,
|
AddExpenseDialog(group: widget.group, currentUser: userState.user),
|
||||||
currentUser: userState.user,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
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'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ import '../../blocs/activity/activity_state.dart';
|
|||||||
import '../../models/trip.dart';
|
import '../../models/trip.dart';
|
||||||
import '../../models/activity.dart';
|
import '../../models/activity.dart';
|
||||||
import '../../services/activity_cache_service.dart';
|
import '../../services/activity_cache_service.dart';
|
||||||
import '../activities/add_activity_bottom_sheet.dart';
|
|
||||||
import '../loading/laoding_content.dart';
|
import '../loading/laoding_content.dart';
|
||||||
|
import '../../blocs/user/user_bloc.dart';
|
||||||
|
import '../../blocs/user/user_state.dart';
|
||||||
|
|
||||||
class ActivitiesPage extends StatefulWidget {
|
class ActivitiesPage extends StatefulWidget {
|
||||||
final Trip trip;
|
final Trip trip;
|
||||||
@@ -23,9 +25,6 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
late TabController _tabController;
|
late TabController _tabController;
|
||||||
final TextEditingController _searchController = TextEditingController();
|
final TextEditingController _searchController = TextEditingController();
|
||||||
final ActivityCacheService _cacheService = ActivityCacheService();
|
final ActivityCacheService _cacheService = ActivityCacheService();
|
||||||
String _selectedCategory = 'Toutes les catégories';
|
|
||||||
String _selectedPrice = 'Prix';
|
|
||||||
String _selectedRating = 'Note';
|
|
||||||
|
|
||||||
// Cache pour éviter de recharger les données
|
// Cache pour éviter de recharger les données
|
||||||
bool _activitiesLoaded = false;
|
bool _activitiesLoaded = false;
|
||||||
@@ -35,8 +34,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
List<Activity> _tripActivities = [];
|
List<Activity> _tripActivities = [];
|
||||||
List<Activity> _approvedActivities = [];
|
List<Activity> _approvedActivities = [];
|
||||||
bool _isLoadingTripActivities = false;
|
bool _isLoadingTripActivities = false;
|
||||||
int _totalGoogleActivitiesRequested =
|
|
||||||
0; // Compteur pour les recherches progressives
|
|
||||||
bool _autoReloadInProgress =
|
bool _autoReloadInProgress =
|
||||||
false; // Protection contre les rechargements en boucle
|
false; // Protection contre les rechargements en boucle
|
||||||
int _lastAutoReloadTriggerCount =
|
int _lastAutoReloadTriggerCount =
|
||||||
@@ -83,7 +81,9 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
// Si on va sur l'onglet suggestions Google et qu'aucune recherche n'a été faite
|
// Si on va sur l'onglet suggestions Google et qu'aucune recherche n'a été faite
|
||||||
if (_tabController.index == 2 && !_googleSearchPerformed) {
|
if (_tabController.index == 2 && !_googleSearchPerformed) {
|
||||||
// Vérifier si on a des activités en cache
|
// Vérifier si on a des activités en cache
|
||||||
final cachedActivities = _cacheService.getCachedActivities(widget.trip.id!);
|
final cachedActivities = _cacheService.getCachedActivities(
|
||||||
|
widget.trip.id!,
|
||||||
|
);
|
||||||
if (cachedActivities != null && cachedActivities.isNotEmpty) {
|
if (cachedActivities != null && cachedActivities.isNotEmpty) {
|
||||||
// Restaurer les activités en cache dans le BLoC
|
// Restaurer les activités en cache dans le BLoC
|
||||||
context.read<ActivityBloc>().add(
|
context.read<ActivityBloc>().add(
|
||||||
@@ -144,13 +144,13 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
if (Navigator.of(context).canPop()) {
|
if (Navigator.of(context).canPop()) {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajouter l'activité à la liste locale des activités du voyage
|
// Ajouter l'activité à la liste locale des activités du voyage
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_tripActivities.add(state.activity);
|
_tripActivities.add(state.activity);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Afficher un feedback de succès
|
// Afficher un feedback de succès
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
@@ -174,10 +174,26 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
// Stocker les activités localement
|
// Stocker les activités localement
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_tripActivities = state.activities;
|
final allActivities = state.filteredActivities;
|
||||||
_approvedActivities = state.activities
|
|
||||||
.where((a) => a.totalVotes > 0)
|
_approvedActivities = allActivities
|
||||||
|
.where(
|
||||||
|
(a) => a.isApprovedByAllParticipants([
|
||||||
|
...widget.trip.participants,
|
||||||
|
widget.trip.createdBy,
|
||||||
|
]),
|
||||||
|
)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
_tripActivities = allActivities
|
||||||
|
.where(
|
||||||
|
(a) => !a.isApprovedByAllParticipants([
|
||||||
|
...widget.trip.participants,
|
||||||
|
widget.trip.createdBy,
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
|
||||||
_isLoadingTripActivities = false;
|
_isLoadingTripActivities = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -189,6 +205,37 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (state is ActivitySearchResults) {
|
if (state is ActivitySearchResults) {
|
||||||
|
// Gérer l'ajout d'activité depuis les résultats de recherche
|
||||||
|
if (state.newlyAddedActivity != null) {
|
||||||
|
// Fermer le dialog de loading s'il est ouvert
|
||||||
|
if (Navigator.of(context).canPop()) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
setState(() {
|
||||||
|
_tripActivities.add(state.newlyAddedActivity!);
|
||||||
|
});
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
'${state.newlyAddedActivity!.name} ajoutée au voyage !',
|
||||||
|
),
|
||||||
|
duration: const Duration(seconds: 2),
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
action: SnackBarAction(
|
||||||
|
label: 'Voir',
|
||||||
|
textColor: Colors.white,
|
||||||
|
onPressed: () {
|
||||||
|
_tabController.animateTo(0);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Déclencher l'auto-reload uniquement pour la recherche initiale (6 résultats)
|
// Déclencher l'auto-reload uniquement pour la recherche initiale (6 résultats)
|
||||||
// et pas pour les rechargements automatiques
|
// et pas pour les rechargements automatiques
|
||||||
if (state.searchResults.length <= 6 && !_autoReloadInProgress) {
|
if (state.searchResults.length <= 6 && !_autoReloadInProgress) {
|
||||||
@@ -220,21 +267,13 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
backgroundColor: theme.colorScheme.surface,
|
backgroundColor: theme.colorScheme.surface,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
foregroundColor: theme.colorScheme.onSurface,
|
foregroundColor: theme.colorScheme.onSurface,
|
||||||
actions: [
|
actions: [],
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.add),
|
|
||||||
onPressed: _showAddActivityBottomSheet,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
// Barre de recherche
|
// Barre de recherche
|
||||||
_buildSearchBar(theme),
|
_buildSearchBar(theme),
|
||||||
|
|
||||||
// Filtres
|
|
||||||
_buildFilters(theme),
|
|
||||||
|
|
||||||
// Onglets de catégories
|
// Onglets de catégories
|
||||||
_buildCategoryTabs(theme),
|
_buildCategoryTabs(theme),
|
||||||
|
|
||||||
@@ -260,7 +299,9 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: theme.colorScheme.surfaceContainerHighest.withOpacity(0.3),
|
color: theme.colorScheme.surfaceContainerHighest.withValues(
|
||||||
|
alpha: 0.3,
|
||||||
|
),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
child: TextField(
|
child: TextField(
|
||||||
@@ -268,11 +309,11 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: 'Rechercher restaurants, musées...',
|
hintText: 'Rechercher restaurants, musées...',
|
||||||
hintStyle: TextStyle(
|
hintStyle: TextStyle(
|
||||||
color: theme.colorScheme.onSurface.withOpacity(0.6),
|
color: theme.colorScheme.onSurface.withValues(alpha: 0.6),
|
||||||
),
|
),
|
||||||
prefixIcon: Icon(
|
prefixIcon: Icon(
|
||||||
Icons.search,
|
Icons.search,
|
||||||
color: theme.colorScheme.onSurface.withOpacity(0.6),
|
color: theme.colorScheme.onSurface.withValues(alpha: 0.6),
|
||||||
),
|
),
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
contentPadding: const EdgeInsets.symmetric(
|
contentPadding: const EdgeInsets.symmetric(
|
||||||
@@ -280,95 +321,32 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
vertical: 12,
|
vertical: 12,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onChanged: (value) {
|
onSubmitted: (value) {
|
||||||
// TODO: Implémenter la recherche
|
if (value.isNotEmpty) {
|
||||||
|
_performSearch(value);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildFilters(ThemeData theme) {
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: _buildFilterButton(
|
|
||||||
theme,
|
|
||||||
_selectedCategory,
|
|
||||||
Icons.category,
|
|
||||||
() => _showCategoryFilter(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
_buildFilterButton(
|
|
||||||
theme,
|
|
||||||
_selectedPrice,
|
|
||||||
Icons.euro,
|
|
||||||
() => _showPriceFilter(),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
_buildFilterButton(
|
|
||||||
theme,
|
|
||||||
_selectedRating,
|
|
||||||
Icons.star,
|
|
||||||
() => _showRatingFilter(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildFilterButton(
|
|
||||||
ThemeData theme,
|
|
||||||
String text,
|
|
||||||
IconData icon,
|
|
||||||
VoidCallback onPressed,
|
|
||||||
) {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: onPressed,
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
border: Border.all(color: theme.colorScheme.outline.withOpacity(0.5)),
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
color: theme.colorScheme.surface,
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
size: 16,
|
|
||||||
color: theme.colorScheme.onSurface.withOpacity(0.7),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Text(
|
|
||||||
text,
|
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
|
||||||
color: theme.colorScheme.onSurface.withOpacity(0.7),
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildCategoryTabs(ThemeData theme) {
|
Widget _buildCategoryTabs(ThemeData theme) {
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: theme.colorScheme.surfaceContainerHighest.withOpacity(0.3),
|
color: theme.colorScheme.surfaceContainerHighest.withValues(
|
||||||
|
alpha: 0.3,
|
||||||
|
),
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
child: TabBar(
|
child: TabBar(
|
||||||
controller: _tabController,
|
controller: _tabController,
|
||||||
labelColor: Colors.white,
|
labelColor: Colors.white,
|
||||||
unselectedLabelColor: theme.colorScheme.onSurface.withOpacity(0.7),
|
unselectedLabelColor: theme.colorScheme.onSurface.withValues(
|
||||||
|
alpha: 0.7,
|
||||||
|
),
|
||||||
indicator: BoxDecoration(
|
indicator: BoxDecoration(
|
||||||
color: theme.colorScheme.primary,
|
color: theme.colorScheme.primary,
|
||||||
borderRadius: BorderRadius.circular(6),
|
borderRadius: BorderRadius.circular(6),
|
||||||
@@ -376,246 +354,15 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
indicatorSize: TabBarIndicatorSize.tab,
|
indicatorSize: TabBarIndicatorSize.tab,
|
||||||
dividerColor: Colors.transparent,
|
dividerColor: Colors.transparent,
|
||||||
tabs: const [
|
tabs: const [
|
||||||
Tab(text: 'Activités du voyage'),
|
Tab(text: 'Voyage'),
|
||||||
Tab(text: 'Activités approuvées'),
|
Tab(text: 'Approuvées'),
|
||||||
Tab(text: 'Suggestions Google'),
|
Tab(text: 'Suggestion'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showCategoryFilter() {
|
|
||||||
showModalBottomSheet(
|
|
||||||
context: context,
|
|
||||||
builder: (context) => _buildCategoryFilterSheet(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _showPriceFilter() {
|
|
||||||
showModalBottomSheet(
|
|
||||||
context: context,
|
|
||||||
builder: (context) => _buildPriceFilterSheet(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _showRatingFilter() {
|
|
||||||
showModalBottomSheet(
|
|
||||||
context: context,
|
|
||||||
builder: (context) => _buildRatingFilterSheet(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildCategoryFilterSheet() {
|
|
||||||
final theme = Theme.of(context);
|
|
||||||
final categories = [
|
|
||||||
'Toutes les catégories',
|
|
||||||
...ActivityCategory.values.map((e) => e.displayName),
|
|
||||||
];
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.all(16),
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxHeight:
|
|
||||||
MediaQuery.of(context).size.height * 0.7, // Limite à 70% de l'écran
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'Catégories',
|
|
||||||
style: theme.textTheme.titleMedium?.copyWith(
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Flexible(
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Column(
|
|
||||||
children: categories
|
|
||||||
.map(
|
|
||||||
(category) => ListTile(
|
|
||||||
title: Text(category),
|
|
||||||
onTap: () {
|
|
||||||
setState(() {
|
|
||||||
_selectedCategory = category;
|
|
||||||
});
|
|
||||||
Navigator.pop(context);
|
|
||||||
_applyFilters();
|
|
||||||
},
|
|
||||||
trailing: _selectedCategory == category
|
|
||||||
? Icon(
|
|
||||||
Icons.check,
|
|
||||||
color: theme.colorScheme.primary,
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildPriceFilterSheet() {
|
|
||||||
final theme = Theme.of(context);
|
|
||||||
final prices = [
|
|
||||||
'Prix',
|
|
||||||
'Gratuit',
|
|
||||||
'Bon marché',
|
|
||||||
'Modéré',
|
|
||||||
'Cher',
|
|
||||||
'Très cher',
|
|
||||||
];
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.all(16),
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxHeight: MediaQuery.of(context).size.height * 0.7,
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'Niveau de prix',
|
|
||||||
style: theme.textTheme.titleMedium?.copyWith(
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Flexible(
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Column(
|
|
||||||
children: prices
|
|
||||||
.map(
|
|
||||||
(price) => ListTile(
|
|
||||||
title: Text(price),
|
|
||||||
onTap: () {
|
|
||||||
setState(() {
|
|
||||||
_selectedPrice = price;
|
|
||||||
});
|
|
||||||
Navigator.pop(context);
|
|
||||||
_applyFilters();
|
|
||||||
},
|
|
||||||
trailing: _selectedPrice == price
|
|
||||||
? Icon(
|
|
||||||
Icons.check,
|
|
||||||
color: theme.colorScheme.primary,
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildRatingFilterSheet() {
|
|
||||||
final theme = Theme.of(context);
|
|
||||||
final ratings = [
|
|
||||||
'Note',
|
|
||||||
'4+ étoiles',
|
|
||||||
'3+ étoiles',
|
|
||||||
'2+ étoiles',
|
|
||||||
'1+ étoiles',
|
|
||||||
];
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.all(16),
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxHeight: MediaQuery.of(context).size.height * 0.7,
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'Note minimale',
|
|
||||||
style: theme.textTheme.titleMedium?.copyWith(
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Flexible(
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Column(
|
|
||||||
children: ratings
|
|
||||||
.map(
|
|
||||||
(rating) => ListTile(
|
|
||||||
title: Text(rating),
|
|
||||||
onTap: () {
|
|
||||||
setState(() {
|
|
||||||
_selectedRating = rating;
|
|
||||||
});
|
|
||||||
Navigator.pop(context);
|
|
||||||
_applyFilters();
|
|
||||||
},
|
|
||||||
trailing: _selectedRating == rating
|
|
||||||
? Icon(
|
|
||||||
Icons.check,
|
|
||||||
color: theme.colorScheme.primary,
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _applyFilters() {
|
|
||||||
String? category = _selectedCategory == 'Toutes les catégories'
|
|
||||||
? null
|
|
||||||
: _selectedCategory;
|
|
||||||
double? minRating = _getMinRatingFromString(_selectedRating);
|
|
||||||
|
|
||||||
context.read<ActivityBloc>().add(
|
|
||||||
FilterActivities(category: category, minRating: minRating),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
double? _getMinRatingFromString(String rating) {
|
|
||||||
switch (rating) {
|
|
||||||
case '4+ étoiles':
|
|
||||||
return 4.0;
|
|
||||||
case '3+ étoiles':
|
|
||||||
return 3.0;
|
|
||||||
case '2+ étoiles':
|
|
||||||
return 2.0;
|
|
||||||
case '1+ étoiles':
|
|
||||||
return 1.0;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _showAddActivityBottomSheet() {
|
|
||||||
showModalBottomSheet(
|
|
||||||
context: context,
|
|
||||||
isScrollControlled: true,
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
builder: (context) => Padding(
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
bottom: MediaQuery.of(context).viewInsets.bottom,
|
|
||||||
),
|
|
||||||
child: AddActivityBottomSheet(trip: widget.trip),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildTripActivitiesTab() {
|
Widget _buildTripActivitiesTab() {
|
||||||
// Utiliser les données locales au lieu du BLoC
|
// Utiliser les données locales au lieu du BLoC
|
||||||
if (_isLoadingTripActivities) {
|
if (_isLoadingTripActivities) {
|
||||||
@@ -814,7 +561,9 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
Text(
|
Text(
|
||||||
'Recherche powered by Google Places',
|
'Recherche powered by Google Places',
|
||||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||||
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
|
color: Theme.of(
|
||||||
|
context,
|
||||||
|
).colorScheme.onSurface.withValues(alpha: 0.6),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -845,7 +594,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
Text(
|
Text(
|
||||||
subtitle,
|
subtitle,
|
||||||
style: theme.textTheme.bodyMedium?.copyWith(
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
color: theme.colorScheme.onSurface.withOpacity(0.7),
|
color: theme.colorScheme.onSurface.withValues(alpha: 0.7),
|
||||||
),
|
),
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
@@ -977,7 +726,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: theme.colorScheme.primary.withOpacity(0.1),
|
color: theme.colorScheme.primary.withValues(alpha: 0.1),
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
child: Icon(
|
child: Icon(
|
||||||
@@ -1015,7 +764,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
vertical: 4,
|
vertical: 4,
|
||||||
),
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.amber.withOpacity(0.1),
|
color: Colors.amber.withValues(alpha: 0.1),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -1043,7 +792,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
Text(
|
Text(
|
||||||
activity.description,
|
activity.description,
|
||||||
style: theme.textTheme.bodyMedium?.copyWith(
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
color: theme.colorScheme.onSurface.withOpacity(0.8),
|
color: theme.colorScheme.onSurface.withValues(alpha: 0.8),
|
||||||
),
|
),
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
@@ -1056,14 +805,18 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
Icon(
|
Icon(
|
||||||
Icons.location_on,
|
Icons.location_on,
|
||||||
size: 16,
|
size: 16,
|
||||||
color: theme.colorScheme.onSurface.withOpacity(0.6),
|
color: theme.colorScheme.onSurface.withValues(
|
||||||
|
alpha: 0.6,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
activity.address!,
|
activity.address!,
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
color: theme.colorScheme.onSurface.withOpacity(0.6),
|
color: theme.colorScheme.onSurface.withValues(
|
||||||
|
alpha: 0.6,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -1084,10 +837,10 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
vertical: 8,
|
vertical: 8,
|
||||||
),
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.orange.withOpacity(0.1),
|
color: Colors.orange.withValues(alpha: 0.1),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: Colors.orange.withOpacity(0.3),
|
color: Colors.orange.withValues(alpha: 0.3),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -1140,7 +893,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
vertical: 4,
|
vertical: 4,
|
||||||
),
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.green.withOpacity(0.1),
|
color: Colors.green.withValues(alpha: 0.1),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -1170,7 +923,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
vertical: 4,
|
vertical: 4,
|
||||||
),
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.red.withOpacity(0.1),
|
color: Colors.red.withValues(alpha: 0.1),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -1247,9 +1000,41 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _voteForActivity(String activityId, int vote) {
|
void _voteForActivity(String activityId, int vote) {
|
||||||
// TODO: Récupérer l'ID utilisateur actuel
|
// Récupérer l'ID utilisateur actuel depuis le UserBloc
|
||||||
// Pour l'instant, on utilise un ID temporaire
|
final userState = context.read<UserBloc>().state;
|
||||||
final userId = 'current_user_id';
|
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)
|
||||||
|
final currentActivity = _tripActivities.firstWhere(
|
||||||
|
(a) => a.id == activityId,
|
||||||
|
orElse: () => _approvedActivities.firstWhere(
|
||||||
|
(a) => a.id == activityId,
|
||||||
|
orElse: () => Activity(
|
||||||
|
id: '',
|
||||||
|
tripId: '',
|
||||||
|
name: '',
|
||||||
|
description: '',
|
||||||
|
category: '',
|
||||||
|
createdAt: DateTime.now(),
|
||||||
|
updatedAt: DateTime.now(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Si l'activité a été trouvée et que l'utilisateur a déjà voté
|
||||||
|
if (currentActivity.id.isNotEmpty && currentActivity.hasUserVoted(userId)) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('Vous avez déjà voté pour cette activité'),
|
||||||
|
backgroundColor: Colors.orange,
|
||||||
|
duration: Duration(seconds: 2),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
context.read<ActivityBloc>().add(
|
context.read<ActivityBloc>().add(
|
||||||
VoteForActivity(activityId: activityId, userId: userId, vote: vote),
|
VoteForActivity(activityId: activityId, userId: userId, vote: vote),
|
||||||
@@ -1285,12 +1070,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
loadingText: 'Ajout de ${activity.name}...',
|
loadingText: 'Ajout de ${activity.name}...',
|
||||||
onBackgroundTask: () async {
|
onBackgroundTask: () async {
|
||||||
// Ajouter l'activité au voyage
|
// Ajouter l'activité au voyage
|
||||||
context.read<ActivityBloc>().add(
|
context.read<ActivityBloc>().add(AddActivity(newActivity));
|
||||||
AddActivityAndRemoveFromSearch(
|
|
||||||
activity: newActivity,
|
|
||||||
googleActivityId: activity.id,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// Attendre que l'ajout soit complété
|
// Attendre que l'ajout soit complété
|
||||||
await Future.delayed(const Duration(milliseconds: 1000));
|
await Future.delayed(const Duration(milliseconds: 1000));
|
||||||
},
|
},
|
||||||
@@ -1345,7 +1125,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
6; // Activités actuelles + ce qui manque + buffer de 6
|
6; // Activités actuelles + ce qui manque + buffer de 6
|
||||||
|
|
||||||
// Mettre à jour le compteur et recharger avec le nouveau total
|
// Mettre à jour le compteur et recharger avec le nouveau total
|
||||||
_totalGoogleActivitiesRequested = newTotalToRequest;
|
|
||||||
_loadMoreGoogleActivitiesWithTotal(newTotalToRequest);
|
_loadMoreGoogleActivitiesWithTotal(newTotalToRequest);
|
||||||
|
|
||||||
// Libérer le verrou après un délai
|
// Libérer le verrou après un délai
|
||||||
@@ -1358,7 +1138,6 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _searchGoogleActivities() {
|
void _searchGoogleActivities() {
|
||||||
_totalGoogleActivitiesRequested = 6; // Reset du compteur
|
|
||||||
_autoReloadInProgress = false; // Reset des protections
|
_autoReloadInProgress = false; // Reset des protections
|
||||||
_lastAutoReloadTriggerCount = 0;
|
_lastAutoReloadTriggerCount = 0;
|
||||||
|
|
||||||
@@ -1389,7 +1168,6 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _resetAndSearchGoogleActivities() {
|
void _resetAndSearchGoogleActivities() {
|
||||||
_totalGoogleActivitiesRequested = 6; // Reset du compteur
|
|
||||||
_autoReloadInProgress = false; // Reset des protections
|
_autoReloadInProgress = false; // Reset des protections
|
||||||
_lastAutoReloadTriggerCount = 0;
|
_lastAutoReloadTriggerCount = 0;
|
||||||
|
|
||||||
@@ -1426,8 +1204,6 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
final currentCount = currentState.searchResults.length;
|
final currentCount = currentState.searchResults.length;
|
||||||
final newTotal = currentCount + 6;
|
final newTotal = currentCount + 6;
|
||||||
|
|
||||||
_totalGoogleActivitiesRequested = newTotal;
|
|
||||||
|
|
||||||
// Utiliser les coordonnées pré-géolocalisées du voyage si disponibles
|
// Utiliser les coordonnées pré-géolocalisées du voyage si disponibles
|
||||||
if (widget.trip.hasCoordinates) {
|
if (widget.trip.hasCoordinates) {
|
||||||
context.read<ActivityBloc>().add(
|
context.read<ActivityBloc>().add(
|
||||||
@@ -1514,4 +1290,19 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _performSearch(String query) {
|
||||||
|
// Basculer vers l'onglet suggestions
|
||||||
|
_tabController.animateTo(2);
|
||||||
|
|
||||||
|
// Déclencher la recherche textuelle
|
||||||
|
context.read<ActivityBloc>().add(
|
||||||
|
SearchActivitiesByText(
|
||||||
|
tripId: widget.trip.id!,
|
||||||
|
destination: widget.trip.location,
|
||||||
|
query: query,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
_googleSearchPerformed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
|||||||
height: 4,
|
height: 4,
|
||||||
margin: const EdgeInsets.symmetric(vertical: 12),
|
margin: const EdgeInsets.symmetric(vertical: 12),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: theme.colorScheme.onSurface.withOpacity(0.3),
|
color: theme.colorScheme.onSurface.withValues(alpha: 0.3),
|
||||||
borderRadius: BorderRadius.circular(2),
|
borderRadius: BorderRadius.circular(2),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'dart:async';
|
||||||
import '../../blocs/user/user_bloc.dart';
|
import '../../blocs/user/user_bloc.dart';
|
||||||
import '../../blocs/user/user_state.dart' as user_state;
|
import '../../blocs/user/user_state.dart' as user_state;
|
||||||
import '../../blocs/message/message_bloc.dart';
|
import '../../blocs/message/message_bloc.dart';
|
||||||
import '../../blocs/message/message_event.dart';
|
import '../../blocs/message/message_event.dart';
|
||||||
import '../../blocs/message/message_state.dart';
|
import '../../blocs/message/message_state.dart';
|
||||||
import '../../models/group.dart';
|
import '../../models/group.dart';
|
||||||
|
import '../../models/group_member.dart';
|
||||||
import '../../models/message.dart';
|
import '../../models/message.dart';
|
||||||
|
import '../../repositories/group_repository.dart';
|
||||||
|
|
||||||
/// Chat group content widget for group messaging functionality.
|
/// Chat group content widget for group messaging functionality.
|
||||||
///
|
///
|
||||||
/// This widget provides a complete chat interface for group members to
|
/// This widget provides a complete chat interface for group members to
|
||||||
/// communicate within a travel group. Features include:
|
/// communicate within a travel group. Features include:
|
||||||
/// - Real-time message loading and sending
|
/// - Real-time message loading and sending
|
||||||
@@ -17,7 +20,7 @@ import '../../models/message.dart';
|
|||||||
/// - Message reactions (like/unlike)
|
/// - Message reactions (like/unlike)
|
||||||
/// - Scroll-to-bottom functionality
|
/// - Scroll-to-bottom functionality
|
||||||
/// - Message status indicators
|
/// - Message status indicators
|
||||||
///
|
///
|
||||||
/// The widget integrates with MessageBloc for state management and
|
/// The widget integrates with MessageBloc for state management and
|
||||||
/// handles various message operations through the bloc pattern.
|
/// handles various message operations through the bloc pattern.
|
||||||
class ChatGroupContent extends StatefulWidget {
|
class ChatGroupContent extends StatefulWidget {
|
||||||
@@ -25,13 +28,10 @@ class ChatGroupContent extends StatefulWidget {
|
|||||||
final Group group;
|
final Group group;
|
||||||
|
|
||||||
/// Creates a chat group content widget.
|
/// Creates a chat group content widget.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [group]: The group object containing group details and ID
|
/// [group]: The group object containing group details and ID
|
||||||
const ChatGroupContent({
|
const ChatGroupContent({super.key, required this.group});
|
||||||
super.key,
|
|
||||||
required this.group,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ChatGroupContent> createState() => _ChatGroupContentState();
|
State<ChatGroupContent> createState() => _ChatGroupContentState();
|
||||||
@@ -40,33 +40,52 @@ class ChatGroupContent extends StatefulWidget {
|
|||||||
class _ChatGroupContentState extends State<ChatGroupContent> {
|
class _ChatGroupContentState extends State<ChatGroupContent> {
|
||||||
/// Controller for the message input field
|
/// Controller for the message input field
|
||||||
final _messageController = TextEditingController();
|
final _messageController = TextEditingController();
|
||||||
|
|
||||||
/// Controller for managing scroll position in the message list
|
/// Controller for managing scroll position in the message list
|
||||||
final _scrollController = ScrollController();
|
final _scrollController = ScrollController();
|
||||||
|
|
||||||
/// Currently selected message for editing (null if not editing)
|
/// Currently selected message for editing (null if not editing)
|
||||||
Message? _editingMessage;
|
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;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
// Load messages when the widget initializes
|
// Load messages when the widget initializes
|
||||||
context.read<MessageBloc>().add(LoadMessages(widget.group.id));
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_messageController.dispose();
|
_messageController.dispose();
|
||||||
_scrollController.dispose();
|
_scrollController.dispose();
|
||||||
|
_membersSubscription.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends a new message or updates an existing message.
|
/// Sends a new message or updates an existing message.
|
||||||
///
|
///
|
||||||
/// Handles both sending new messages and editing existing ones based
|
/// Handles both sending new messages and editing existing ones based
|
||||||
/// on the current editing state. Validates input and clears the input
|
/// on the current editing state. Validates input and clears the input
|
||||||
/// field after successful submission.
|
/// field after successful submission.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [currentUser]: The user sending or editing the message
|
/// [currentUser]: The user sending or editing the message
|
||||||
void _sendMessage(user_state.UserModel currentUser) {
|
void _sendMessage(user_state.UserModel currentUser) {
|
||||||
@@ -76,33 +95,33 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
if (_editingMessage != null) {
|
if (_editingMessage != null) {
|
||||||
// Edit mode - update existing message
|
// Edit mode - update existing message
|
||||||
context.read<MessageBloc>().add(
|
context.read<MessageBloc>().add(
|
||||||
UpdateMessage(
|
UpdateMessage(
|
||||||
groupId: widget.group.id,
|
groupId: widget.group.id,
|
||||||
messageId: _editingMessage!.id,
|
messageId: _editingMessage!.id,
|
||||||
newText: messageText,
|
newText: messageText,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
_cancelEdit();
|
_cancelEdit();
|
||||||
} else {
|
} else {
|
||||||
// Send mode - create new message
|
// Send mode - create new message
|
||||||
context.read<MessageBloc>().add(
|
context.read<MessageBloc>().add(
|
||||||
SendMessage(
|
SendMessage(
|
||||||
groupId: widget.group.id,
|
groupId: widget.group.id,
|
||||||
text: messageText,
|
text: messageText,
|
||||||
senderId: currentUser.id,
|
senderId: currentUser.id,
|
||||||
senderName: currentUser.prenom,
|
senderName: currentUser.prenom,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_messageController.clear();
|
_messageController.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initiates editing mode for a selected message.
|
/// Initiates editing mode for a selected message.
|
||||||
///
|
///
|
||||||
/// Sets the message as the currently editing message and populates
|
/// Sets the message as the currently editing message and populates
|
||||||
/// the input field with the message text for modification.
|
/// the input field with the message text for modification.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [message]: The message to edit
|
/// [message]: The message to edit
|
||||||
void _editMessage(Message message) {
|
void _editMessage(Message message) {
|
||||||
@@ -113,7 +132,7 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Cancels the current editing operation.
|
/// Cancels the current editing operation.
|
||||||
///
|
///
|
||||||
/// Resets the editing state and clears the input field,
|
/// Resets the editing state and clears the input field,
|
||||||
/// returning to normal message sending mode.
|
/// returning to normal message sending mode.
|
||||||
void _cancelEdit() {
|
void _cancelEdit() {
|
||||||
@@ -124,46 +143,43 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Deletes a message from the group chat.
|
/// Deletes a message from the group chat.
|
||||||
///
|
///
|
||||||
/// Sends a delete event to the MessageBloc to remove the specified
|
/// Sends a delete event to the MessageBloc to remove the specified
|
||||||
/// message from the group's message history.
|
/// message from the group's message history.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [messageId]: The ID of the message to delete
|
/// [messageId]: The ID of the message to delete
|
||||||
void _deleteMessage(String messageId) {
|
void _deleteMessage(String messageId) {
|
||||||
context.read<MessageBloc>().add(
|
context.read<MessageBloc>().add(
|
||||||
DeleteMessage(
|
DeleteMessage(groupId: widget.group.id, messageId: messageId),
|
||||||
groupId: widget.group.id,
|
);
|
||||||
messageId: messageId,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _reactToMessage(String messageId, String userId, String reaction) {
|
void _reactToMessage(String messageId, String userId, String reaction) {
|
||||||
context.read<MessageBloc>().add(
|
context.read<MessageBloc>().add(
|
||||||
ReactToMessage(
|
ReactToMessage(
|
||||||
groupId: widget.group.id,
|
groupId: widget.group.id,
|
||||||
messageId: messageId,
|
messageId: messageId,
|
||||||
userId: userId,
|
userId: userId,
|
||||||
reaction: reaction,
|
reaction: reaction,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _removeReaction(String messageId, String userId) {
|
void _removeReaction(String messageId, String userId) {
|
||||||
context.read<MessageBloc>().add(
|
context.read<MessageBloc>().add(
|
||||||
RemoveReaction(
|
RemoveReaction(
|
||||||
groupId: widget.group.id,
|
groupId: widget.group.id,
|
||||||
messageId: messageId,
|
messageId: messageId,
|
||||||
userId: userId,
|
userId: userId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||||
|
|
||||||
return BlocBuilder<UserBloc, user_state.UserState>(
|
return BlocBuilder<UserBloc, user_state.UserState>(
|
||||||
builder: (context, userState) {
|
builder: (context, userState) {
|
||||||
if (userState is! user_state.UserLoaded) {
|
if (userState is! user_state.UserLoaded) {
|
||||||
@@ -183,7 +199,10 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
Text(widget.group.name, style: const TextStyle(fontSize: 18)),
|
Text(widget.group.name, style: const TextStyle(fontSize: 18)),
|
||||||
Text(
|
Text(
|
||||||
'${widget.group.members.length} membre${widget.group.members.length > 1 ? 's' : ''}',
|
'${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,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -235,7 +254,8 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final message = state.messages[index];
|
final message = state.messages[index];
|
||||||
final isMe = message.senderId == currentUser.id;
|
final isMe = message.senderId == currentUser.id;
|
||||||
final showDate = index == 0 ||
|
final showDate =
|
||||||
|
index == 0 ||
|
||||||
!_isSameDay(
|
!_isSameDay(
|
||||||
state.messages[index - 1].timestamp,
|
state.messages[index - 1].timestamp,
|
||||||
message.timestamp,
|
message.timestamp,
|
||||||
@@ -243,8 +263,14 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
if (showDate) _buildDateSeparator(message.timestamp),
|
if (showDate)
|
||||||
_buildMessageBubble(message, isMe, isDark, currentUser.id),
|
_buildDateSeparator(message.timestamp),
|
||||||
|
_buildMessageBubble(
|
||||||
|
message,
|
||||||
|
isMe,
|
||||||
|
isDark,
|
||||||
|
currentUser.id,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -260,14 +286,15 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
if (_editingMessage != null)
|
if (_editingMessage != null)
|
||||||
Container(
|
Container(
|
||||||
color: isDark ? Colors.blue[900] : Colors.blue[100],
|
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(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.edit, size: 20),
|
const Icon(Icons.edit, size: 20),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
const Expanded(
|
const Expanded(child: Text('Modification du message')),
|
||||||
child: Text('Modification du message'),
|
|
||||||
),
|
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.close),
|
icon: const Icon(Icons.close),
|
||||||
onPressed: _cancelEdit,
|
onPressed: _cancelEdit,
|
||||||
@@ -295,11 +322,13 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
child: TextField(
|
child: TextField(
|
||||||
controller: _messageController,
|
controller: _messageController,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: _editingMessage != null
|
hintText: _editingMessage != null
|
||||||
? 'Modifier le message...'
|
? 'Modifier le message...'
|
||||||
: 'Écrire un message...',
|
: 'Écrire un message...',
|
||||||
filled: true,
|
filled: true,
|
||||||
fillColor: isDark ? Colors.grey[850] : Colors.grey[100],
|
fillColor: isDark
|
||||||
|
? Colors.grey[850]
|
||||||
|
: Colors.grey[100],
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(24),
|
borderRadius: BorderRadius.circular(24),
|
||||||
borderSide: BorderSide.none,
|
borderSide: BorderSide.none,
|
||||||
@@ -316,9 +345,13 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => _sendMessage(currentUser),
|
onPressed: () => _sendMessage(currentUser),
|
||||||
icon: Icon(_editingMessage != null ? Icons.check : Icons.send),
|
icon: Icon(
|
||||||
|
_editingMessage != null ? Icons.check : Icons.send,
|
||||||
|
),
|
||||||
style: IconButton.styleFrom(
|
style: IconButton.styleFrom(
|
||||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
backgroundColor: Theme.of(
|
||||||
|
context,
|
||||||
|
).colorScheme.primary,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
padding: const EdgeInsets.all(12),
|
padding: const EdgeInsets.all(12),
|
||||||
),
|
),
|
||||||
@@ -341,27 +374,17 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(Icons.chat_bubble_outline, size: 80, color: Colors.grey[400]),
|
||||||
Icons.chat_bubble_outline,
|
|
||||||
size: 80,
|
|
||||||
color: Colors.grey[400],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
const Text(
|
const Text(
|
||||||
'Aucun message',
|
'Aucun message',
|
||||||
style: TextStyle(
|
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
'Commencez la conversation !',
|
'Commencez la conversation !',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
|
||||||
fontSize: 14,
|
|
||||||
color: Colors.grey[600],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -369,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 bubbleColor;
|
||||||
final Color textColor;
|
final Color textColor;
|
||||||
|
|
||||||
if (isMe) {
|
if (isMe) {
|
||||||
bubbleColor = isDark ? const Color(0xFF1E3A5F) : const Color(0xFF90CAF9);
|
bubbleColor = isDark ? const Color(0xFF1E3A5F) : const Color(0xFF90CAF9);
|
||||||
textColor = isDark ? Colors.white : Colors.black87;
|
textColor = isDark ? Colors.white : Colors.black87;
|
||||||
@@ -380,77 +408,142 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
bubbleColor = isDark ? Colors.grey[800]! : Colors.grey[200]!;
|
bubbleColor = isDark ? Colors.grey[800]! : Colors.grey[200]!;
|
||||||
textColor = isDark ? Colors.white : Colors.black87;
|
textColor = isDark ? Colors.white : Colors.black87;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// Utiliser le pseudo actuel du membre, ou le senderName en fallback
|
||||||
|
final displayName = senderMember != null
|
||||||
|
? senderMember.pseudo
|
||||||
|
: message.senderName;
|
||||||
|
|
||||||
return Align(
|
return Align(
|
||||||
alignment: isMe ? Alignment.centerRight : Alignment.centerLeft,
|
alignment: isMe ? Alignment.centerRight : Alignment.centerLeft,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onLongPress: () => _showMessageOptions(context, message, isMe, currentUserId),
|
onLongPress: () =>
|
||||||
child: Container(
|
_showMessageOptions(context, message, isMe, currentUserId),
|
||||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||||
constraints: BoxConstraints(
|
child: Row(
|
||||||
maxWidth: MediaQuery.of(context).size.width * 0.7,
|
mainAxisAlignment: isMe
|
||||||
),
|
? MainAxisAlignment.end
|
||||||
decoration: BoxDecoration(
|
: MainAxisAlignment.start,
|
||||||
color: bubbleColor,
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
borderRadius: BorderRadius.only(
|
|
||||||
topLeft: const Radius.circular(16),
|
|
||||||
topRight: const Radius.circular(16),
|
|
||||||
bottomLeft: Radius.circular(isMe ? 16 : 4),
|
|
||||||
bottomRight: Radius.circular(isMe ? 4 : 16),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: isMe ? CrossAxisAlignment.end : CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
|
// Avatar du sender (seulement pour les autres messages)
|
||||||
if (!isMe) ...[
|
if (!isMe) ...[
|
||||||
Text(
|
CircleAvatar(
|
||||||
message.senderName,
|
radius: 16,
|
||||||
style: TextStyle(
|
backgroundImage:
|
||||||
fontSize: 12,
|
(senderMember != null &&
|
||||||
fontWeight: FontWeight.bold,
|
senderMember.profilePictureUrl != null &&
|
||||||
color: isDark ? Colors.grey[400] : Colors.grey[700],
|
senderMember.profilePictureUrl!.isNotEmpty)
|
||||||
|
? NetworkImage(senderMember.profilePictureUrl!)
|
||||||
|
: null,
|
||||||
|
child:
|
||||||
|
(senderMember == null ||
|
||||||
|
senderMember.profilePictureUrl == null ||
|
||||||
|
senderMember.profilePictureUrl!.isEmpty)
|
||||||
|
? Text(
|
||||||
|
displayName.isNotEmpty
|
||||||
|
? displayName[0].toUpperCase()
|
||||||
|
: '?',
|
||||||
|
style: const TextStyle(fontSize: 12),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
],
|
||||||
|
|
||||||
|
Container(
|
||||||
|
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 16,
|
||||||
|
vertical: 10,
|
||||||
|
),
|
||||||
|
constraints: BoxConstraints(
|
||||||
|
maxWidth: MediaQuery.of(context).size.width * 0.65,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: bubbleColor,
|
||||||
|
borderRadius: BorderRadius.only(
|
||||||
|
topLeft: const Radius.circular(16),
|
||||||
|
topRight: const Radius.circular(16),
|
||||||
|
bottomLeft: Radius.circular(isMe ? 16 : 4),
|
||||||
|
bottomRight: Radius.circular(isMe ? 4 : 16),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
child: Column(
|
||||||
],
|
crossAxisAlignment: isMe
|
||||||
Text(
|
? CrossAxisAlignment.end
|
||||||
message.text,
|
: CrossAxisAlignment.start,
|
||||||
style: TextStyle(fontSize: 15, color: textColor),
|
children: [
|
||||||
),
|
if (!isMe) ...[
|
||||||
const SizedBox(height: 4),
|
Text(
|
||||||
Row(
|
displayName,
|
||||||
mainAxisSize: MainAxisSize.min,
|
style: TextStyle(
|
||||||
children: [
|
fontSize: 12,
|
||||||
Text(
|
fontWeight: FontWeight.bold,
|
||||||
_formatTime(message.timestamp),
|
color: isDark ? Colors.grey[400] : Colors.grey[700],
|
||||||
style: TextStyle(
|
),
|
||||||
fontSize: 11,
|
),
|
||||||
color: textColor.withValues(alpha: 0.7),
|
const SizedBox(height: 4),
|
||||||
),
|
],
|
||||||
),
|
|
||||||
if (message.isEdited) ...[
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Text(
|
Text(
|
||||||
'(modifié)',
|
message.isDeleted
|
||||||
|
? 'a supprimé un message'
|
||||||
|
: message.text,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 10,
|
fontSize: 15,
|
||||||
fontStyle: FontStyle.italic,
|
color: message.isDeleted
|
||||||
color: textColor.withValues(alpha: 0.6),
|
? textColor.withValues(alpha: 0.5)
|
||||||
|
: textColor,
|
||||||
|
fontStyle: message.isDeleted
|
||||||
|
? FontStyle.italic
|
||||||
|
: FontStyle.normal,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
_formatTime(message.timestamp),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 11,
|
||||||
|
color: textColor.withValues(alpha: 0.7),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (message.isEdited) ...[
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text(
|
||||||
|
'(modifié)',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 10,
|
||||||
|
fontStyle: FontStyle.italic,
|
||||||
|
color: textColor.withValues(alpha: 0.6),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
// Afficher les réactions
|
||||||
|
if (message.reactions.isNotEmpty)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 4),
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 4,
|
||||||
|
children: _buildReactionChips(message, currentUserId),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
],
|
|
||||||
),
|
|
||||||
// Afficher les réactions
|
|
||||||
if (message.reactions.isNotEmpty)
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 4),
|
|
||||||
child: Wrap(
|
|
||||||
spacing: 4,
|
|
||||||
children: _buildReactionChips(message, currentUserId),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -460,7 +553,7 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
|
|
||||||
List<Widget> _buildReactionChips(Message message, String currentUserId) {
|
List<Widget> _buildReactionChips(Message message, String currentUserId) {
|
||||||
final reactionCounts = <String, List<String>>{};
|
final reactionCounts = <String, List<String>>{};
|
||||||
|
|
||||||
// Grouper les réactions par emoji
|
// Grouper les réactions par emoji
|
||||||
message.reactions.forEach((userId, emoji) {
|
message.reactions.forEach((userId, emoji) {
|
||||||
reactionCounts.putIfAbsent(emoji, () => []).add(userId);
|
reactionCounts.putIfAbsent(emoji, () => []).add(userId);
|
||||||
@@ -482,7 +575,7 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: hasReacted
|
color: hasReacted
|
||||||
? Colors.blue.withValues(alpha: 0.3)
|
? Colors.blue.withValues(alpha: 0.3)
|
||||||
: Colors.grey.withValues(alpha: 0.3),
|
: Colors.grey.withValues(alpha: 0.3),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
@@ -497,7 +590,10 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
const SizedBox(width: 2),
|
const SizedBox(width: 2),
|
||||||
Text(
|
Text(
|
||||||
'${userIds.length}',
|
'${userIds.length}',
|
||||||
style: const TextStyle(fontSize: 10, fontWeight: FontWeight.bold),
|
style: const TextStyle(
|
||||||
|
fontSize: 10,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -506,7 +602,12 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showMessageOptions(BuildContext context, Message message, bool isMe, String currentUserId) {
|
void _showMessageOptions(
|
||||||
|
BuildContext context,
|
||||||
|
Message message,
|
||||||
|
bool isMe,
|
||||||
|
String currentUserId,
|
||||||
|
) {
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => SafeArea(
|
builder: (context) => SafeArea(
|
||||||
@@ -541,7 +642,10 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.delete, color: Colors.red),
|
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: () {
|
onTap: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
_showDeleteConfirmation(context, message.id);
|
_showDeleteConfirmation(context, message.id);
|
||||||
@@ -642,11 +746,55 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
itemCount: widget.group.members.length,
|
itemCount: widget.group.members.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final member = widget.group.members[index];
|
final member = widget.group.members[index];
|
||||||
|
final initials = member.pseudo.isNotEmpty
|
||||||
|
? member.pseudo[0].toUpperCase()
|
||||||
|
: (member.firstName.isNotEmpty
|
||||||
|
? member.firstName[0].toUpperCase()
|
||||||
|
: '?');
|
||||||
|
|
||||||
|
// Construire le nom complet
|
||||||
|
final fullName = '${member.firstName} ${member.lastName}'.trim();
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
leading: CircleAvatar(
|
leading: CircleAvatar(
|
||||||
child: Text(member.pseudo.substring(0, 1).toUpperCase()),
|
backgroundImage:
|
||||||
|
(member.profilePictureUrl != null &&
|
||||||
|
member.profilePictureUrl!.isNotEmpty)
|
||||||
|
? NetworkImage(member.profilePictureUrl!)
|
||||||
|
: null,
|
||||||
|
child:
|
||||||
|
(member.profilePictureUrl == null ||
|
||||||
|
member.profilePictureUrl!.isEmpty)
|
||||||
|
? Text(initials)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
title: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(member.pseudo),
|
||||||
|
if (fullName.isNotEmpty)
|
||||||
|
Text(
|
||||||
|
fullName,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.normal,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
subtitle: member.role == 'admin'
|
||||||
|
? const Text(
|
||||||
|
'Administrateur',
|
||||||
|
style: TextStyle(fontSize: 12),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
trailing: IconButton(
|
||||||
|
icon: const Icon(Icons.edit, size: 18),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
_showChangePseudoDialog(member);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
title: Text(member.pseudo),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -660,4 +808,85 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void _showChangePseudoDialog(dynamic member) {
|
||||||
|
final pseudoController = TextEditingController(text: member.pseudo);
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
backgroundColor:
|
||||||
|
theme.dialogTheme.backgroundColor ?? theme.colorScheme.surface,
|
||||||
|
title: Text(
|
||||||
|
'Changer le pseudo',
|
||||||
|
style: theme.textTheme.titleLarge?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
content: TextField(
|
||||||
|
controller: pseudoController,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Nouveau pseudo',
|
||||||
|
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||||
|
contentPadding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 16,
|
||||||
|
vertical: 12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
style: TextStyle(color: theme.colorScheme.onSurface),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: Text(
|
||||||
|
'Annuler',
|
||||||
|
style: TextStyle(color: theme.colorScheme.primary),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
final newPseudo = pseudoController.text.trim();
|
||||||
|
if (newPseudo.isNotEmpty) {
|
||||||
|
_updateMemberPseudo(member, newPseudo);
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Text(
|
||||||
|
'Valider',
|
||||||
|
style: TextStyle(color: theme.colorScheme.primary),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _updateMemberPseudo(dynamic member, String newPseudo) async {
|
||||||
|
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"'),
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Erreur lors de la modification du pseudo: $e'),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -127,17 +127,6 @@ class _GroupContentState extends State<GroupContent> {
|
|||||||
child: ListView(
|
child: ListView(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
children: [
|
children: [
|
||||||
const Text(
|
|
||||||
'Mes groupes',
|
|
||||||
style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Text(
|
|
||||||
'Discutez avec les participants',
|
|
||||||
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
|
|
||||||
...groups.map((group) {
|
...groups.map((group) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 12),
|
padding: const EdgeInsets.only(bottom: 12),
|
||||||
@@ -155,12 +144,9 @@ class _GroupContentState extends State<GroupContent> {
|
|||||||
final color = colors[group.name.hashCode.abs() % colors.length];
|
final color = colors[group.name.hashCode.abs() % colors.length];
|
||||||
|
|
||||||
// Membres de manière simple
|
// Membres de manière simple
|
||||||
String memberInfo = '${group.members.length} membre(s)';
|
String memberInfo = '${group.memberIds.length} membre(s)';
|
||||||
if (group.members.isNotEmpty) {
|
if (group.members.isNotEmpty) {
|
||||||
final names = group.members
|
final names = group.members.take(2).map((m) => m.firstName).join(', ');
|
||||||
.take(2)
|
|
||||||
.map((m) => m.pseudo.isNotEmpty ? m.pseudo : m.firstName)
|
|
||||||
.join(', ');
|
|
||||||
memberInfo += '\n$names';
|
memberInfo += '\n$names';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
333
lib/components/home/calendar/calendar_page.dart
Normal file
333
lib/components/home/calendar/calendar_page.dart
Normal file
@@ -0,0 +1,333 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:table_calendar/table_calendar.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import '../../../models/trip.dart';
|
||||||
|
import '../../../models/activity.dart';
|
||||||
|
import '../../../blocs/activity/activity_bloc.dart';
|
||||||
|
import '../../../blocs/activity/activity_state.dart';
|
||||||
|
import '../../../blocs/activity/activity_event.dart';
|
||||||
|
|
||||||
|
class CalendarPage extends StatefulWidget {
|
||||||
|
final Trip trip;
|
||||||
|
|
||||||
|
const CalendarPage({super.key, required this.trip});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<CalendarPage> createState() => _CalendarPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CalendarPageState extends State<CalendarPage> {
|
||||||
|
late DateTime _focusedDay;
|
||||||
|
DateTime? _selectedDay;
|
||||||
|
CalendarFormat _calendarFormat = CalendarFormat.month;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_focusedDay = widget.trip.startDate;
|
||||||
|
_selectedDay = _focusedDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Activity> _getActivitiesForDay(DateTime day, List<Activity> activities) {
|
||||||
|
return activities.where((activity) {
|
||||||
|
if (activity.date == null) return false;
|
||||||
|
return isSameDay(activity.date, day);
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _selectTimeAndSchedule(Activity activity, DateTime date) async {
|
||||||
|
final TimeOfDay? pickedTime = await showTimePicker(
|
||||||
|
context: context,
|
||||||
|
initialTime: TimeOfDay.now(),
|
||||||
|
builder: (BuildContext context, Widget? child) {
|
||||||
|
return MediaQuery(
|
||||||
|
data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: true),
|
||||||
|
child: child!,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (pickedTime != null && mounted) {
|
||||||
|
final scheduledDate = DateTime(
|
||||||
|
date.year,
|
||||||
|
date.month,
|
||||||
|
date.day,
|
||||||
|
pickedTime.hour,
|
||||||
|
pickedTime.minute,
|
||||||
|
);
|
||||||
|
|
||||||
|
context.read<ActivityBloc>().add(
|
||||||
|
UpdateActivityDate(
|
||||||
|
tripId: widget.trip.id!,
|
||||||
|
activityId: activity.id,
|
||||||
|
date: scheduledDate,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Calendrier du voyage'),
|
||||||
|
backgroundColor: theme.colorScheme.surface,
|
||||||
|
foregroundColor: theme.colorScheme.onSurface,
|
||||||
|
elevation: 0,
|
||||||
|
),
|
||||||
|
body: BlocBuilder<ActivityBloc, ActivityState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
if (state is ActivityLoading) {
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Activity> allActivities = [];
|
||||||
|
if (state is ActivityLoaded) {
|
||||||
|
allActivities = state.activities;
|
||||||
|
} else if (state is ActivitySearchResults) {
|
||||||
|
// Fallback if we are in search state, though ideally we should be in loaded state
|
||||||
|
// This might happen if we navigate back and forth
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter approved activities
|
||||||
|
final approvedActivities = allActivities.where((a) {
|
||||||
|
return a.isApprovedByAllParticipants([
|
||||||
|
...widget.trip.participants,
|
||||||
|
widget.trip.createdBy,
|
||||||
|
]);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
final scheduledActivities = approvedActivities
|
||||||
|
.where((a) => a.date != null)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
final unscheduledActivities = approvedActivities
|
||||||
|
.where((a) => a.date == null)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
final selectedActivities = _getActivitiesForDay(
|
||||||
|
_selectedDay ?? _focusedDay,
|
||||||
|
scheduledActivities,
|
||||||
|
);
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
TableCalendar(
|
||||||
|
firstDay: DateTime.now().subtract(const Duration(days: 365)),
|
||||||
|
lastDay: DateTime.now().add(const Duration(days: 365)),
|
||||||
|
focusedDay: _focusedDay,
|
||||||
|
calendarFormat: _calendarFormat,
|
||||||
|
selectedDayPredicate: (day) {
|
||||||
|
return isSameDay(_selectedDay, day);
|
||||||
|
},
|
||||||
|
onDaySelected: (selectedDay, focusedDay) {
|
||||||
|
setState(() {
|
||||||
|
_selectedDay = selectedDay;
|
||||||
|
_focusedDay = focusedDay;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onFormatChanged: (format) {
|
||||||
|
setState(() {
|
||||||
|
_calendarFormat = format;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onPageChanged: (focusedDay) {
|
||||||
|
_focusedDay = focusedDay;
|
||||||
|
},
|
||||||
|
eventLoader: (day) {
|
||||||
|
return _getActivitiesForDay(day, scheduledActivities);
|
||||||
|
},
|
||||||
|
calendarBuilders: CalendarBuilders(
|
||||||
|
markerBuilder: (context, day, events) {
|
||||||
|
if (events.isEmpty) return null;
|
||||||
|
return Positioned(
|
||||||
|
bottom: 1,
|
||||||
|
child: Container(
|
||||||
|
width: 7,
|
||||||
|
height: 7,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
calendarStyle: CalendarStyle(
|
||||||
|
todayDecoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.primary.withValues(alpha: 0.5),
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
selectedDecoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
Expanded(
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
// Scheduled Activities for Selected Day
|
||||||
|
Expanded(
|
||||||
|
flex: 3,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(
|
||||||
|
'Activités du ${DateFormat('dd/MM/yyyy').format(_selectedDay!)}',
|
||||||
|
style: theme.textTheme.titleMedium,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: selectedActivities.isEmpty
|
||||||
|
? Center(
|
||||||
|
child: Text(
|
||||||
|
'Aucune activité prévue',
|
||||||
|
style: theme.textTheme.bodyMedium
|
||||||
|
?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurface
|
||||||
|
.withValues(alpha: 0.6),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: ListView.builder(
|
||||||
|
itemCount: selectedActivities.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final activity =
|
||||||
|
selectedActivities[index];
|
||||||
|
return ListTile(
|
||||||
|
title: Text(activity.name),
|
||||||
|
subtitle: Text(
|
||||||
|
'${activity.category} - ${DateFormat('HH:mm').format(activity.date!)}',
|
||||||
|
),
|
||||||
|
trailing: IconButton(
|
||||||
|
icon: const Icon(Icons.close),
|
||||||
|
onPressed: () {
|
||||||
|
context.read<ActivityBloc>().add(
|
||||||
|
UpdateActivityDate(
|
||||||
|
tripId: widget.trip.id!,
|
||||||
|
activityId: activity.id,
|
||||||
|
date: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const VerticalDivider(),
|
||||||
|
// Unscheduled Activities
|
||||||
|
Expanded(
|
||||||
|
flex: 2,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(
|
||||||
|
'À planifier',
|
||||||
|
style: theme.textTheme.titleMedium,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: unscheduledActivities.isEmpty
|
||||||
|
? Center(
|
||||||
|
child: Text(
|
||||||
|
'Tout est planifié !',
|
||||||
|
style: theme.textTheme.bodyMedium
|
||||||
|
?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurface
|
||||||
|
.withValues(alpha: 0.6),
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: ListView.builder(
|
||||||
|
itemCount: unscheduledActivities.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final activity =
|
||||||
|
unscheduledActivities[index];
|
||||||
|
return Draggable<Activity>(
|
||||||
|
data: activity,
|
||||||
|
feedback: Material(
|
||||||
|
elevation: 4,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
color: theme.cardColor,
|
||||||
|
child: Text(activity.name),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: ListTile(
|
||||||
|
title: Text(
|
||||||
|
activity.name,
|
||||||
|
style: theme.textTheme.bodySmall,
|
||||||
|
),
|
||||||
|
trailing: IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_back),
|
||||||
|
onPressed: () {
|
||||||
|
if (_selectedDay != null) {
|
||||||
|
_selectTimeAndSchedule(
|
||||||
|
activity,
|
||||||
|
_selectedDay!,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Zone de drop pour le calendrier
|
||||||
|
DragTarget<Activity>(
|
||||||
|
onWillAcceptWithDetails: (details) => true,
|
||||||
|
onAcceptWithDetails: (details) {
|
||||||
|
if (_selectedDay != null) {
|
||||||
|
_selectTimeAndSchedule(
|
||||||
|
details.data,
|
||||||
|
_selectedDay!,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
builder: (context, candidateData, rejectedData) {
|
||||||
|
return Container(
|
||||||
|
height: 50,
|
||||||
|
color: candidateData.isNotEmpty
|
||||||
|
? theme.colorScheme.primary.withValues(
|
||||||
|
alpha: 0.1,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
'Glisser ici pour planifier',
|
||||||
|
style: TextStyle(
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,13 +17,15 @@ import '../../models/group.dart';
|
|||||||
import '../../models/group_member.dart';
|
import '../../models/group_member.dart';
|
||||||
import '../../services/user_service.dart';
|
import '../../services/user_service.dart';
|
||||||
import '../../repositories/group_repository.dart';
|
import '../../repositories/group_repository.dart';
|
||||||
|
import '../../repositories/account_repository.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import '../../services/place_image_service.dart';
|
import '../../services/place_image_service.dart';
|
||||||
import '../../services/trip_geocoding_service.dart';
|
import '../../services/trip_geocoding_service.dart';
|
||||||
|
import '../../services/logger_service.dart';
|
||||||
|
|
||||||
/// Create trip content widget for trip creation and editing functionality.
|
/// Create trip content widget for trip creation and editing functionality.
|
||||||
///
|
///
|
||||||
/// This widget provides a comprehensive form interface for creating new trips
|
/// This widget provides a comprehensive form interface for creating new trips
|
||||||
/// or editing existing ones. Key features include:
|
/// or editing existing ones. Key features include:
|
||||||
/// - Trip creation with validation
|
/// - Trip creation with validation
|
||||||
@@ -33,22 +35,19 @@ import '../../services/trip_geocoding_service.dart';
|
|||||||
/// - Group creation and member management
|
/// - Group creation and member management
|
||||||
/// - Account setup for expense tracking
|
/// - Account setup for expense tracking
|
||||||
/// - Integration with mapping services for location selection
|
/// - Integration with mapping services for location selection
|
||||||
///
|
///
|
||||||
/// The widget handles both creation and editing modes based on the
|
/// The widget handles both creation and editing modes based on the
|
||||||
/// provided tripToEdit parameter.
|
/// provided tripToEdit parameter.
|
||||||
class CreateTripContent extends StatefulWidget {
|
class CreateTripContent extends StatefulWidget {
|
||||||
/// Optional trip to edit. If null, creates a new trip
|
/// Optional trip to edit. If null, creates a new trip
|
||||||
final Trip? tripToEdit;
|
final Trip? tripToEdit;
|
||||||
|
|
||||||
/// Creates a create trip content widget.
|
/// Creates a create trip content widget.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [tripToEdit]: Optional trip to edit. If provided, the form will
|
/// [tripToEdit]: Optional trip to edit. If provided, the form will
|
||||||
/// be populated with existing trip data for editing
|
/// be populated with existing trip data for editing
|
||||||
const CreateTripContent({
|
const CreateTripContent({super.key, this.tripToEdit});
|
||||||
super.key,
|
|
||||||
this.tripToEdit,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<CreateTripContent> createState() => _CreateTripContentState();
|
State<CreateTripContent> createState() => _CreateTripContentState();
|
||||||
@@ -57,27 +56,28 @@ class CreateTripContent extends StatefulWidget {
|
|||||||
class _CreateTripContentState extends State<CreateTripContent> {
|
class _CreateTripContentState extends State<CreateTripContent> {
|
||||||
/// Service for handling and displaying errors
|
/// Service for handling and displaying errors
|
||||||
final _errorService = ErrorService();
|
final _errorService = ErrorService();
|
||||||
|
|
||||||
/// Form validation key
|
/// Form validation key
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
/// Text controllers for form fields
|
/// Text controllers for form fields
|
||||||
final _titleController = TextEditingController();
|
final _titleController = TextEditingController();
|
||||||
final _descriptionController = TextEditingController();
|
final _descriptionController = TextEditingController();
|
||||||
final _locationController = TextEditingController();
|
final _locationController = TextEditingController();
|
||||||
final _budgetController = TextEditingController();
|
final _budgetController = TextEditingController();
|
||||||
final _participantController = TextEditingController();
|
final _participantController = TextEditingController();
|
||||||
|
|
||||||
/// Services for user and group operations
|
/// Services for user and group operations
|
||||||
final _userService = UserService();
|
final _userService = UserService();
|
||||||
final _groupRepository = GroupRepository();
|
final _groupRepository = GroupRepository();
|
||||||
|
final _accountRepository = AccountRepository();
|
||||||
final _placeImageService = PlaceImageService();
|
final _placeImageService = PlaceImageService();
|
||||||
final _tripGeocodingService = TripGeocodingService();
|
final _tripGeocodingService = TripGeocodingService();
|
||||||
|
|
||||||
/// Trip date variables
|
/// Trip date variables
|
||||||
DateTime? _startDate;
|
DateTime? _startDate;
|
||||||
DateTime? _endDate;
|
DateTime? _endDate;
|
||||||
|
|
||||||
/// Loading and state management variables
|
/// Loading and state management variables
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
String? _createdTripId;
|
String? _createdTripId;
|
||||||
@@ -125,7 +125,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
|
|
||||||
void _onLocationChanged() {
|
void _onLocationChanged() {
|
||||||
final query = _locationController.text.trim();
|
final query = _locationController.text.trim();
|
||||||
|
|
||||||
if (query.length < 2) {
|
if (query.length < 2) {
|
||||||
_hideSuggestions();
|
_hideSuggestions();
|
||||||
return;
|
return;
|
||||||
@@ -149,14 +149,14 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
'?input=${Uri.encodeComponent(query)}'
|
'?input=${Uri.encodeComponent(query)}'
|
||||||
'&types=(cities)'
|
'&types=(cities)'
|
||||||
'&language=fr'
|
'&language=fr'
|
||||||
'&key=$_apiKey'
|
'&key=$_apiKey',
|
||||||
);
|
);
|
||||||
|
|
||||||
final response = await http.get(url);
|
final response = await http.get(url);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
|
|
||||||
if (data['status'] == 'OK') {
|
if (data['status'] == 'OK') {
|
||||||
final predictions = data['predictions'] as List;
|
final predictions = data['predictions'] as List;
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -168,7 +168,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
}).toList();
|
}).toList();
|
||||||
_isLoadingSuggestions = false;
|
_isLoadingSuggestions = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (_placeSuggestions.isNotEmpty) {
|
if (_placeSuggestions.isNotEmpty) {
|
||||||
_showSuggestions();
|
_showSuggestions();
|
||||||
} else {
|
} else {
|
||||||
@@ -200,12 +200,14 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
// Nouvelle méthode pour afficher les suggestions
|
// Nouvelle méthode pour afficher les suggestions
|
||||||
void _showSuggestions() {
|
void _showSuggestions() {
|
||||||
_hideSuggestions(); // Masquer d'abord les suggestions existantes
|
_hideSuggestions(); // Masquer d'abord les suggestions existantes
|
||||||
|
|
||||||
if (_placeSuggestions.isEmpty) return;
|
if (_placeSuggestions.isEmpty) return;
|
||||||
|
|
||||||
_suggestionsOverlay = OverlayEntry(
|
_suggestionsOverlay = OverlayEntry(
|
||||||
builder: (context) => Positioned(
|
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(
|
child: CompositedTransformFollower(
|
||||||
link: _layerLink,
|
link: _layerLink,
|
||||||
showWhenUnlinked: false,
|
showWhenUnlinked: false,
|
||||||
@@ -256,26 +258,32 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
_placeSuggestions = [];
|
_placeSuggestions = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
// Charger l'image du lieu sélectionné
|
// Charger l'image du lieu sélectionné
|
||||||
_loadPlaceImage(suggestion.description);
|
_loadPlaceImage(suggestion.description);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Charge l'image du lieu depuis Google Places API
|
/// Charge l'image du lieu depuis Google Places API
|
||||||
Future<void> _loadPlaceImage(String location) async {
|
Future<void> _loadPlaceImage(String location) async {
|
||||||
print('CreateTripContent: Chargement de l\'image pour: $location');
|
LoggerService.info(
|
||||||
|
'CreateTripContent: Chargement de l\'image pour: $location',
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final imageUrl = await _placeImageService.getPlaceImageUrl(location);
|
final imageUrl = await _placeImageService.getPlaceImageUrl(location);
|
||||||
print('CreateTripContent: Image URL reçue: $imageUrl');
|
LoggerService.info('CreateTripContent: Image URL reçue: $imageUrl');
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedImageUrl = imageUrl;
|
_selectedImageUrl = imageUrl;
|
||||||
});
|
});
|
||||||
print('CreateTripContent: État mis à jour avec imageUrl: $_selectedImageUrl');
|
LoggerService.info(
|
||||||
|
'CreateTripContent: État mis à jour avec imageUrl: $_selectedImageUrl',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} 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) {
|
if (mounted) {
|
||||||
_errorService.logError(
|
_errorService.logError(
|
||||||
'create_trip_content.dart',
|
'create_trip_content.dart',
|
||||||
@@ -335,7 +343,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
}) {
|
}) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final isDarkMode = theme.brightness == Brightness.dark;
|
final isDarkMode = theme.brightness == Brightness.dark;
|
||||||
|
|
||||||
return TextFormField(
|
return TextFormField(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
validator: validator,
|
validator: validator,
|
||||||
@@ -347,42 +355,36 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: label,
|
hintText: label,
|
||||||
hintStyle: theme.textTheme.bodyLarge?.copyWith(
|
hintStyle: theme.textTheme.bodyLarge?.copyWith(
|
||||||
color: theme.colorScheme.onSurface.withOpacity(0.5),
|
color: theme.colorScheme.onSurface.withValues(alpha: 0.5),
|
||||||
),
|
),
|
||||||
prefixIcon: Icon(
|
prefixIcon: Icon(
|
||||||
icon,
|
icon,
|
||||||
color: theme.colorScheme.onSurface.withOpacity(0.5),
|
color: theme.colorScheme.onSurface.withValues(alpha: 0.5),
|
||||||
),
|
),
|
||||||
suffixIcon: suffixIcon,
|
suffixIcon: suffixIcon,
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: isDarkMode
|
color: isDarkMode
|
||||||
? Colors.white.withOpacity(0.2)
|
? Colors.white.withValues(alpha: 0.2)
|
||||||
: Colors.black.withOpacity(0.2),
|
: Colors.black.withValues(alpha: 0.2),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
enabledBorder: OutlineInputBorder(
|
enabledBorder: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: isDarkMode
|
color: isDarkMode
|
||||||
? Colors.white.withOpacity(0.2)
|
? Colors.white.withValues(alpha: 0.2)
|
||||||
: Colors.black.withOpacity(0.2),
|
: Colors.black.withValues(alpha: 0.2),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
focusedBorder: OutlineInputBorder(
|
focusedBorder: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(color: Colors.teal, width: 2),
|
||||||
color: Colors.teal,
|
|
||||||
width: 2,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
errorBorder: OutlineInputBorder(
|
errorBorder: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
borderSide: const BorderSide(
|
borderSide: const BorderSide(color: Colors.red, width: 2),
|
||||||
color: Colors.red,
|
|
||||||
width: 2,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
filled: true,
|
filled: true,
|
||||||
fillColor: theme.cardColor,
|
fillColor: theme.cardColor,
|
||||||
@@ -401,7 +403,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
}) {
|
}) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final isDarkMode = theme.brightness == Brightness.dark;
|
final isDarkMode = theme.brightness == Brightness.dark;
|
||||||
|
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
@@ -411,27 +413,27 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
color: theme.cardColor,
|
color: theme.cardColor,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: isDarkMode
|
color: isDarkMode
|
||||||
? Colors.white.withOpacity(0.2)
|
? Colors.white.withValues(alpha: 0.2)
|
||||||
: Colors.black.withOpacity(0.2),
|
: Colors.black.withValues(alpha: 0.2),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
Icons.calendar_today,
|
Icons.calendar_today,
|
||||||
color: theme.colorScheme.onSurface.withOpacity(0.5),
|
color: theme.colorScheme.onSurface.withValues(alpha: 0.5),
|
||||||
size: 20,
|
size: 20,
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Text(
|
Text(
|
||||||
date != null
|
date != null
|
||||||
? '${date.day.toString().padLeft(2, '0')}/${date.month.toString().padLeft(2, '0')}/${date.year}'
|
? '${date.day.toString().padLeft(2, '0')}/${date.month.toString().padLeft(2, '0')}/${date.year}'
|
||||||
: 'mm/dd/yyyy',
|
: 'mm/dd/yyyy',
|
||||||
style: theme.textTheme.bodyLarge?.copyWith(
|
style: theme.textTheme.bodyLarge?.copyWith(
|
||||||
color: date != null
|
color: date != null
|
||||||
? theme.colorScheme.onSurface
|
? theme.colorScheme.onSurface
|
||||||
: theme.colorScheme.onSurface.withOpacity(0.5),
|
: theme.colorScheme.onSurface.withValues(alpha: 0.5),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -440,11 +442,11 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final isDarkMode = theme.brightness == Brightness.dark;
|
final isDarkMode = theme.brightness == Brightness.dark;
|
||||||
|
|
||||||
return BlocListener<TripBloc, TripState>(
|
return BlocListener<TripBloc, TripState>(
|
||||||
listener: (context, tripState) {
|
listener: (context, tripState) {
|
||||||
if (tripState is TripCreated) {
|
if (tripState is TripCreated) {
|
||||||
@@ -452,7 +454,10 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
_createGroupAndAccountForTrip(_createdTripId!);
|
_createGroupAndAccountForTrip(_createdTripId!);
|
||||||
} else if (tripState is TripOperationSuccess) {
|
} else if (tripState is TripOperationSuccess) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
_errorService.showSnackbar(message: tripState.message, isError: false);
|
_errorService.showSnackbar(
|
||||||
|
message: tripState.message,
|
||||||
|
isError: false,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
});
|
});
|
||||||
@@ -463,7 +468,10 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
}
|
}
|
||||||
} else if (tripState is TripError) {
|
} else if (tripState is TripError) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
_errorService.showSnackbar(message: tripState.message, isError: true);
|
_errorService.showSnackbar(
|
||||||
|
message: tripState.message,
|
||||||
|
isError: true,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
});
|
});
|
||||||
@@ -476,7 +484,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: theme.scaffoldBackgroundColor,
|
backgroundColor: theme.scaffoldBackgroundColor,
|
||||||
appBar: AppBar(
|
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,
|
backgroundColor: theme.appBarTheme.backgroundColor,
|
||||||
foregroundColor: theme.appBarTheme.foregroundColor,
|
foregroundColor: theme.appBarTheme.foregroundColor,
|
||||||
),
|
),
|
||||||
@@ -504,7 +514,10 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
leading: IconButton(
|
leading: IconButton(
|
||||||
icon: Icon(Icons.arrow_back, color: theme.colorScheme.onSurface),
|
icon: Icon(
|
||||||
|
Icons.arrow_back,
|
||||||
|
color: theme.colorScheme.onSurface,
|
||||||
|
),
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -517,7 +530,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: Colors.black.withOpacity(isDarkMode ? 0.3 : 0.1),
|
color: Colors.black.withValues(
|
||||||
|
alpha: isDarkMode ? 0.3 : 0.1,
|
||||||
|
),
|
||||||
blurRadius: 10,
|
blurRadius: 10,
|
||||||
offset: const Offset(0, 5),
|
offset: const Offset(0, 5),
|
||||||
),
|
),
|
||||||
@@ -542,7 +557,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
Text(
|
Text(
|
||||||
'Donne un nom à ton voyage',
|
'Donne un nom à ton voyage',
|
||||||
style: theme.textTheme.bodyMedium?.copyWith(
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
color: theme.colorScheme.onSurface.withOpacity(0.7),
|
color: theme.colorScheme.onSurface.withValues(
|
||||||
|
alpha: 0.7,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
@@ -586,7 +603,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
? const SizedBox(
|
? const SizedBox(
|
||||||
width: 20,
|
width: 20,
|
||||||
height: 20,
|
height: 20,
|
||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
@@ -611,46 +630,42 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
|
||||||
// Dates
|
// Dates
|
||||||
Row(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Column(
|
||||||
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
||||||
children: [
|
Text(
|
||||||
Text(
|
'Début du voyage',
|
||||||
'Début du voyage',
|
style: theme.textTheme.titleMedium?.copyWith(
|
||||||
style: theme.textTheme.titleMedium?.copyWith(
|
fontWeight: FontWeight.w600,
|
||||||
fontWeight: FontWeight.w600,
|
color: theme.colorScheme.onSurface,
|
||||||
color: theme.colorScheme.onSurface,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
),
|
||||||
_buildDateField(
|
const SizedBox(height: 12),
|
||||||
date: _startDate,
|
_buildDateField(
|
||||||
onTap: () => _selectStartDate(context),
|
date: _startDate,
|
||||||
),
|
onTap: () => _selectStartDate(context),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(width: 16),
|
const SizedBox(height: 20),
|
||||||
Expanded(
|
Column(
|
||||||
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
||||||
children: [
|
Text(
|
||||||
Text(
|
'Fin du voyage',
|
||||||
'Fin du voyage',
|
style: theme.textTheme.titleMedium?.copyWith(
|
||||||
style: theme.textTheme.titleMedium?.copyWith(
|
fontWeight: FontWeight.w600,
|
||||||
fontWeight: FontWeight.w600,
|
color: theme.colorScheme.onSurface,
|
||||||
color: theme.colorScheme.onSurface,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
),
|
||||||
_buildDateField(
|
const SizedBox(height: 12),
|
||||||
date: _endDate,
|
_buildDateField(
|
||||||
onTap: () => _selectEndDate(context),
|
date: _endDate,
|
||||||
),
|
onTap: () => _selectEndDate(context),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -669,86 +684,94 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
controller: _budgetController,
|
controller: _budgetController,
|
||||||
label: 'Ex : 500',
|
label: 'Ex : 500',
|
||||||
icon: Icons.euro,
|
icon: Icons.euro,
|
||||||
keyboardType: TextInputType.numberWithOptions(decimal: true),
|
keyboardType: TextInputType.numberWithOptions(
|
||||||
|
decimal: true,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
|
||||||
// Inviter des amis
|
// Inviter des amis - seulement en mode création
|
||||||
Text(
|
if (!isEditing) ...[
|
||||||
'Invite tes amis',
|
Text(
|
||||||
style: theme.textTheme.titleMedium?.copyWith(
|
'Invite tes amis',
|
||||||
fontWeight: FontWeight.w600,
|
style: theme.textTheme.titleMedium?.copyWith(
|
||||||
color: theme.colorScheme.onSurface,
|
fontWeight: FontWeight.w600,
|
||||||
|
color: theme.colorScheme.onSurface,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 12),
|
||||||
const SizedBox(height: 12),
|
Row(
|
||||||
Row(
|
children: [
|
||||||
children: [
|
Expanded(
|
||||||
Expanded(
|
child: _buildModernTextField(
|
||||||
child: _buildModernTextField(
|
controller: _participantController,
|
||||||
controller: _participantController,
|
label: 'adresse@email.com',
|
||||||
label: 'adresse@email.com',
|
icon: Icons.alternate_email,
|
||||||
icon: Icons.alternate_email,
|
keyboardType: TextInputType.emailAddress,
|
||||||
keyboardType: TextInputType.emailAddress,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Container(
|
|
||||||
height: 56,
|
|
||||||
width: 56,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.teal,
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
child: IconButton(
|
|
||||||
onPressed: _addParticipant,
|
|
||||||
icon: const Icon(Icons.add, color: Colors.white),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
// Participants ajoutés
|
|
||||||
if (_participants.isNotEmpty) ...[
|
|
||||||
Wrap(
|
|
||||||
spacing: 8,
|
|
||||||
runSpacing: 8,
|
|
||||||
children: _participants.map((email) {
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 12,
|
|
||||||
vertical: 8,
|
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Container(
|
||||||
|
height: 56,
|
||||||
|
width: 56,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.teal.withOpacity(0.1),
|
color: Colors.teal,
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: IconButton(
|
||||||
mainAxisSize: MainAxisSize.min,
|
onPressed: _addParticipant,
|
||||||
children: [
|
icon: const Icon(
|
||||||
Text(
|
Icons.add,
|
||||||
email,
|
color: Colors.white,
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
),
|
||||||
color: Colors.teal,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () => _removeParticipant(email),
|
|
||||||
child: const Icon(
|
|
||||||
Icons.close,
|
|
||||||
size: 16,
|
|
||||||
color: Colors.teal,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
}).toList(),
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
// Participants ajoutés
|
||||||
|
if (_participants.isNotEmpty) ...[
|
||||||
|
Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 8,
|
||||||
|
children: _participants.map((email) {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 12,
|
||||||
|
vertical: 8,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.teal.withValues(alpha: 0.1),
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
email,
|
||||||
|
style: theme.textTheme.bodySmall
|
||||||
|
?.copyWith(
|
||||||
|
color: Colors.teal,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () => _removeParticipant(email),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.close,
|
||||||
|
size: 16,
|
||||||
|
color: Colors.teal,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
const SizedBox(height: 32),
|
const SizedBox(height: 32),
|
||||||
@@ -758,7 +781,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: 56,
|
height: 56,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: _isLoading ? null : () => _saveTrip(userState.user),
|
onPressed: _isLoading
|
||||||
|
? null
|
||||||
|
: () => _saveTrip(userState.user),
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Colors.teal,
|
backgroundColor: Colors.teal,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
@@ -773,15 +798,20 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
height: 20,
|
height: 20,
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
strokeWidth: 2,
|
strokeWidth: 2,
|
||||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
valueColor: AlwaysStoppedAnimation<Color>(
|
||||||
|
Colors.white,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: Text(
|
: Text(
|
||||||
isEditing ? 'Modifier le voyage' : 'Créer le voyage',
|
isEditing
|
||||||
style: theme.textTheme.titleMedium?.copyWith(
|
? 'Modifier le voyage'
|
||||||
color: Colors.white,
|
: 'Créer le voyage',
|
||||||
fontWeight: FontWeight.w600,
|
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}$');
|
final emailRegex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
|
||||||
if (!emailRegex.hasMatch(email)) {
|
if (!emailRegex.hasMatch(email)) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Email invalide')));
|
ScaffoldMessenger.of(
|
||||||
|
context,
|
||||||
|
).showSnackBar(SnackBar(content: Text('Email invalide')));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_participants.contains(email)) {
|
if (_participants.contains(email)) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context)
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
.showSnackBar(SnackBar(content: Text('Ce participant est déjà ajouté')));
|
SnackBar(content: Text('Ce participant est déjà ajouté')),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -871,13 +904,15 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mettre à jour le groupe avec les nouveaux membres
|
// Mettre à jour le groupe ET le compte avec les nouveaux membres
|
||||||
Future<void> _updateGroupMembers(
|
Future<void> _updateGroupAndAccountMembers(
|
||||||
String tripId,
|
String tripId,
|
||||||
user_state.UserModel currentUser,
|
user_state.UserModel currentUser,
|
||||||
List<Map<String, dynamic>> participantsData,
|
List<Map<String, dynamic>> participantsData,
|
||||||
) async {
|
) async {
|
||||||
final groupBloc = context.read<GroupBloc>();
|
final groupBloc = context.read<GroupBloc>();
|
||||||
|
final accountBloc = context.read<AccountBloc>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final group = await _groupRepository.getGroupByTripId(tripId);
|
final group = await _groupRepository.getGroupByTripId(tripId);
|
||||||
|
|
||||||
@@ -889,33 +924,58 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Récupérer le compte associé au voyage
|
||||||
|
final account = await _accountRepository.getAccountByTripId(tripId);
|
||||||
|
|
||||||
final newMembers = await _createMembers();
|
final newMembers = await _createMembers();
|
||||||
|
|
||||||
final currentMembers = await _groupRepository.getGroupMembers(group.id);
|
final currentMembers = await _groupRepository.getGroupMembers(group.id);
|
||||||
final currentMemberIds = currentMembers.map((m) => m.userId).toSet();
|
final currentMemberIds = currentMembers.map((m) => m.userId).toSet();
|
||||||
final newMemberIds = newMembers.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
|
final membersToRemove = currentMembers
|
||||||
.where((m) => !newMemberIds.contains(m.userId) && m.role != 'admin')
|
.where((m) => !newMemberIds.contains(m.userId) && m.role != 'admin')
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
// Ajouter les nouveaux membres au groupe ET au compte
|
||||||
for (final member in membersToAdd) {
|
for (final member in membersToAdd) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
groupBloc.add(AddMemberToGroup(group.id, member));
|
groupBloc.add(AddMemberToGroup(group.id, member));
|
||||||
|
if (account != null) {
|
||||||
|
accountBloc.add(AddMemberToAccount(account.id, member));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Supprimer les membres supprimés du groupe ET du compte
|
||||||
for (final member in membersToRemove) {
|
for (final member in membersToRemove) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
groupBloc.add(RemoveMemberFromGroup(group.id, member.userId));
|
groupBloc.add(RemoveMemberFromGroup(group.id, member.userId));
|
||||||
|
if (account != null) {
|
||||||
|
accountBloc.add(RemoveMemberFromAccount(account.id, member.userId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Groupe et compte mis à jour avec succès !'),
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError(
|
_errorService.logError(
|
||||||
'create_trip_content.dart',
|
'create_trip_content.dart',
|
||||||
'Erreur lors de la mise à jour du groupe: $e',
|
'Erreur lors de la mise à jour du groupe et du compte: $e',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -931,17 +991,21 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
GroupMember(
|
GroupMember(
|
||||||
userId: currentUser.id,
|
userId: currentUser.id,
|
||||||
firstName: currentUser.prenom,
|
firstName: currentUser.prenom,
|
||||||
|
lastName: currentUser.nom,
|
||||||
pseudo: currentUser.prenom,
|
pseudo: currentUser.prenom,
|
||||||
role: 'admin',
|
role: 'admin',
|
||||||
profilePictureUrl: currentUser.profilePictureUrl,
|
profilePictureUrl: currentUser.profilePictureUrl,
|
||||||
),
|
),
|
||||||
...participantsData.map((p) => GroupMember(
|
...participantsData.map(
|
||||||
userId: p['id'] as String,
|
(p) => GroupMember(
|
||||||
firstName: p['firstName'] as String,
|
userId: p['id'] as String,
|
||||||
pseudo: p['firstName'] as String,
|
firstName: p['firstName'] as String,
|
||||||
role: 'member',
|
lastName: p['lastName'] as String? ?? '',
|
||||||
profilePictureUrl: p['profilePictureUrl'] as String?,
|
pseudo: p['firstName'] as String,
|
||||||
)),
|
role: 'member',
|
||||||
|
profilePictureUrl: p['profilePictureUrl'] as String?,
|
||||||
|
),
|
||||||
|
),
|
||||||
];
|
];
|
||||||
return groupMembers;
|
return groupMembers;
|
||||||
}
|
}
|
||||||
@@ -949,9 +1013,8 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
Future<void> _createGroupAndAccountForTrip(String tripId) async {
|
Future<void> _createGroupAndAccountForTrip(String tripId) async {
|
||||||
final groupBloc = context.read<GroupBloc>();
|
final groupBloc = context.read<GroupBloc>();
|
||||||
final accountBloc = context.read<AccountBloc>();
|
final accountBloc = context.read<AccountBloc>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
final userState = context.read<UserBloc>().state;
|
final userState = context.read<UserBloc>().state;
|
||||||
if (userState is! user_state.UserLoaded) {
|
if (userState is! user_state.UserLoaded) {
|
||||||
throw Exception('Utilisateur non connecté');
|
throw Exception('Utilisateur non connecté');
|
||||||
@@ -971,21 +1034,19 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
throw Exception('Erreur lors de la création des membres du groupe');
|
throw Exception('Erreur lors de la création des membres du groupe');
|
||||||
}
|
}
|
||||||
|
|
||||||
groupBloc.add(CreateGroupWithMembers(
|
groupBloc.add(
|
||||||
group: group,
|
CreateGroupWithMembers(group: group, members: groupMembers),
|
||||||
members: groupMembers,
|
);
|
||||||
));
|
|
||||||
final account = Account(
|
final account = Account(
|
||||||
id: '',
|
id: '',
|
||||||
tripId: tripId,
|
tripId: tripId,
|
||||||
name: _titleController.text.trim(),
|
name: _titleController.text.trim(),
|
||||||
);
|
);
|
||||||
|
|
||||||
accountBloc.add(CreateAccountWithMembers(
|
accountBloc.add(
|
||||||
account: account,
|
CreateAccountWithMembers(account: account, members: groupMembers),
|
||||||
members: groupMembers,
|
);
|
||||||
));
|
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
@@ -998,7 +1059,6 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
});
|
});
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError(
|
_errorService.logError(
|
||||||
'create_trip_content.dart',
|
'create_trip_content.dart',
|
||||||
@@ -1007,10 +1067,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(content: Text('Erreur: $e'), backgroundColor: Colors.red),
|
||||||
content: Text('Erreur: $e'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
@@ -1019,8 +1076,6 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Future<void> _saveTrip(user_state.UserModel currentUser) async {
|
Future<void> _saveTrip(user_state.UserModel currentUser) async {
|
||||||
if (!_formKey.currentState!.validate()) {
|
if (!_formKey.currentState!.validate()) {
|
||||||
return;
|
return;
|
||||||
@@ -1043,7 +1098,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final participantsData = await _getParticipantsData(_participants);
|
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)) {
|
if (!participantIds.contains(currentUser.id)) {
|
||||||
participantIds.insert(0, currentUser.id);
|
participantIds.insert(0, currentUser.id);
|
||||||
@@ -1067,17 +1124,16 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
// Géolocaliser le voyage avant de le sauvegarder
|
// Géolocaliser le voyage avant de le sauvegarder
|
||||||
Trip tripWithCoordinates;
|
Trip tripWithCoordinates;
|
||||||
try {
|
try {
|
||||||
print('🌍 [CreateTrip] Géolocalisation en cours pour: ${trip.location}');
|
|
||||||
tripWithCoordinates = await _tripGeocodingService.geocodeTrip(trip);
|
tripWithCoordinates = await _tripGeocodingService.geocodeTrip(trip);
|
||||||
print('✅ [CreateTrip] Géolocalisation réussie: ${tripWithCoordinates.latitude}, ${tripWithCoordinates.longitude}');
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('⚠️ [CreateTrip] Erreur de géolocalisation: $e');
|
|
||||||
// Continuer sans coordonnées en cas d'erreur
|
// Continuer sans coordonnées en cas d'erreur
|
||||||
tripWithCoordinates = trip;
|
tripWithCoordinates = trip;
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
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,
|
backgroundColor: Colors.orange,
|
||||||
duration: Duration(seconds: 2),
|
duration: Duration(seconds: 2),
|
||||||
),
|
),
|
||||||
@@ -1089,15 +1145,22 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
// Mode mise à jour
|
// Mode mise à jour
|
||||||
tripBloc.add(TripUpdateRequested(trip: tripWithCoordinates));
|
tripBloc.add(TripUpdateRequested(trip: tripWithCoordinates));
|
||||||
|
|
||||||
// Vérifier que l'ID du voyage existe avant de mettre à jour le groupe
|
// Mettre à jour le groupe ET les comptes avec les nouveaux participants
|
||||||
if (widget.tripToEdit != null && widget.tripToEdit!.id != null && widget.tripToEdit!.id!.isNotEmpty) {
|
if (widget.tripToEdit != null &&
|
||||||
await _updateGroupMembers(
|
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!,
|
widget.tripToEdit!.id!,
|
||||||
currentUser,
|
currentUser,
|
||||||
participantsData,
|
participantsData,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Mode création - Le groupe sera créé dans le listener TripCreated
|
// Mode création - Le groupe sera créé dans le listener TripCreated
|
||||||
tripBloc.add(TripCreateRequested(trip: tripWithCoordinates));
|
tripBloc.add(TripCreateRequested(trip: tripWithCoordinates));
|
||||||
@@ -1105,10 +1168,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(content: Text('Erreur: $e'), backgroundColor: Colors.red),
|
||||||
content: Text('Erreur: $e'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -1118,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 = [];
|
List<Map<String, dynamic>> participantsData = [];
|
||||||
|
|
||||||
for (String email in emails) {
|
for (String email in emails) {
|
||||||
@@ -1127,11 +1189,13 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
final userDoc = await _userService.getUserById(userId);
|
final userDoc = await _userService.getUserById(userId);
|
||||||
final firstName = userDoc?.prenom ?? 'Utilisateur';
|
final firstName = userDoc?.prenom ?? 'Utilisateur';
|
||||||
|
final lastName = userDoc?.nom ?? '';
|
||||||
final profilePictureUrl = userDoc?.profilePictureUrl;
|
final profilePictureUrl = userDoc?.profilePictureUrl;
|
||||||
|
|
||||||
participantsData.add({
|
participantsData.add({
|
||||||
'id': userId,
|
'id': userId,
|
||||||
'firstName': firstName,
|
'firstName': firstName,
|
||||||
|
'lastName': lastName,
|
||||||
'profilePictureUrl': profilePictureUrl,
|
'profilePictureUrl': profilePictureUrl,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -1160,8 +1224,5 @@ class PlaceSuggestion {
|
|||||||
final String placeId;
|
final String placeId;
|
||||||
final String description;
|
final String description;
|
||||||
|
|
||||||
PlaceSuggestion({
|
PlaceSuggestion({required this.placeId, required this.description});
|
||||||
required this.placeId,
|
}
|
||||||
required this.description,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -134,17 +134,7 @@ class _HomeContentState extends State<HomeContent>
|
|||||||
: Colors.black,
|
: Colors.black,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 16),
|
||||||
Text(
|
|
||||||
'Vos voyages',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
color: Theme.of(context).brightness == Brightness.dark
|
|
||||||
? Colors.white70
|
|
||||||
: Colors.grey[600],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
|
|
||||||
if (tripState is TripLoading || tripState is TripCreated)
|
if (tripState is TripLoading || tripState is TripCreated)
|
||||||
_buildLoadingState()
|
_buildLoadingState()
|
||||||
|
|||||||
@@ -11,7 +11,11 @@ import 'package:travel_mate/components/map/map_content.dart';
|
|||||||
import 'package:travel_mate/services/error_service.dart';
|
import 'package:travel_mate/services/error_service.dart';
|
||||||
import 'package:travel_mate/services/activity_cache_service.dart';
|
import 'package:travel_mate/services/activity_cache_service.dart';
|
||||||
import 'package:travel_mate/repositories/group_repository.dart';
|
import 'package:travel_mate/repositories/group_repository.dart';
|
||||||
|
import 'package:travel_mate/repositories/user_repository.dart';
|
||||||
|
import 'package:travel_mate/repositories/account_repository.dart';
|
||||||
|
import 'package:travel_mate/models/group_member.dart';
|
||||||
import 'package:travel_mate/components/activities/activities_page.dart';
|
import 'package:travel_mate/components/activities/activities_page.dart';
|
||||||
|
import 'package:travel_mate/components/home/calendar/calendar_page.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class ShowTripDetailsContent extends StatefulWidget {
|
class ShowTripDetailsContent extends StatefulWidget {
|
||||||
@@ -26,6 +30,8 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
final ErrorService _errorService = ErrorService();
|
final ErrorService _errorService = ErrorService();
|
||||||
final ActivityCacheService _cacheService = ActivityCacheService();
|
final ActivityCacheService _cacheService = ActivityCacheService();
|
||||||
final GroupRepository _groupRepository = GroupRepository();
|
final GroupRepository _groupRepository = GroupRepository();
|
||||||
|
final UserRepository _userRepository = UserRepository();
|
||||||
|
final AccountRepository _accountRepository = AccountRepository();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -89,12 +95,13 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
// Méthode pour afficher le dialogue de sélection de carte
|
// Méthode pour afficher le dialogue de sélection de carte
|
||||||
void _showMapOptions() {
|
void _showMapOptions() {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
backgroundColor: theme.dialogBackgroundColor,
|
backgroundColor:
|
||||||
|
theme.dialogTheme.backgroundColor ?? theme.colorScheme.surface,
|
||||||
title: Text(
|
title: Text(
|
||||||
'Ouvrir la carte',
|
'Ouvrir la carte',
|
||||||
style: theme.textTheme.titleLarge?.copyWith(
|
style: theme.textTheme.titleLarge?.copyWith(
|
||||||
@@ -188,7 +195,7 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
// Méthode pour ouvrir Google Maps
|
// Méthode pour ouvrir Google Maps
|
||||||
Future<void> _openGoogleMaps() async {
|
Future<void> _openGoogleMaps() async {
|
||||||
final location = Uri.encodeComponent(widget.trip.location);
|
final location = Uri.encodeComponent(widget.trip.location);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Essayer d'abord l'URL scheme pour l'app mobile
|
// Essayer d'abord l'URL scheme pour l'app mobile
|
||||||
final appUrl = 'comgooglemaps://?q=$location';
|
final appUrl = 'comgooglemaps://?q=$location';
|
||||||
@@ -197,17 +204,19 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
await launchUrl(appUri);
|
await launchUrl(appUri);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback vers l'URL web
|
// Fallback vers l'URL web
|
||||||
final webUrl = 'https://www.google.com/maps/search/?api=1&query=$location';
|
final webUrl =
|
||||||
|
'https://www.google.com/maps/search/?api=1&query=$location';
|
||||||
final webUri = Uri.parse(webUrl);
|
final webUri = Uri.parse(webUrl);
|
||||||
if (await canLaunchUrl(webUri)) {
|
if (await canLaunchUrl(webUri)) {
|
||||||
await launchUrl(webUri, mode: LaunchMode.externalApplication);
|
await launchUrl(webUri, mode: LaunchMode.externalApplication);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_errorService.showError(
|
_errorService.showError(
|
||||||
message: 'Impossible d\'ouvrir Google Maps. Vérifiez que l\'application est installée.',
|
message:
|
||||||
|
'Impossible d\'ouvrir Google Maps. Vérifiez que l\'application est installée.',
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.showError(
|
_errorService.showError(
|
||||||
@@ -219,7 +228,7 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
// Méthode pour ouvrir Waze
|
// Méthode pour ouvrir Waze
|
||||||
Future<void> _openWaze() async {
|
Future<void> _openWaze() async {
|
||||||
final location = Uri.encodeComponent(widget.trip.location);
|
final location = Uri.encodeComponent(widget.trip.location);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Essayer d'abord l'URL scheme pour l'app mobile
|
// Essayer d'abord l'URL scheme pour l'app mobile
|
||||||
final appUrl = 'waze://?q=$location';
|
final appUrl = 'waze://?q=$location';
|
||||||
@@ -228,7 +237,7 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
await launchUrl(appUri);
|
await launchUrl(appUri);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback vers l'URL web
|
// Fallback vers l'URL web
|
||||||
final webUrl = 'https://waze.com/ul?q=$location';
|
final webUrl = 'https://waze.com/ul?q=$location';
|
||||||
final webUri = Uri.parse(webUrl);
|
final webUri = Uri.parse(webUrl);
|
||||||
@@ -236,14 +245,13 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
await launchUrl(webUri, mode: LaunchMode.externalApplication);
|
await launchUrl(webUri, mode: LaunchMode.externalApplication);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_errorService.showError(
|
_errorService.showError(
|
||||||
message: 'Impossible d\'ouvrir Waze. Vérifiez que l\'application est installée.',
|
message:
|
||||||
|
'Impossible d\'ouvrir Waze. Vérifiez que l\'application est installée.',
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.showError(
|
_errorService.showError(message: 'Erreur lors de l\'ouverture de Waze');
|
||||||
message: 'Erreur lors de l\'ouverture de Waze',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,9 +259,11 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final isDarkMode = theme.brightness == Brightness.dark;
|
final isDarkMode = theme.brightness == Brightness.dark;
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: isDarkMode ? theme.scaffoldBackgroundColor : Colors.grey[50],
|
backgroundColor: isDarkMode
|
||||||
|
? theme.scaffoldBackgroundColor
|
||||||
|
: Colors.grey[50],
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
@@ -287,7 +297,7 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: Colors.black.withValues(alpha:0.1),
|
color: Colors.black.withValues(alpha: 0.1),
|
||||||
blurRadius: 10,
|
blurRadius: 10,
|
||||||
offset: const Offset(0, 5),
|
offset: const Offset(0, 5),
|
||||||
),
|
),
|
||||||
@@ -295,16 +305,19 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
),
|
),
|
||||||
child: ClipRRect(
|
child: ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
child: widget.trip.imageUrl != null && widget.trip.imageUrl!.isNotEmpty
|
child:
|
||||||
|
widget.trip.imageUrl != null &&
|
||||||
|
widget.trip.imageUrl!.isNotEmpty
|
||||||
? Image.network(
|
? Image.network(
|
||||||
widget.trip.imageUrl!,
|
widget.trip.imageUrl!,
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
errorBuilder: (context, error, stackTrace) => _buildPlaceholderImage(),
|
errorBuilder: (context, error, stackTrace) =>
|
||||||
|
_buildPlaceholderImage(),
|
||||||
)
|
)
|
||||||
: _buildPlaceholderImage(),
|
: _buildPlaceholderImage(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// Contenu principal
|
// Contenu principal
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
@@ -313,21 +326,24 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
children: [
|
children: [
|
||||||
// Section "Départ dans X jours"
|
// Section "Départ dans X jours"
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 16,
|
||||||
|
vertical: 12,
|
||||||
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: theme.cardColor,
|
color: theme.cardColor,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: isDarkMode
|
color: isDarkMode
|
||||||
? Colors.white.withValues(alpha:0.1)
|
? Colors.white.withValues(alpha: 0.1)
|
||||||
: Colors.black.withValues(alpha:0.1),
|
: Colors.black.withValues(alpha: 0.1),
|
||||||
width: 1,
|
width: 1,
|
||||||
),
|
),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: isDarkMode
|
color: isDarkMode
|
||||||
? Colors.black.withValues(alpha:0.3)
|
? Colors.black.withValues(alpha: 0.3)
|
||||||
: Colors.black.withValues(alpha:0.1),
|
: Colors.black.withValues(alpha: 0.1),
|
||||||
blurRadius: isDarkMode ? 8 : 5,
|
blurRadius: isDarkMode ? 8 : 5,
|
||||||
offset: const Offset(0, 2),
|
offset: const Offset(0, 2),
|
||||||
),
|
),
|
||||||
@@ -338,7 +354,7 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.teal.withValues(alpha:0.1),
|
color: Colors.teal.withValues(alpha: 0.1),
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
child: Icon(
|
child: Icon(
|
||||||
@@ -354,11 +370,15 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
Text(
|
Text(
|
||||||
'Départ dans',
|
'Départ dans',
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
color: theme.colorScheme.onSurface.withValues(alpha:0.6),
|
color: theme.colorScheme.onSurface.withValues(
|
||||||
|
alpha: 0.6,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
daysUntilTrip > 0 ? '$daysUntilTrip Jours' : 'Voyage terminé',
|
daysUntilTrip > 0
|
||||||
|
? '$daysUntilTrip Jours'
|
||||||
|
: 'Voyage terminé',
|
||||||
style: theme.textTheme.titleMedium?.copyWith(
|
style: theme.textTheme.titleMedium?.copyWith(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: theme.colorScheme.onSurface,
|
color: theme.colorScheme.onSurface,
|
||||||
@@ -367,7 +387,9 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
Text(
|
Text(
|
||||||
widget.trip.formattedDates,
|
widget.trip.formattedDates,
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
color: theme.colorScheme.onSurface.withValues(alpha:0.6),
|
color: theme.colorScheme.onSurface.withValues(
|
||||||
|
alpha: 0.6,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -375,9 +397,9 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
|
|
||||||
// Section Participants
|
// Section Participants
|
||||||
Text(
|
Text(
|
||||||
'Participants',
|
'Participants',
|
||||||
@@ -387,12 +409,12 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
|
|
||||||
// Afficher les participants avec leurs images
|
// Afficher les participants avec leurs images
|
||||||
_buildParticipantsSection(),
|
_buildParticipantsSection(),
|
||||||
|
|
||||||
const SizedBox(height: 32),
|
const SizedBox(height: 32),
|
||||||
|
|
||||||
// Grille d'actions
|
// Grille d'actions
|
||||||
GridView.count(
|
GridView.count(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
@@ -406,7 +428,13 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
icon: Icons.calendar_today,
|
icon: Icons.calendar_today,
|
||||||
title: 'Calendrier',
|
title: 'Calendrier',
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
onTap: () => _showComingSoon('Calendrier'),
|
onTap: () => Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
CalendarPage(trip: widget.trip),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
_buildActionButton(
|
_buildActionButton(
|
||||||
icon: Icons.local_activity,
|
icon: Icons.local_activity,
|
||||||
@@ -428,6 +456,9 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 32),
|
||||||
|
_buildNextActivitiesSection(),
|
||||||
|
_buildExpensesCard(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -444,18 +475,11 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(Icons.location_city, size: 48, color: Colors.grey),
|
||||||
Icons.location_city,
|
|
||||||
size: 48,
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
SizedBox(height: 8),
|
SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
'Aucune image',
|
'Aucune image',
|
||||||
style: TextStyle(
|
style: TextStyle(color: Colors.grey, fontSize: 14),
|
||||||
color: Colors.grey,
|
|
||||||
fontSize: 14,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -471,7 +495,7 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
}) {
|
}) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final isDarkMode = theme.brightness == Brightness.dark;
|
final isDarkMode = theme.brightness == Brightness.dark;
|
||||||
|
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
@@ -481,16 +505,16 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
color: theme.cardColor,
|
color: theme.cardColor,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: isDarkMode
|
color: isDarkMode
|
||||||
? Colors.white.withValues(alpha:0.1)
|
? Colors.white.withValues(alpha: 0.1)
|
||||||
: Colors.black.withValues(alpha:0.1),
|
: Colors.black.withValues(alpha: 0.1),
|
||||||
width: 1,
|
width: 1,
|
||||||
),
|
),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: isDarkMode
|
color: isDarkMode
|
||||||
? Colors.black.withValues(alpha:0.3)
|
? Colors.black.withValues(alpha: 0.3)
|
||||||
: Colors.black.withValues(alpha:0.1),
|
: Colors.black.withValues(alpha: 0.1),
|
||||||
blurRadius: isDarkMode ? 8 : 5,
|
blurRadius: isDarkMode ? 8 : 5,
|
||||||
offset: const Offset(0, 2),
|
offset: const Offset(0, 2),
|
||||||
),
|
),
|
||||||
@@ -505,11 +529,7 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
color: color.withValues(alpha: 0.1),
|
color: color.withValues(alpha: 0.1),
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
child: Icon(
|
child: Icon(icon, color: color, size: 24),
|
||||||
icon,
|
|
||||||
color: color,
|
|
||||||
size: 24,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
@@ -537,7 +557,7 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
|
|
||||||
void _showOptionsMenu() {
|
void _showOptionsMenu() {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
backgroundColor: theme.bottomSheetTheme.backgroundColor,
|
backgroundColor: theme.bottomSheetTheme.backgroundColor,
|
||||||
@@ -589,11 +609,12 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
|
|
||||||
void _showDeleteConfirmation() {
|
void _showDeleteConfirmation() {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
backgroundColor: theme.dialogBackgroundColor,
|
backgroundColor:
|
||||||
|
theme.dialogTheme.backgroundColor ?? theme.colorScheme.surface,
|
||||||
title: Text(
|
title: Text(
|
||||||
'Confirmer la suppression',
|
'Confirmer la suppression',
|
||||||
style: theme.textTheme.titleLarge?.copyWith(
|
style: theme.textTheme.titleLarge?.copyWith(
|
||||||
@@ -622,10 +643,7 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
Navigator.pop(context, true);
|
Navigator.pop(context, true);
|
||||||
},
|
},
|
||||||
child: const Text(
|
child: const Text('Supprimer', style: TextStyle(color: Colors.red)),
|
||||||
'Supprimer',
|
|
||||||
style: TextStyle(color: Colors.red),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -641,50 +659,63 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
|
|
||||||
return FutureBuilder(
|
return FutureBuilder(
|
||||||
future: _groupRepository.getGroupByTripId(widget.trip.id!),
|
future: _groupRepository.getGroupByTripId(widget.trip.id!),
|
||||||
builder: (context, snapshot) {
|
builder: (context, groupSnapshot) {
|
||||||
// En attente
|
if (groupSnapshot.connectionState == ConnectionState.waiting) {
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Erreur
|
if (groupSnapshot.hasError ||
|
||||||
if (snapshot.hasError) {
|
!groupSnapshot.hasData ||
|
||||||
return Center(
|
groupSnapshot.data == null) {
|
||||||
child: Text(
|
|
||||||
'Erreur: ${snapshot.error}',
|
|
||||||
style: TextStyle(color: Colors.red),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pas de groupe trouvé
|
|
||||||
if (!snapshot.hasData || snapshot.data == null) {
|
|
||||||
return const Center(child: Text('Aucun participant'));
|
return const Center(child: Text('Aucun participant'));
|
||||||
}
|
}
|
||||||
|
|
||||||
final group = snapshot.data!;
|
final groupId = groupSnapshot.data!.id;
|
||||||
final members = group.members;
|
|
||||||
|
|
||||||
if (members.isEmpty) {
|
return StreamBuilder<List<GroupMember>>(
|
||||||
return const Center(child: Text('Aucun participant'));
|
stream: _groupRepository.watchGroupMembers(groupId),
|
||||||
}
|
builder: (context, snapshot) {
|
||||||
|
// En attente
|
||||||
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
|
||||||
return SingleChildScrollView(
|
// Erreur
|
||||||
scrollDirection: Axis.horizontal,
|
if (snapshot.hasError) {
|
||||||
child: Row(
|
return Center(
|
||||||
children: [
|
child: Text(
|
||||||
...List.generate(
|
'Erreur: ${snapshot.error}',
|
||||||
members.length,
|
style: TextStyle(color: Colors.red),
|
||||||
(index) {
|
),
|
||||||
final member = members[index];
|
);
|
||||||
return Padding(
|
}
|
||||||
|
|
||||||
|
final members = snapshot.data ?? [];
|
||||||
|
|
||||||
|
if (members.isEmpty) {
|
||||||
|
return const Center(child: Text('Aucun participant'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return SingleChildScrollView(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
...List.generate(members.length, (index) {
|
||||||
|
final member = members[index];
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 12),
|
||||||
|
child: _buildParticipantAvatar(member),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
// Bouton "+" pour ajouter un participant
|
||||||
|
Padding(
|
||||||
padding: const EdgeInsets.only(right: 12),
|
padding: const EdgeInsets.only(right: 12),
|
||||||
child: _buildParticipantAvatar(member),
|
child: _buildAddParticipantButton(),
|
||||||
);
|
),
|
||||||
},
|
],
|
||||||
),
|
),
|
||||||
],
|
);
|
||||||
),
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -695,7 +726,9 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final initials = member.pseudo.isNotEmpty
|
final initials = member.pseudo.isNotEmpty
|
||||||
? member.pseudo[0].toUpperCase()
|
? member.pseudo[0].toUpperCase()
|
||||||
: (member.firstName.isNotEmpty ? member.firstName[0].toUpperCase() : '?');
|
: (member.firstName.isNotEmpty
|
||||||
|
? member.firstName[0].toUpperCase()
|
||||||
|
: '?');
|
||||||
|
|
||||||
final name = member.pseudo.isNotEmpty ? member.pseudo : member.firstName;
|
final name = member.pseudo.isNotEmpty ? member.pseudo : member.firstName;
|
||||||
|
|
||||||
@@ -719,11 +752,14 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
child: CircleAvatar(
|
child: CircleAvatar(
|
||||||
radius: 28,
|
radius: 28,
|
||||||
backgroundColor: theme.colorScheme.primary.withValues(alpha: 0.2),
|
backgroundColor: theme.colorScheme.primary.withValues(alpha: 0.2),
|
||||||
backgroundImage: (member.profilePictureUrl != null &&
|
backgroundImage:
|
||||||
member.profilePictureUrl!.isNotEmpty)
|
(member.profilePictureUrl != null &&
|
||||||
|
member.profilePictureUrl!.isNotEmpty)
|
||||||
? NetworkImage(member.profilePictureUrl!)
|
? NetworkImage(member.profilePictureUrl!)
|
||||||
: null,
|
: null,
|
||||||
child: (member.profilePictureUrl == null || member.profilePictureUrl!.isEmpty)
|
child:
|
||||||
|
(member.profilePictureUrl == null ||
|
||||||
|
member.profilePictureUrl!.isEmpty)
|
||||||
? Text(
|
? Text(
|
||||||
initials,
|
initials,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@@ -738,6 +774,191 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Construire le bouton pour ajouter un participant
|
||||||
|
Widget _buildAddParticipantButton() {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
return Tooltip(
|
||||||
|
message: 'Ajouter un participant',
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
border: Border.all(
|
||||||
|
color: theme.colorScheme.primary.withValues(alpha: 0.3),
|
||||||
|
width: 2,
|
||||||
|
),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withValues(alpha: 0.1),
|
||||||
|
blurRadius: 4,
|
||||||
|
offset: const Offset(0, 2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: _showAddParticipantDialog,
|
||||||
|
child: CircleAvatar(
|
||||||
|
radius: 28,
|
||||||
|
backgroundColor: theme.colorScheme.primary.withValues(alpha: 0.1),
|
||||||
|
child: Icon(Icons.add, color: theme.colorScheme.primary, size: 28),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Afficher le dialogue pour ajouter un participant
|
||||||
|
void _showAddParticipantDialog() {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final TextEditingController emailController = TextEditingController();
|
||||||
|
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
backgroundColor:
|
||||||
|
theme.dialogTheme.backgroundColor ?? theme.colorScheme.surface,
|
||||||
|
title: Text(
|
||||||
|
'Ajouter un participant',
|
||||||
|
style: theme.textTheme.titleLarge?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Entrez l\'email du participant à ajouter :',
|
||||||
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
TextField(
|
||||||
|
controller: emailController,
|
||||||
|
keyboardType: TextInputType.emailAddress,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'participant@example.com',
|
||||||
|
hintStyle: TextStyle(
|
||||||
|
color: theme.colorScheme.onSurface.withValues(alpha: 0.5),
|
||||||
|
),
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
contentPadding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 16,
|
||||||
|
vertical: 12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
style: TextStyle(color: theme.colorScheme.onSurface),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: Text(
|
||||||
|
'Annuler',
|
||||||
|
style: TextStyle(color: theme.colorScheme.primary),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
if (emailController.text.isNotEmpty) {
|
||||||
|
_addParticipantByEmail(emailController.text);
|
||||||
|
Navigator.pop(context);
|
||||||
|
} else {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('Veuillez entrer un email valide'),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Text(
|
||||||
|
'Ajouter',
|
||||||
|
style: TextStyle(color: theme.colorScheme.primary),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Ajouter un participant par email
|
||||||
|
Future<void> _addParticipantByEmail(String email) async {
|
||||||
|
try {
|
||||||
|
// Chercher l'utilisateur par email
|
||||||
|
final user = await _userRepository.getUserByEmail(email);
|
||||||
|
|
||||||
|
if (user == null) {
|
||||||
|
_errorService.showError(
|
||||||
|
message: 'Utilisateur non trouvé avec cet email',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.id == null) {
|
||||||
|
_errorService.showError(message: 'ID utilisateur invalide');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajouter l'utilisateur au groupe
|
||||||
|
if (widget.trip.id != null) {
|
||||||
|
final group = await _groupRepository.getGroupByTripId(widget.trip.id!);
|
||||||
|
if (group != null) {
|
||||||
|
// Créer un GroupMember à partir du User
|
||||||
|
final newMember = GroupMember(
|
||||||
|
userId: user.id!,
|
||||||
|
firstName: user.prenom,
|
||||||
|
lastName: user.nom,
|
||||||
|
pseudo: user.prenom,
|
||||||
|
profilePictureUrl: user.profilePictureUrl,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Ajouter le membre au groupe
|
||||||
|
await _groupRepository.addMember(group.id, newMember);
|
||||||
|
|
||||||
|
// Ajouter le membre au compte
|
||||||
|
final account = await _accountRepository.getAccountByTripId(
|
||||||
|
widget.trip.id!,
|
||||||
|
);
|
||||||
|
if (account != null) {
|
||||||
|
await _accountRepository.addMemberToAccount(account.id, newMember);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mettre à jour la liste des participants du voyage
|
||||||
|
final newParticipants = [...widget.trip.participants, user.id!];
|
||||||
|
final updatedTrip = widget.trip.copyWith(
|
||||||
|
participants: newParticipants,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
context.read<TripBloc>().add(
|
||||||
|
TripUpdateRequested(trip: updatedTrip),
|
||||||
|
);
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('${user.prenom} a été ajouté au voyage'),
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Rafraîchir la page
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
_errorService.showError(
|
||||||
|
message: 'Erreur lors de l\'ajout du participant: $e',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _navigateToActivities() {
|
void _navigateToActivities() {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
@@ -746,4 +967,175 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildNextActivitiesSection() {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Prochaines activités',
|
||||||
|
style: theme.textTheme.titleMedium?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: theme.colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => _navigateToActivities(),
|
||||||
|
child: Text(
|
||||||
|
'Tout voir',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.teal,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
_buildActivityCard(
|
||||||
|
title: 'Visite du Colisée',
|
||||||
|
date: '11 août, 10:00',
|
||||||
|
icon: Icons.museum,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
_buildActivityCard(
|
||||||
|
title: 'Dîner à Trastevere',
|
||||||
|
date: '11 août, 20:30',
|
||||||
|
icon: Icons.restaurant,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildActivityCard({
|
||||||
|
required String title,
|
||||||
|
required String date,
|
||||||
|
required IconData icon,
|
||||||
|
}) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final isDarkMode = theme.brightness == Brightness.dark;
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.cardColor,
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
border: Border.all(
|
||||||
|
color: isDarkMode
|
||||||
|
? Colors.white.withValues(alpha: 0.1)
|
||||||
|
: Colors.black.withValues(alpha: 0.05),
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withValues(alpha: 0.05),
|
||||||
|
blurRadius: 10,
|
||||||
|
offset: const Offset(0, 2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.teal.withValues(alpha: 0.1),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Icon(icon, color: Colors.teal, size: 24),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
title,
|
||||||
|
style: theme.textTheme.bodyLarge?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: theme.colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text(
|
||||||
|
date,
|
||||||
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurface.withValues(alpha: 0.6),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Icon(
|
||||||
|
Icons.chevron_right,
|
||||||
|
color: theme.colorScheme.onSurface.withValues(alpha: 0.4),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildExpensesCard() {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
margin: const EdgeInsets.only(top: 24),
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: const Color(0xFFFDF4E3), // Light beige background
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.all(10),
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
color: Colors.orange,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.warning_amber_rounded,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 24,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Dépenses',
|
||||||
|
style: theme.textTheme.bodyLarge?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: const Color(0xFF5D4037), // Brown text
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text(
|
||||||
|
'Vous devez 25€ à Clara',
|
||||||
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: const Color(0xFF8D6E63), // Lighter brown
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => _showComingSoon('Régler les dépenses'),
|
||||||
|
child: Text(
|
||||||
|
'Régler',
|
||||||
|
style: TextStyle(
|
||||||
|
color: const Color(0xFF5D4037),
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class _LoadingContentState extends State<LoadingContent>
|
|||||||
widget.onComplete!();
|
widget.onComplete!();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} 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 _isLoadingLocation = false;
|
||||||
bool _isSearching = false;
|
bool _isSearching = false;
|
||||||
Position? _currentPosition;
|
Position? _currentPosition;
|
||||||
|
|
||||||
final Set<Marker> _markers = {};
|
final Set<Marker> _markers = {};
|
||||||
final Set<Circle> _circles = {};
|
final Set<Circle> _circles = {};
|
||||||
|
|
||||||
List<PlaceSuggestion> _suggestions = [];
|
List<PlaceSuggestion> _suggestions = [];
|
||||||
|
|
||||||
static final String _apiKey = dotenv.env['GOOGLE_MAPS_API_KEY'] ?? '';
|
static final String _apiKey = dotenv.env['GOOGLE_MAPS_API_KEY'] ?? '';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
// Si une recherche initiale est fournie, la pré-remplir et lancer la recherche
|
// 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!;
|
_searchController.text = widget.initialSearchQuery!;
|
||||||
// Lancer la recherche automatiquement après un court délai pour laisser l'interface se charger
|
// Lancer la recherche automatiquement après un court délai pour laisser l'interface se charger
|
||||||
Future.delayed(const Duration(milliseconds: 500), () {
|
Future.delayed(const Duration(milliseconds: 500), () {
|
||||||
@@ -65,17 +66,19 @@ class _MapContentState extends State<MapContent> {
|
|||||||
'https://maps.googleapis.com/maps/api/place/autocomplete/json'
|
'https://maps.googleapis.com/maps/api/place/autocomplete/json'
|
||||||
'?input=${Uri.encodeComponent(query)}'
|
'?input=${Uri.encodeComponent(query)}'
|
||||||
'&key=$_apiKey'
|
'&key=$_apiKey'
|
||||||
'&language=fr'
|
'&language=fr',
|
||||||
);
|
);
|
||||||
|
|
||||||
final response = await http.get(url);
|
final response = await http.get(url);
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
|
|
||||||
if (data['status'] == 'OK') {
|
if (data['status'] == 'OK') {
|
||||||
final predictions = data['predictions'] as List;
|
final predictions = data['predictions'] as List;
|
||||||
|
|
||||||
if (predictions.isNotEmpty) {
|
if (predictions.isNotEmpty) {
|
||||||
// Prendre automatiquement la première suggestion
|
// Prendre automatiquement la première suggestion
|
||||||
final firstPrediction = predictions.first;
|
final firstPrediction = predictions.first;
|
||||||
@@ -83,7 +86,7 @@ class _MapContentState extends State<MapContent> {
|
|||||||
placeId: firstPrediction['place_id'],
|
placeId: firstPrediction['place_id'],
|
||||||
description: firstPrediction['description'],
|
description: firstPrediction['description'],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Effectuer la sélection automatique
|
// Effectuer la sélection automatique
|
||||||
await _selectPlaceForInitialSearch(suggestion);
|
await _selectPlaceForInitialSearch(suggestion);
|
||||||
} else {
|
} else {
|
||||||
@@ -117,9 +120,11 @@ class _MapContentState extends State<MapContent> {
|
|||||||
|
|
||||||
final response = await http.get(url);
|
final response = await http.get(url);
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
|
|
||||||
if (data['status'] == 'OK') {
|
if (data['status'] == 'OK') {
|
||||||
final location = data['result']['geometry']['location'];
|
final location = data['result']['geometry']['location'];
|
||||||
final lat = location['lat'];
|
final lat = location['lat'];
|
||||||
@@ -132,7 +137,7 @@ class _MapContentState extends State<MapContent> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
// Garder le marqueur de position utilisateur s'il existe
|
// Garder le marqueur de position utilisateur s'il existe
|
||||||
_markers.removeWhere((m) => m.markerId.value != 'user_location');
|
_markers.removeWhere((m) => m.markerId.value != 'user_location');
|
||||||
|
|
||||||
// Ajouter le nouveau marqueur de lieu
|
// Ajouter le nouveau marqueur de lieu
|
||||||
_markers.add(
|
_markers.add(
|
||||||
Marker(
|
Marker(
|
||||||
@@ -230,9 +235,7 @@ class _MapContentState extends State<MapContent> {
|
|||||||
const size = 120.0;
|
const size = 120.0;
|
||||||
|
|
||||||
// Dessiner l'icône person_pin_circle en bleu
|
// Dessiner l'icône person_pin_circle en bleu
|
||||||
final iconPainter = TextPainter(
|
final iconPainter = TextPainter(textDirection: TextDirection.ltr);
|
||||||
textDirection: TextDirection.ltr,
|
|
||||||
);
|
|
||||||
iconPainter.text = TextSpan(
|
iconPainter.text = TextSpan(
|
||||||
text: String.fromCharCode(Icons.person_pin_circle.codePoint),
|
text: String.fromCharCode(Icons.person_pin_circle.codePoint),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@@ -242,26 +245,20 @@ class _MapContentState extends State<MapContent> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
iconPainter.layout();
|
iconPainter.layout();
|
||||||
iconPainter.paint(
|
iconPainter.paint(canvas, Offset((size - iconPainter.width) / 2, 0));
|
||||||
canvas,
|
|
||||||
Offset(
|
|
||||||
(size - iconPainter.width) / 2,
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
final picture = pictureRecorder.endRecording();
|
final picture = pictureRecorder.endRecording();
|
||||||
final image = await picture.toImage(size.toInt(), size.toInt());
|
final image = await picture.toImage(size.toInt(), size.toInt());
|
||||||
final bytes = await image.toByteData(format: ui.ImageByteFormat.png);
|
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
|
// Ajouter le marqueur avec l'icône personnalisée
|
||||||
Future<void> _addUserLocationMarker(LatLng position) async {
|
Future<void> _addUserLocationMarker(LatLng position) async {
|
||||||
_markers.clear();
|
_markers.clear();
|
||||||
_circles.clear();
|
_circles.clear();
|
||||||
|
|
||||||
// Ajouter un cercle de précision
|
// Ajouter un cercle de précision
|
||||||
_circles.add(
|
_circles.add(
|
||||||
Circle(
|
Circle(
|
||||||
@@ -284,10 +281,14 @@ class _MapContentState extends State<MapContent> {
|
|||||||
markerId: const MarkerId('user_location'),
|
markerId: const MarkerId('user_location'),
|
||||||
position: position,
|
position: position,
|
||||||
icon: icon,
|
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(
|
infoWindow: InfoWindow(
|
||||||
title: 'Ma position',
|
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'
|
'https://maps.googleapis.com/maps/api/place/autocomplete/json'
|
||||||
'?input=${Uri.encodeComponent(query)}'
|
'?input=${Uri.encodeComponent(query)}'
|
||||||
'&key=$_apiKey'
|
'&key=$_apiKey'
|
||||||
'&language=fr'
|
'&language=fr',
|
||||||
);
|
);
|
||||||
|
|
||||||
final response = await http.get(url);
|
final response = await http.get(url);
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
|
|
||||||
if (data['status'] == 'OK') {
|
if (data['status'] == 'OK') {
|
||||||
final predictions = data['predictions'] as List;
|
final predictions = data['predictions'] as List;
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_suggestions = predictions
|
_suggestions = predictions
|
||||||
.map((p) => PlaceSuggestion(
|
.map(
|
||||||
placeId: p['place_id'],
|
(p) => PlaceSuggestion(
|
||||||
description: p['description'],
|
placeId: p['place_id'],
|
||||||
))
|
description: p['description'],
|
||||||
|
),
|
||||||
|
)
|
||||||
.toList();
|
.toList();
|
||||||
_isSearching = false;
|
_isSearching = false;
|
||||||
});
|
});
|
||||||
@@ -363,9 +368,11 @@ class _MapContentState extends State<MapContent> {
|
|||||||
|
|
||||||
final response = await http.get(url);
|
final response = await http.get(url);
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
|
|
||||||
if (data['status'] == 'OK') {
|
if (data['status'] == 'OK') {
|
||||||
final location = data['result']['geometry']['location'];
|
final location = data['result']['geometry']['location'];
|
||||||
final lat = location['lat'];
|
final lat = location['lat'];
|
||||||
@@ -378,7 +385,7 @@ class _MapContentState extends State<MapContent> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
// Garder le marqueur de position utilisateur
|
// Garder le marqueur de position utilisateur
|
||||||
_markers.removeWhere((m) => m.markerId.value != 'user_location');
|
_markers.removeWhere((m) => m.markerId.value != 'user_location');
|
||||||
|
|
||||||
// Ajouter le nouveau marqueur de lieu
|
// Ajouter le nouveau marqueur de lieu
|
||||||
_markers.add(
|
_markers.add(
|
||||||
Marker(
|
Marker(
|
||||||
@@ -394,7 +401,9 @@ class _MapContentState extends State<MapContent> {
|
|||||||
CameraUpdate.newLatLngZoom(newPosition, 15),
|
CameraUpdate.newLatLngZoom(newPosition, 15),
|
||||||
);
|
);
|
||||||
|
|
||||||
FocusScope.of(context).unfocus();
|
if (mounted) {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -545,7 +554,10 @@ class _MapContentState extends State<MapContent> {
|
|||||||
: Icon(Icons.search, color: Colors.grey[700]),
|
: Icon(Icons.search, color: Colors.grey[700]),
|
||||||
suffixIcon: _searchController.text.isNotEmpty
|
suffixIcon: _searchController.text.isNotEmpty
|
||||||
? IconButton(
|
? IconButton(
|
||||||
icon: Icon(Icons.clear, color: Colors.grey[700]),
|
icon: Icon(
|
||||||
|
Icons.clear,
|
||||||
|
color: Colors.grey[700],
|
||||||
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_searchController.clear();
|
_searchController.clear();
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -567,7 +579,8 @@ class _MapContentState extends State<MapContent> {
|
|||||||
),
|
),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
// Ne pas rechercher si c'est juste le remplissage initial
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
_searchPlaces(value);
|
_searchPlaces(value);
|
||||||
@@ -601,10 +614,8 @@ class _MapContentState extends State<MapContent> {
|
|||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
itemCount: _suggestions.length,
|
itemCount: _suggestions.length,
|
||||||
separatorBuilder: (context, index) => Divider(
|
separatorBuilder: (context, index) =>
|
||||||
height: 1,
|
Divider(height: 1, color: Colors.grey[300]),
|
||||||
color: Colors.grey[300],
|
|
||||||
),
|
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final suggestion = _suggestions[index];
|
final suggestion = _suggestions[index];
|
||||||
return InkWell(
|
return InkWell(
|
||||||
@@ -664,8 +675,5 @@ class PlaceSuggestion {
|
|||||||
final String placeId;
|
final String placeId;
|
||||||
final String description;
|
final String description;
|
||||||
|
|
||||||
PlaceSuggestion({
|
PlaceSuggestion({required this.placeId, required this.description});
|
||||||
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_state.dart' as user_state;
|
||||||
import '../../../blocs/user/user_event.dart' as user_event;
|
import '../../../blocs/user/user_event.dart' as user_event;
|
||||||
import '../../../services/auth_service.dart';
|
import '../../../services/auth_service.dart';
|
||||||
|
import '../../../services/logger_service.dart';
|
||||||
|
|
||||||
class ProfileContent extends StatelessWidget {
|
class ProfileContent extends StatelessWidget {
|
||||||
ProfileContent({super.key});
|
ProfileContent({super.key});
|
||||||
@@ -19,7 +20,8 @@ class ProfileContent extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return UserStateWrapper(
|
return UserStateWrapper(
|
||||||
builder: (context, user) {
|
builder: (context, user) {
|
||||||
final isEmailAuth = user.authMethod == 'email' || user.authMethod == null;
|
final isEmailAuth =
|
||||||
|
user.authMethod == 'email' || user.authMethod == null;
|
||||||
|
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -40,10 +42,12 @@ class ProfileContent extends StatelessWidget {
|
|||||||
color: Colors.black.withValues(alpha: 0.1),
|
color: Colors.black.withValues(alpha: 0.1),
|
||||||
blurRadius: 8,
|
blurRadius: 8,
|
||||||
offset: Offset(0, 2),
|
offset: Offset(0, 2),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: user.profilePictureUrl != null && user.profilePictureUrl!.isNotEmpty
|
child:
|
||||||
|
user.profilePictureUrl != null &&
|
||||||
|
user.profilePictureUrl!.isNotEmpty
|
||||||
? CircleAvatar(
|
? CircleAvatar(
|
||||||
radius: 50,
|
radius: 50,
|
||||||
backgroundImage: NetworkImage(
|
backgroundImage: NetworkImage(
|
||||||
@@ -57,7 +61,9 @@ class ProfileContent extends StatelessWidget {
|
|||||||
)
|
)
|
||||||
: CircleAvatar(
|
: CircleAvatar(
|
||||||
radius: 50,
|
radius: 50,
|
||||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
backgroundColor: Theme.of(
|
||||||
|
context,
|
||||||
|
).colorScheme.primary,
|
||||||
child: Text(
|
child: Text(
|
||||||
user.prenom.isNotEmpty
|
user.prenom.isNotEmpty
|
||||||
? user.prenom[0].toUpperCase()
|
? user.prenom[0].toUpperCase()
|
||||||
@@ -88,10 +94,7 @@ class ProfileContent extends StatelessWidget {
|
|||||||
// Email
|
// Email
|
||||||
Text(
|
Text(
|
||||||
user.email,
|
user.email,
|
||||||
style: TextStyle(
|
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
|
||||||
fontSize: 14,
|
|
||||||
color: Colors.grey[600],
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -99,7 +102,10 @@ class ProfileContent extends StatelessWidget {
|
|||||||
|
|
||||||
// Badge de méthode de connexion
|
// Badge de méthode de connexion
|
||||||
Container(
|
Container(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
padding: EdgeInsets.symmetric(
|
||||||
|
horizontal: 12,
|
||||||
|
vertical: 6,
|
||||||
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: _getAuthMethodColor(user.authMethod, context),
|
color: _getAuthMethodColor(user.authMethod, context),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
@@ -120,7 +126,10 @@ class ProfileContent extends StatelessWidget {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
color: _getAuthMethodTextColor(user.authMethod, context),
|
color: _getAuthMethodTextColor(
|
||||||
|
user.authMethod,
|
||||||
|
context,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -314,17 +323,13 @@ class ProfileContent extends StatelessWidget {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
color: isDestructive
|
color: isDestructive
|
||||||
? Colors.red
|
? Colors.red
|
||||||
: (isDarkMode ? Colors.white : Colors.black87),
|
: (isDarkMode ? Colors.white : Colors.black87),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Icon(
|
Icon(Icons.arrow_forward_ios, size: 16, color: Colors.grey[400]),
|
||||||
Icons.arrow_forward_ios,
|
|
||||||
size: 16,
|
|
||||||
color: Colors.grey[400],
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -355,7 +360,7 @@ class ProfileContent extends StatelessWidget {
|
|||||||
|
|
||||||
Color _getAuthMethodColor(String? authMethod, BuildContext context) {
|
Color _getAuthMethodColor(String? authMethod, BuildContext context) {
|
||||||
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
||||||
|
|
||||||
switch (authMethod) {
|
switch (authMethod) {
|
||||||
case 'apple':
|
case 'apple':
|
||||||
return isDarkMode ? Colors.white : Colors.black87;
|
return isDarkMode ? Colors.white : Colors.black87;
|
||||||
@@ -368,7 +373,7 @@ class ProfileContent extends StatelessWidget {
|
|||||||
|
|
||||||
Color _getAuthMethodTextColor(String? authMethod, BuildContext context) {
|
Color _getAuthMethodTextColor(String? authMethod, BuildContext context) {
|
||||||
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
||||||
|
|
||||||
switch (authMethod) {
|
switch (authMethod) {
|
||||||
case 'apple':
|
case 'apple':
|
||||||
return isDarkMode ? Colors.black87 : Colors.white;
|
return isDarkMode ? Colors.black87 : Colors.white;
|
||||||
@@ -401,7 +406,9 @@ class ProfileContent extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
CircleAvatar(
|
CircleAvatar(
|
||||||
radius: 50,
|
radius: 50,
|
||||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
backgroundColor: Theme.of(
|
||||||
|
context,
|
||||||
|
).colorScheme.primary,
|
||||||
child: Text(
|
child: Text(
|
||||||
prenomController.text.isNotEmpty
|
prenomController.text.isNotEmpty
|
||||||
? prenomController.text[0].toUpperCase()
|
? prenomController.text[0].toUpperCase()
|
||||||
@@ -422,7 +429,11 @@ class ProfileContent extends StatelessWidget {
|
|||||||
color: Theme.of(context).colorScheme.primary,
|
color: Theme.of(context).colorScheme.primary,
|
||||||
),
|
),
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
icon: Icon(Icons.camera_alt, color: Colors.white, size: 20),
|
icon: Icon(
|
||||||
|
Icons.camera_alt,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_showPhotoPickerDialog(dialogContext);
|
_showPhotoPickerDialog(dialogContext);
|
||||||
},
|
},
|
||||||
@@ -511,60 +522,66 @@ class ProfileContent extends StatelessWidget {
|
|||||||
void _showPhotoPickerDialog(BuildContext context) {
|
void _showPhotoPickerDialog(BuildContext context) {
|
||||||
// Récupérer les références AVANT que le modal ne se ferme
|
// Récupérer les références AVANT que le modal ne se ferme
|
||||||
final userBloc = context.read<UserBloc>();
|
final userBloc = context.read<UserBloc>();
|
||||||
|
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext sheetContext) {
|
builder: (BuildContext sheetContext) {
|
||||||
return Container(
|
return Wrap(
|
||||||
child: Wrap(
|
children: [
|
||||||
children: [
|
ListTile(
|
||||||
ListTile(
|
leading: Icon(Icons.photo_library),
|
||||||
leading: Icon(Icons.photo_library),
|
title: Text('Galerie'),
|
||||||
title: Text('Galerie'),
|
onTap: () {
|
||||||
onTap: () {
|
Navigator.pop(sheetContext);
|
||||||
Navigator.pop(sheetContext);
|
_pickImageFromGallery(context, userBloc);
|
||||||
_pickImageFromGallery(context, userBloc);
|
},
|
||||||
},
|
),
|
||||||
),
|
ListTile(
|
||||||
ListTile(
|
leading: Icon(Icons.camera_alt),
|
||||||
leading: Icon(Icons.camera_alt),
|
title: Text('Caméra'),
|
||||||
title: Text('Caméra'),
|
onTap: () {
|
||||||
onTap: () {
|
Navigator.pop(sheetContext);
|
||||||
Navigator.pop(sheetContext);
|
_pickImageFromCamera(context, userBloc);
|
||||||
_pickImageFromCamera(context, userBloc);
|
},
|
||||||
},
|
),
|
||||||
),
|
ListTile(
|
||||||
ListTile(
|
leading: Icon(Icons.close),
|
||||||
leading: Icon(Icons.close),
|
title: Text('Annuler'),
|
||||||
title: Text('Annuler'),
|
onTap: () => Navigator.pop(sheetContext),
|
||||||
onTap: () => Navigator.pop(sheetContext),
|
),
|
||||||
),
|
],
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _pickImageFromGallery(BuildContext context, UserBloc userBloc) async {
|
Future<void> _pickImageFromGallery(
|
||||||
|
BuildContext context,
|
||||||
|
UserBloc userBloc,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
final ImagePicker picker = ImagePicker();
|
final ImagePicker picker = ImagePicker();
|
||||||
final XFile? image = await picker.pickImage(source: ImageSource.gallery);
|
final XFile? image = await picker.pickImage(source: ImageSource.gallery);
|
||||||
|
|
||||||
if (image != null) {
|
if (image != null && context.mounted) {
|
||||||
await _uploadProfilePicture(context, image.path, userBloc);
|
await _uploadProfilePicture(context, image.path, userBloc);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} 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 {
|
try {
|
||||||
final ImagePicker picker = ImagePicker();
|
final ImagePicker picker = ImagePicker();
|
||||||
final XFile? image = await picker.pickImage(source: ImageSource.camera);
|
final XFile? image = await picker.pickImage(source: ImageSource.camera);
|
||||||
|
|
||||||
if (image != null) {
|
if (image != null && context.mounted) {
|
||||||
await _uploadProfilePicture(context, image.path, userBloc);
|
await _uploadProfilePicture(context, image.path, userBloc);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} 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 {
|
try {
|
||||||
final File imageFile = File(imagePath);
|
final File imageFile = File(imagePath);
|
||||||
|
|
||||||
// Vérifier que le fichier existe
|
// Vérifier que le fichier existe
|
||||||
if (!await imageFile.exists()) {
|
if (!await imageFile.exists()) {
|
||||||
_errorService.showError(message: 'Le fichier image n\'existe pas');
|
_errorService.showError(message: 'Le fichier image n\'existe pas');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
print('DEBUG: Taille du fichier: ${imageFile.lengthSync()} bytes');
|
LoggerService.info(
|
||||||
|
'DEBUG: Taille du fichier: ${imageFile.lengthSync()} bytes',
|
||||||
|
);
|
||||||
|
|
||||||
final userState = userBloc.state;
|
final userState = userBloc.state;
|
||||||
if (userState is! user_state.UserLoaded) {
|
if (userState is! user_state.UserLoaded) {
|
||||||
@@ -591,30 +614,35 @@ class ProfileContent extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final user = userState.user;
|
final user = userState.user;
|
||||||
|
|
||||||
// Créer un nom unique pour la photo
|
// 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
|
final Reference storageRef = FirebaseStorage.instance
|
||||||
.ref()
|
.ref()
|
||||||
.child('profile_pictures')
|
.child('profile_pictures')
|
||||||
.child(fileName);
|
.child(fileName);
|
||||||
|
|
||||||
print('DEBUG: Chemin Storage: ${storageRef.fullPath}');
|
LoggerService.info('DEBUG: Chemin Storage: ${storageRef.fullPath}');
|
||||||
print('DEBUG: Upload en cours pour $fileName');
|
LoggerService.info('DEBUG: Upload en cours pour $fileName');
|
||||||
|
|
||||||
// Uploader l'image avec gestion d'erreur détaillée
|
// Uploader l'image avec gestion d'erreur détaillée
|
||||||
try {
|
try {
|
||||||
final uploadTask = storageRef.putFile(imageFile);
|
final uploadTask = storageRef.putFile(imageFile);
|
||||||
|
|
||||||
// Écouter la progression
|
// Écouter la progression
|
||||||
uploadTask.snapshotEvents.listen((TaskSnapshot snapshot) {
|
uploadTask.snapshotEvents.listen((TaskSnapshot snapshot) {
|
||||||
print('DEBUG: Progression: ${snapshot.bytesTransferred}/${snapshot.totalBytes}');
|
LoggerService.info(
|
||||||
|
'DEBUG: Progression: ${snapshot.bytesTransferred}/${snapshot.totalBytes}',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
final snapshot = await uploadTask;
|
final snapshot = await uploadTask;
|
||||||
print('DEBUG: Upload terminé. État: ${snapshot.state}');
|
LoggerService.info('DEBUG: Upload terminé. État: ${snapshot.state}');
|
||||||
} on FirebaseException catch (e) {
|
} 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) {
|
if (context.mounted) {
|
||||||
_errorService.showError(
|
_errorService.showError(
|
||||||
message: 'Erreur Firebase: ${e.code}\n${e.message}',
|
message: 'Erreur Firebase: ${e.code}\n${e.message}',
|
||||||
@@ -623,26 +651,22 @@ class ProfileContent extends StatelessWidget {
|
|||||||
return;
|
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
|
// Récupérer l'URL
|
||||||
final String downloadUrl = await storageRef.getDownloadURL();
|
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
|
// 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');
|
LoggerService.info('DEBUG: Envoi de UserUpdated event au BLoC');
|
||||||
userBloc.add(
|
userBloc.add(user_event.UserUpdated({'profilePictureUrl': downloadUrl}));
|
||||||
user_event.UserUpdated({
|
|
||||||
'profilePictureUrl': downloadUrl,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Attendre un peu que Firestore se mette à jour
|
// Attendre un peu que Firestore se mette à jour
|
||||||
await Future.delayed(Duration(milliseconds: 500));
|
await Future.delayed(Duration(milliseconds: 500));
|
||||||
|
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
print('DEBUG: Affichage du succès');
|
LoggerService.info('DEBUG: Affichage du succès');
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text('Photo de profil mise à jour !'),
|
content: Text('Photo de profil mise à jour !'),
|
||||||
@@ -651,8 +675,8 @@ class ProfileContent extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
print('DEBUG: Erreur lors de l\'upload: $e');
|
LoggerService.error('DEBUG: Erreur lors de l\'upload: $e');
|
||||||
print('DEBUG: Stack trace: $stackTrace');
|
LoggerService.error('DEBUG: Stack trace: $stackTrace');
|
||||||
_errorService.logError(
|
_errorService.logError(
|
||||||
'ProfileContent - _uploadProfilePicture',
|
'ProfileContent - _uploadProfilePicture',
|
||||||
'Erreur lors de l\'upload de la photo: $e\n$stackTrace',
|
'Erreur lors de l\'upload de la photo: $e\n$stackTrace',
|
||||||
@@ -738,13 +762,15 @@ class ProfileContent extends StatelessWidget {
|
|||||||
email: user.email,
|
email: user.email,
|
||||||
);
|
);
|
||||||
|
|
||||||
Navigator.of(dialogContext).pop();
|
if (context.mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
Navigator.of(dialogContext).pop();
|
||||||
SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
content: Text('Mot de passe changé !'),
|
SnackBar(
|
||||||
backgroundColor: Colors.green,
|
content: Text('Mot de passe changé !'),
|
||||||
),
|
backgroundColor: Colors.green,
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.showError(
|
_errorService.showError(
|
||||||
message: 'Erreur: Mot de passe actuel incorrect',
|
message: 'Erreur: Mot de passe actuel incorrect',
|
||||||
@@ -801,13 +827,15 @@ class ProfileContent extends StatelessWidget {
|
|||||||
email: user.email,
|
email: user.email,
|
||||||
);
|
);
|
||||||
|
|
||||||
Navigator.of(dialogContext).pop();
|
if (context.mounted) {
|
||||||
context.read<UserBloc>().add(user_event.UserLoggedOut());
|
Navigator.of(dialogContext).pop();
|
||||||
Navigator.pushNamedAndRemoveUntil(
|
context.read<UserBloc>().add(user_event.UserLoggedOut());
|
||||||
context,
|
Navigator.pushNamedAndRemoveUntil(
|
||||||
'/login',
|
context,
|
||||||
(route) => false,
|
'/login',
|
||||||
);
|
(route) => false,
|
||||||
|
);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.showError(
|
_errorService.showError(
|
||||||
message: 'Erreur: Mot de passe incorrect',
|
message: 'Erreur: Mot de passe incorrect',
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ class Activity {
|
|||||||
final Map<String, int> votes; // userId -> vote (1 pour pour, -1 pour contre)
|
final Map<String, int> votes; // userId -> vote (1 pour pour, -1 pour contre)
|
||||||
final DateTime createdAt;
|
final DateTime createdAt;
|
||||||
final DateTime updatedAt;
|
final DateTime updatedAt;
|
||||||
|
final DateTime? date; // Date prévue pour l'activité
|
||||||
|
|
||||||
Activity({
|
Activity({
|
||||||
required this.id,
|
required this.id,
|
||||||
@@ -40,11 +41,12 @@ class Activity {
|
|||||||
this.votes = const {},
|
this.votes = const {},
|
||||||
required this.createdAt,
|
required this.createdAt,
|
||||||
required this.updatedAt,
|
required this.updatedAt,
|
||||||
|
this.date,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Calcule le score total des votes
|
/// Calcule le score total des votes
|
||||||
int get totalVotes {
|
int get totalVotes {
|
||||||
return votes.values.fold(0, (sum, vote) => sum + vote);
|
return votes.values.fold(0, (total, vote) => total + vote);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calcule le nombre de votes positifs
|
/// Calcule le nombre de votes positifs
|
||||||
@@ -104,6 +106,8 @@ class Activity {
|
|||||||
Map<String, int>? votes,
|
Map<String, int>? votes,
|
||||||
DateTime? createdAt,
|
DateTime? createdAt,
|
||||||
DateTime? updatedAt,
|
DateTime? updatedAt,
|
||||||
|
DateTime? date,
|
||||||
|
bool clearDate = false,
|
||||||
}) {
|
}) {
|
||||||
return Activity(
|
return Activity(
|
||||||
id: id ?? this.id,
|
id: id ?? this.id,
|
||||||
@@ -124,6 +128,7 @@ class Activity {
|
|||||||
votes: votes ?? this.votes,
|
votes: votes ?? this.votes,
|
||||||
createdAt: createdAt ?? this.createdAt,
|
createdAt: createdAt ?? this.createdAt,
|
||||||
updatedAt: updatedAt ?? this.updatedAt,
|
updatedAt: updatedAt ?? this.updatedAt,
|
||||||
|
date: clearDate ? null : (date ?? this.date),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,6 +153,7 @@ class Activity {
|
|||||||
'votes': votes,
|
'votes': votes,
|
||||||
'createdAt': Timestamp.fromDate(createdAt),
|
'createdAt': Timestamp.fromDate(createdAt),
|
||||||
'updatedAt': Timestamp.fromDate(updatedAt),
|
'updatedAt': Timestamp.fromDate(updatedAt),
|
||||||
|
'date': date != null ? Timestamp.fromDate(date!) : null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,6 +178,7 @@ class Activity {
|
|||||||
votes: Map<String, int>.from(map['votes'] ?? {}),
|
votes: Map<String, int>.from(map['votes'] ?? {}),
|
||||||
createdAt: (map['createdAt'] as Timestamp).toDate(),
|
createdAt: (map['createdAt'] as Timestamp).toDate(),
|
||||||
updatedAt: (map['updatedAt'] as Timestamp).toDate(),
|
updatedAt: (map['updatedAt'] as Timestamp).toDate(),
|
||||||
|
date: map['date'] != null ? (map['date'] as Timestamp).toDate() : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,107 +4,114 @@ import 'package:flutter/material.dart';
|
|||||||
import 'expense_split.dart';
|
import 'expense_split.dart';
|
||||||
|
|
||||||
/// Enumeration of supported currencies for expenses.
|
/// Enumeration of supported currencies for expenses.
|
||||||
///
|
///
|
||||||
/// Each currency includes both a display symbol and standard currency code.
|
/// Each currency includes both a display symbol and standard currency code.
|
||||||
enum ExpenseCurrency {
|
enum ExpenseCurrency {
|
||||||
/// Euro currency
|
/// Euro currency
|
||||||
eur('€', 'EUR'),
|
eur('€', 'EUR'),
|
||||||
/// US Dollar currency
|
|
||||||
|
/// US Dollar currency
|
||||||
usd('\$', 'USD'),
|
usd('\$', 'USD'),
|
||||||
|
|
||||||
/// British Pound currency
|
/// British Pound currency
|
||||||
gbp('£', 'GBP');
|
gbp('£', 'GBP');
|
||||||
|
|
||||||
const ExpenseCurrency(this.symbol, this.code);
|
const ExpenseCurrency(this.symbol, this.code);
|
||||||
|
|
||||||
/// Currency symbol for display (e.g., €, $, £)
|
/// Currency symbol for display (e.g., €, $, £)
|
||||||
final String symbol;
|
final String symbol;
|
||||||
|
|
||||||
/// Standard currency code (e.g., EUR, USD, GBP)
|
/// Standard currency code (e.g., EUR, USD, GBP)
|
||||||
final String code;
|
final String code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enumeration of expense categories with display names and icons.
|
/// Enumeration of expense categories with display names and icons.
|
||||||
///
|
///
|
||||||
/// Provides predefined categories for organizing travel expenses.
|
/// Provides predefined categories for organizing travel expenses.
|
||||||
enum ExpenseCategory {
|
enum ExpenseCategory {
|
||||||
/// Restaurant and food expenses
|
/// Restaurant and food expenses
|
||||||
restaurant('Restaurant', Icons.restaurant),
|
restaurant('Restaurant', Icons.restaurant),
|
||||||
|
|
||||||
/// Transportation expenses
|
/// Transportation expenses
|
||||||
transport('Transport', Icons.directions_car),
|
transport('Transport', Icons.directions_car),
|
||||||
|
|
||||||
/// Accommodation and lodging expenses
|
/// Accommodation and lodging expenses
|
||||||
accommodation('Accommodation', Icons.hotel),
|
accommodation('Accommodation', Icons.hotel),
|
||||||
|
|
||||||
/// Entertainment and activity expenses
|
/// Entertainment and activity expenses
|
||||||
entertainment('Entertainment', Icons.local_activity),
|
entertainment('Entertainment', Icons.local_activity),
|
||||||
|
|
||||||
/// Shopping expenses
|
/// Shopping expenses
|
||||||
shopping('Shopping', Icons.shopping_bag),
|
shopping('Shopping', Icons.shopping_bag),
|
||||||
|
|
||||||
/// Other miscellaneous expenses
|
/// Other miscellaneous expenses
|
||||||
other('Other', Icons.category);
|
other('Other', Icons.category);
|
||||||
|
|
||||||
const ExpenseCategory(this.displayName, this.icon);
|
const ExpenseCategory(this.displayName, this.icon);
|
||||||
|
|
||||||
/// Human-readable display name for the category
|
/// Human-readable display name for the category
|
||||||
final String displayName;
|
final String displayName;
|
||||||
|
|
||||||
/// Icon representing the category
|
/// Icon representing the category
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Model representing a travel expense.
|
/// Model representing a travel expense.
|
||||||
///
|
///
|
||||||
/// This class encapsulates all information about an expense including
|
/// This class encapsulates all information about an expense including
|
||||||
/// amount, currency, category, who paid, how it's split among participants,
|
/// amount, currency, category, who paid, how it's split among participants,
|
||||||
/// and receipt information. It extends [Equatable] for value comparison.
|
/// and receipt information. It extends [Equatable] for value comparison.
|
||||||
class Expense extends Equatable {
|
class Expense extends Equatable {
|
||||||
/// Unique identifier for the expense
|
/// Unique identifier for the expense
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
/// ID of the group this expense belongs to
|
/// ID of the group this expense belongs to
|
||||||
final String groupId;
|
final String groupId;
|
||||||
|
|
||||||
/// Description of the expense
|
/// Description of the expense
|
||||||
final String description;
|
final String description;
|
||||||
|
|
||||||
/// Amount of the expense in the original currency
|
/// Amount of the expense in the original currency
|
||||||
final double amount;
|
final double amount;
|
||||||
|
|
||||||
/// Currency of the expense
|
/// Currency of the expense
|
||||||
final ExpenseCurrency currency;
|
final ExpenseCurrency currency;
|
||||||
|
|
||||||
/// Amount converted to EUR for standardized calculations
|
/// Amount converted to EUR for standardized calculations
|
||||||
final double amountInEur;
|
final double amountInEur;
|
||||||
|
|
||||||
/// Category of the expense
|
/// Category of the expense
|
||||||
final ExpenseCategory category;
|
final ExpenseCategory category;
|
||||||
|
|
||||||
/// ID of the user who paid for this expense
|
/// ID of the user who paid for this expense
|
||||||
final String paidById;
|
final String paidById;
|
||||||
|
|
||||||
/// Name of the user who paid for this expense
|
/// Name of the user who paid for this expense
|
||||||
final String paidByName;
|
final String paidByName;
|
||||||
|
|
||||||
/// Date when the expense occurred
|
/// Date when the expense occurred
|
||||||
final DateTime date;
|
final DateTime date;
|
||||||
|
|
||||||
/// Timestamp when the expense was created
|
/// Timestamp when the expense was created
|
||||||
final DateTime createdAt;
|
final DateTime createdAt;
|
||||||
|
|
||||||
/// Timestamp when the expense was last edited (null if never edited)
|
/// Timestamp when the expense was last edited (null if never edited)
|
||||||
final DateTime? editedAt;
|
final DateTime? editedAt;
|
||||||
|
|
||||||
/// Whether this expense has been edited after creation
|
/// Whether this expense has been edited after creation
|
||||||
final bool isEdited;
|
final bool isEdited;
|
||||||
|
|
||||||
/// Whether this expense has been archived
|
/// Whether this expense has been archived
|
||||||
final bool isArchived;
|
final bool isArchived;
|
||||||
|
|
||||||
/// URL to the receipt image (optional)
|
/// URL to the receipt image (optional)
|
||||||
final String? receiptUrl;
|
final String? receiptUrl;
|
||||||
|
|
||||||
/// List of expense splits showing how the cost is divided
|
/// List of expense splits showing how the cost is divided
|
||||||
final List<ExpenseSplit> splits;
|
final List<ExpenseSplit> splits;
|
||||||
|
|
||||||
/// Creates a new [Expense] instance.
|
/// Creates a new [Expense] instance.
|
||||||
///
|
///
|
||||||
/// All parameters except [editedAt] and [receiptUrl] are required.
|
/// All parameters except [editedAt] and [receiptUrl] are required.
|
||||||
const Expense({
|
const Expense({
|
||||||
required this.id,
|
required this.id,
|
||||||
@@ -144,13 +151,17 @@ class Expense extends Equatable {
|
|||||||
paidByName: map['paidByName'] ?? '',
|
paidByName: map['paidByName'] ?? '',
|
||||||
date: _parseDateTime(map['date']),
|
date: _parseDateTime(map['date']),
|
||||||
createdAt: _parseDateTime(map['createdAt']),
|
createdAt: _parseDateTime(map['createdAt']),
|
||||||
editedAt: map['editedAt'] != null ? _parseDateTime(map['editedAt']) : null,
|
editedAt: map['editedAt'] != null
|
||||||
|
? _parseDateTime(map['editedAt'])
|
||||||
|
: null,
|
||||||
isEdited: map['isEdited'] ?? false,
|
isEdited: map['isEdited'] ?? false,
|
||||||
isArchived: map['isArchived'] ?? false,
|
isArchived: map['isArchived'] ?? false,
|
||||||
receiptUrl: map['receiptUrl'],
|
receiptUrl: map['receiptUrl'],
|
||||||
splits: (map['splits'] as List?)
|
splits:
|
||||||
?.map((s) => ExpenseSplit.fromMap(s))
|
(map['splits'] as List?)
|
||||||
.toList() ?? [],
|
?.map((s) => ExpenseSplit.fromMap(s))
|
||||||
|
.toList() ??
|
||||||
|
[],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,25 +254,36 @@ class Expense extends Equatable {
|
|||||||
|
|
||||||
// Marquer comme archivé
|
// Marquer comme archivé
|
||||||
Expense copyWithArchived() {
|
Expense copyWithArchived() {
|
||||||
return copyWith(
|
return copyWith(isArchived: true);
|
||||||
isArchived: true,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajouter/mettre à jour l'URL du reçu
|
// Ajouter/mettre à jour l'URL du reçu
|
||||||
Expense copyWithReceipt(String receiptUrl) {
|
Expense copyWithReceipt(String receiptUrl) {
|
||||||
return copyWith(
|
return copyWith(receiptUrl: receiptUrl);
|
||||||
receiptUrl: receiptUrl,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mettre à jour les splits
|
// Mettre à jour les splits
|
||||||
Expense copyWithSplits(List<ExpenseSplit> newSplits) {
|
Expense copyWithSplits(List<ExpenseSplit> newSplits) {
|
||||||
return copyWith(
|
return copyWith(splits: newSplits);
|
||||||
splits: newSplits,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [id];
|
List<Object?> get props => [
|
||||||
}
|
id,
|
||||||
|
groupId,
|
||||||
|
description,
|
||||||
|
amount,
|
||||||
|
currency,
|
||||||
|
amountInEur,
|
||||||
|
category,
|
||||||
|
paidById,
|
||||||
|
paidByName,
|
||||||
|
date,
|
||||||
|
createdAt,
|
||||||
|
editedAt,
|
||||||
|
isEdited,
|
||||||
|
isArchived,
|
||||||
|
receiptUrl,
|
||||||
|
splits,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,54 +1,59 @@
|
|||||||
import 'group_member.dart';
|
import 'group_member.dart';
|
||||||
|
|
||||||
/// Model representing a travel group.
|
/// Model representing a travel group.
|
||||||
///
|
///
|
||||||
/// A group is a collection of travelers who are part of a specific trip.
|
/// A group is a collection of travelers who are part of a specific trip.
|
||||||
/// It contains information about group members, creation details, and
|
/// It contains information about group members, creation details, and
|
||||||
/// provides methods for serialization with Firestore.
|
/// provides methods for serialization with Firestore.
|
||||||
class Group {
|
class Group {
|
||||||
/// Unique identifier for the group
|
/// Unique identifier for the group
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
/// Display name of the group
|
/// Display name of the group
|
||||||
final String name;
|
final String name;
|
||||||
|
|
||||||
/// ID of the trip this group belongs to
|
/// ID of the trip this group belongs to
|
||||||
final String tripId;
|
final String tripId;
|
||||||
|
|
||||||
/// ID of the user who created this group
|
/// ID of the user who created this group
|
||||||
final String createdBy;
|
final String createdBy;
|
||||||
|
|
||||||
/// Timestamp when the group was created
|
/// Timestamp when the group was created
|
||||||
final DateTime createdAt;
|
final DateTime createdAt;
|
||||||
|
|
||||||
/// Timestamp when the group was last updated
|
/// Timestamp when the group was last updated
|
||||||
final DateTime updatedAt;
|
final DateTime updatedAt;
|
||||||
|
|
||||||
/// List of members in this group
|
/// List of members in this group
|
||||||
final List<GroupMember> members;
|
final List<GroupMember> members;
|
||||||
|
|
||||||
|
/// List of member IDs for efficient querying and security rules
|
||||||
|
final List<String> memberIds;
|
||||||
|
|
||||||
/// Creates a new [Group] instance.
|
/// Creates a new [Group] instance.
|
||||||
///
|
///
|
||||||
/// [id], [name], [tripId], and [createdBy] are required.
|
/// [id], [name], [tripId], and [createdBy] are required.
|
||||||
/// [createdAt] and [updatedAt] default to current time if not provided.
|
/// [createdAt] and [updatedAt] default to current time if not provided.
|
||||||
/// [members] defaults to empty list if not provided.
|
/// [members] defaults to empty list if not provided.
|
||||||
Group({
|
Group({
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.tripId,
|
required this.tripId,
|
||||||
required this.createdBy,
|
required this.createdBy,
|
||||||
DateTime? createdAt,
|
DateTime? createdAt,
|
||||||
DateTime? updatedAt,
|
DateTime? updatedAt,
|
||||||
List<GroupMember>? members,
|
List<GroupMember>? members,
|
||||||
}) : createdAt = createdAt ?? DateTime.now(),
|
List<String>? memberIds,
|
||||||
updatedAt = updatedAt ?? DateTime.now(),
|
}) : createdAt = createdAt ?? DateTime.now(),
|
||||||
members = members ?? [];
|
updatedAt = updatedAt ?? DateTime.now(),
|
||||||
|
members = members ?? [],
|
||||||
|
memberIds = memberIds ?? [];
|
||||||
|
|
||||||
/// Creates a [Group] instance from a Firestore document map.
|
/// Creates a [Group] instance from a Firestore document map.
|
||||||
///
|
///
|
||||||
/// [map] - The document data from Firestore
|
/// [map] - The document data from Firestore
|
||||||
/// [id] - The document ID from Firestore
|
/// [id] - The document ID from Firestore
|
||||||
///
|
///
|
||||||
/// Returns a new [Group] instance with data from the map.
|
/// Returns a new [Group] instance with data from the map.
|
||||||
factory Group.fromMap(Map<String, dynamic> map, String id) {
|
factory Group.fromMap(Map<String, dynamic> map, String id) {
|
||||||
return Group(
|
return Group(
|
||||||
@@ -59,6 +64,7 @@ class Group {
|
|||||||
createdAt: DateTime.fromMillisecondsSinceEpoch(map['createdAt'] ?? 0),
|
createdAt: DateTime.fromMillisecondsSinceEpoch(map['createdAt'] ?? 0),
|
||||||
updatedAt: DateTime.fromMillisecondsSinceEpoch(map['updatedAt'] ?? 0),
|
updatedAt: DateTime.fromMillisecondsSinceEpoch(map['updatedAt'] ?? 0),
|
||||||
members: [],
|
members: [],
|
||||||
|
memberIds: List<String>.from(map['memberIds'] ?? []),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +75,7 @@ class Group {
|
|||||||
'createdBy': createdBy,
|
'createdBy': createdBy,
|
||||||
'createdAt': createdAt.millisecondsSinceEpoch,
|
'createdAt': createdAt.millisecondsSinceEpoch,
|
||||||
'updatedAt': updatedAt.millisecondsSinceEpoch,
|
'updatedAt': updatedAt.millisecondsSinceEpoch,
|
||||||
|
'memberIds': memberIds,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +87,7 @@ class Group {
|
|||||||
DateTime? createdAt,
|
DateTime? createdAt,
|
||||||
DateTime? updatedAt,
|
DateTime? updatedAt,
|
||||||
List<GroupMember>? members,
|
List<GroupMember>? members,
|
||||||
|
List<String>? memberIds,
|
||||||
}) {
|
}) {
|
||||||
return Group(
|
return Group(
|
||||||
id: id ?? this.id,
|
id: id ?? this.id,
|
||||||
@@ -89,6 +97,7 @@ class Group {
|
|||||||
createdAt: createdAt ?? this.createdAt,
|
createdAt: createdAt ?? this.createdAt,
|
||||||
updatedAt: updatedAt ?? this.updatedAt,
|
updatedAt: updatedAt ?? this.updatedAt,
|
||||||
members: members ?? this.members,
|
members: members ?? this.members,
|
||||||
|
memberIds: memberIds ?? this.memberIds,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,12 +22,22 @@ class GroupBalance extends Equatable {
|
|||||||
factory GroupBalance.fromMap(Map<String, dynamic> map) {
|
factory GroupBalance.fromMap(Map<String, dynamic> map) {
|
||||||
return GroupBalance(
|
return GroupBalance(
|
||||||
groupId: map['groupId'] ?? '',
|
groupId: map['groupId'] ?? '',
|
||||||
userBalances: (map['userBalances'] as List?)
|
userBalances:
|
||||||
?.map((userBalance) => UserBalance.fromMap(userBalance as Map<String, dynamic>))
|
(map['userBalances'] as List?)
|
||||||
.toList() ?? [],
|
?.map(
|
||||||
settlements: (map['settlements'] as List?)
|
(userBalance) =>
|
||||||
?.map((settlement) => Settlement.fromMap(settlement as Map<String, dynamic>))
|
UserBalance.fromMap(userBalance as Map<String, dynamic>),
|
||||||
.toList() ?? [],
|
)
|
||||||
|
.toList() ??
|
||||||
|
[],
|
||||||
|
settlements:
|
||||||
|
(map['settlements'] as List?)
|
||||||
|
?.map(
|
||||||
|
(settlement) =>
|
||||||
|
Settlement.fromMap(settlement as Map<String, dynamic>),
|
||||||
|
)
|
||||||
|
.toList() ??
|
||||||
|
[],
|
||||||
totalExpenses: (map['totalExpenses'] as num?)?.toDouble() ?? 0.0,
|
totalExpenses: (map['totalExpenses'] as num?)?.toDouble() ?? 0.0,
|
||||||
calculatedAt: _parseDateTime(map['calculatedAt']),
|
calculatedAt: _parseDateTime(map['calculatedAt']),
|
||||||
);
|
);
|
||||||
@@ -37,8 +47,12 @@ class GroupBalance extends Equatable {
|
|||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
return {
|
return {
|
||||||
'groupId': groupId,
|
'groupId': groupId,
|
||||||
'userBalances': userBalances.map((userBalance) => userBalance.toMap()).toList(),
|
'userBalances': userBalances
|
||||||
'settlements': settlements.map((settlement) => settlement.toMap()).toList(),
|
.map((userBalance) => userBalance.toMap())
|
||||||
|
.toList(),
|
||||||
|
'settlements': settlements
|
||||||
|
.map((settlement) => settlement.toMap())
|
||||||
|
.toList(),
|
||||||
'totalExpenses': totalExpenses,
|
'totalExpenses': totalExpenses,
|
||||||
'calculatedAt': Timestamp.fromDate(calculatedAt),
|
'calculatedAt': Timestamp.fromDate(calculatedAt),
|
||||||
};
|
};
|
||||||
@@ -71,16 +85,20 @@ class GroupBalance extends Equatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Méthodes utilitaires pour la logique métier
|
// Méthodes utilitaires pour la logique métier
|
||||||
bool get hasUnbalancedUsers => userBalances.any((balance) => !balance.isBalanced);
|
bool get hasUnbalancedUsers =>
|
||||||
|
userBalances.any((balance) => !balance.isBalanced);
|
||||||
|
|
||||||
bool get hasSettlements => settlements.isNotEmpty;
|
bool get hasSettlements => settlements.isNotEmpty;
|
||||||
|
|
||||||
double get totalSettlementAmount => settlements.fold(0.0, (sum, settlement) => sum + settlement.amount);
|
double get totalSettlementAmount =>
|
||||||
|
settlements.fold(0.0, (total, settlement) => total + settlement.amount);
|
||||||
List<UserBalance> get creditors => userBalances.where((b) => b.shouldReceive).toList();
|
|
||||||
|
List<UserBalance> get creditors =>
|
||||||
List<UserBalance> get debtors => userBalances.where((b) => b.shouldPay).toList();
|
userBalances.where((b) => b.shouldReceive).toList();
|
||||||
|
|
||||||
|
List<UserBalance> get debtors =>
|
||||||
|
userBalances.where((b) => b.shouldPay).toList();
|
||||||
|
|
||||||
int get participantCount => userBalances.length;
|
int get participantCount => userBalances.length;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -90,4 +108,4 @@ class GroupBalance extends Equatable {
|
|||||||
String toString() {
|
String toString() {
|
||||||
return 'GroupBalance(groupId: $groupId, totalExpenses: $totalExpenses, participantCount: $participantCount, calculatedAt: $calculatedAt)';
|
return 'GroupBalance(groupId: $groupId, totalExpenses: $totalExpenses, participantCount: $participantCount, calculatedAt: $calculatedAt)';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
class GroupMember {
|
class GroupMember {
|
||||||
final String userId;
|
final String userId;
|
||||||
final String firstName;
|
final String firstName;
|
||||||
|
final String lastName;
|
||||||
final String pseudo; // Pseudo du membre (par défaut = prénom)
|
final String pseudo; // Pseudo du membre (par défaut = prénom)
|
||||||
final String role; // 'admin' ou 'member'
|
final String role; // 'admin' ou 'member'
|
||||||
final DateTime joinedAt;
|
final DateTime joinedAt;
|
||||||
@@ -9,17 +10,20 @@ class GroupMember {
|
|||||||
GroupMember({
|
GroupMember({
|
||||||
required this.userId,
|
required this.userId,
|
||||||
required this.firstName,
|
required this.firstName,
|
||||||
|
String? lastName,
|
||||||
String? pseudo,
|
String? pseudo,
|
||||||
this.role = 'member',
|
this.role = 'member',
|
||||||
DateTime? joinedAt,
|
DateTime? joinedAt,
|
||||||
this.profilePictureUrl,
|
this.profilePictureUrl,
|
||||||
}) : pseudo = pseudo ?? firstName, // Par défaut, pseudo = prénom
|
}) : lastName = lastName ?? '',
|
||||||
|
pseudo = pseudo ?? firstName,
|
||||||
joinedAt = joinedAt ?? DateTime.now();
|
joinedAt = joinedAt ?? DateTime.now();
|
||||||
|
|
||||||
factory GroupMember.fromMap(Map<String, dynamic> map, String userId) {
|
factory GroupMember.fromMap(Map<String, dynamic> map, String userId) {
|
||||||
return GroupMember(
|
return GroupMember(
|
||||||
userId: userId,
|
userId: userId,
|
||||||
firstName: map['firstName'] ?? '',
|
firstName: map['firstName'] ?? '',
|
||||||
|
lastName: map['lastName'] ?? '',
|
||||||
pseudo: map['pseudo'] ?? map['firstName'] ?? '',
|
pseudo: map['pseudo'] ?? map['firstName'] ?? '',
|
||||||
role: map['role'] ?? 'member',
|
role: map['role'] ?? 'member',
|
||||||
joinedAt: DateTime.fromMillisecondsSinceEpoch(map['joinedAt'] ?? 0),
|
joinedAt: DateTime.fromMillisecondsSinceEpoch(map['joinedAt'] ?? 0),
|
||||||
@@ -30,6 +34,7 @@ class GroupMember {
|
|||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
return {
|
return {
|
||||||
'firstName': firstName,
|
'firstName': firstName,
|
||||||
|
'lastName': lastName,
|
||||||
'pseudo': pseudo,
|
'pseudo': pseudo,
|
||||||
'role': role,
|
'role': role,
|
||||||
'joinedAt': joinedAt.millisecondsSinceEpoch,
|
'joinedAt': joinedAt.millisecondsSinceEpoch,
|
||||||
@@ -40,6 +45,7 @@ class GroupMember {
|
|||||||
GroupMember copyWith({
|
GroupMember copyWith({
|
||||||
String? userId,
|
String? userId,
|
||||||
String? firstName,
|
String? firstName,
|
||||||
|
String? lastName,
|
||||||
String? pseudo,
|
String? pseudo,
|
||||||
String? role,
|
String? role,
|
||||||
DateTime? joinedAt,
|
DateTime? joinedAt,
|
||||||
@@ -48,6 +54,7 @@ class GroupMember {
|
|||||||
return GroupMember(
|
return GroupMember(
|
||||||
userId: userId ?? this.userId,
|
userId: userId ?? this.userId,
|
||||||
firstName: firstName ?? this.firstName,
|
firstName: firstName ?? this.firstName,
|
||||||
|
lastName: lastName ?? this.lastName,
|
||||||
pseudo: pseudo ?? this.pseudo,
|
pseudo: pseudo ?? this.pseudo,
|
||||||
role: role ?? this.role,
|
role: role ?? this.role,
|
||||||
joinedAt: joinedAt ?? this.joinedAt,
|
joinedAt: joinedAt ?? this.joinedAt,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class Message {
|
|||||||
final Map<String, String> reactions; // userId -> emoji
|
final Map<String, String> reactions; // userId -> emoji
|
||||||
final DateTime? editedAt;
|
final DateTime? editedAt;
|
||||||
final bool isEdited;
|
final bool isEdited;
|
||||||
|
final bool isDeleted;
|
||||||
|
|
||||||
Message({
|
Message({
|
||||||
this.id = '',
|
this.id = '',
|
||||||
@@ -21,6 +22,7 @@ class Message {
|
|||||||
this.reactions = const {},
|
this.reactions = const {},
|
||||||
this.editedAt,
|
this.editedAt,
|
||||||
this.isEdited = false,
|
this.isEdited = false,
|
||||||
|
this.isDeleted = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory Message.fromFirestore(DocumentSnapshot doc) {
|
factory Message.fromFirestore(DocumentSnapshot doc) {
|
||||||
@@ -39,6 +41,7 @@ class Message {
|
|||||||
reactions: reactionsData?.map((key, value) => MapEntry(key, value.toString())) ?? {},
|
reactions: reactionsData?.map((key, value) => MapEntry(key, value.toString())) ?? {},
|
||||||
editedAt: editedAtTimestamp?.toDate(),
|
editedAt: editedAtTimestamp?.toDate(),
|
||||||
isEdited: data['isEdited'] ?? false,
|
isEdited: data['isEdited'] ?? false,
|
||||||
|
isDeleted: data['isDeleted'] ?? false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +55,7 @@ class Message {
|
|||||||
'reactions': reactions,
|
'reactions': reactions,
|
||||||
'editedAt': editedAt != null ? Timestamp.fromDate(editedAt!) : null,
|
'editedAt': editedAt != null ? Timestamp.fromDate(editedAt!) : null,
|
||||||
'isEdited': isEdited,
|
'isEdited': isEdited,
|
||||||
|
'isDeleted': isDeleted,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +69,7 @@ class Message {
|
|||||||
Map<String, String>? reactions,
|
Map<String, String>? reactions,
|
||||||
DateTime? editedAt,
|
DateTime? editedAt,
|
||||||
bool? isEdited,
|
bool? isEdited,
|
||||||
|
bool? isDeleted,
|
||||||
}) {
|
}) {
|
||||||
return Message(
|
return Message(
|
||||||
id: id ?? this.id,
|
id: id ?? this.id,
|
||||||
@@ -76,6 +81,7 @@ class Message {
|
|||||||
reactions: reactions ?? this.reactions,
|
reactions: reactions ?? this.reactions,
|
||||||
editedAt: editedAt ?? this.editedAt,
|
editedAt: editedAt ?? this.editedAt,
|
||||||
isEdited: isEdited ?? this.isEdited,
|
isEdited: isEdited ?? this.isEdited,
|
||||||
|
isDeleted: isDeleted ?? this.isDeleted,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -198,4 +198,22 @@ class AccountRepository {
|
|||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> addMemberToAccount(String accountId, GroupMember member) async {
|
||||||
|
try {
|
||||||
|
await _membersCollection(accountId).doc(member.userId).set(member.toMap());
|
||||||
|
} catch (e) {
|
||||||
|
_errorService.logError('account_repository.dart', 'Erreur lors de l\'ajout du membre: $e');
|
||||||
|
throw Exception('Erreur lors de l\'ajout du membre: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> removeMemberFromAccount(String accountId, String memberId) async {
|
||||||
|
try {
|
||||||
|
await _membersCollection(accountId).doc(memberId).delete();
|
||||||
|
} catch (e) {
|
||||||
|
_errorService.logError('account_repository.dart', 'Erreur lors de la suppression du membre: $e');
|
||||||
|
throw Exception('Erreur lors de la suppression du membre: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -16,18 +16,32 @@ class ActivityRepository {
|
|||||||
/// Ajoute une nouvelle activité
|
/// Ajoute une nouvelle activité
|
||||||
Future<String?> addActivity(Activity activity) async {
|
Future<String?> addActivity(Activity activity) async {
|
||||||
try {
|
try {
|
||||||
print('ActivityRepository: Ajout d\'une activité: ${activity.name}');
|
_errorService.logInfo(
|
||||||
|
'ActivityRepository',
|
||||||
final docRef = await _firestore.collection(_collection).add(activity.toMap());
|
'Ajout d\'une activité: ${activity.name}',
|
||||||
|
);
|
||||||
|
|
||||||
|
final docRef = await _firestore
|
||||||
|
.collection(_collection)
|
||||||
|
.add(activity.toMap());
|
||||||
|
|
||||||
// Mettre à jour l'activité avec l'ID généré
|
// Mettre à jour l'activité avec l'ID généré
|
||||||
await docRef.update({'id': docRef.id});
|
await docRef.update({'id': docRef.id});
|
||||||
|
|
||||||
print('ActivityRepository: Activité ajoutée avec ID: ${docRef.id}');
|
_errorService.logSuccess(
|
||||||
|
'ActivityRepository',
|
||||||
|
'Activité ajoutée avec ID: ${docRef.id}',
|
||||||
|
);
|
||||||
return docRef.id;
|
return docRef.id;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityRepository: Erreur lors de l\'ajout: $e');
|
_errorService.logError(
|
||||||
_errorService.logError('activity_repository', 'Erreur ajout activité: $e');
|
'ActivityRepository',
|
||||||
|
'Erreur lors de l\'ajout: $e',
|
||||||
|
);
|
||||||
|
_errorService.logError(
|
||||||
|
'activity_repository',
|
||||||
|
'Erreur ajout activité: $e',
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,8 +49,11 @@ class ActivityRepository {
|
|||||||
/// Récupère toutes les activités d'un voyage
|
/// Récupère toutes les activités d'un voyage
|
||||||
Future<List<Activity>> getActivitiesByTrip(String tripId) async {
|
Future<List<Activity>> getActivitiesByTrip(String tripId) async {
|
||||||
try {
|
try {
|
||||||
print('ActivityRepository: Récupération des activités pour le voyage: $tripId');
|
_errorService.logInfo(
|
||||||
|
'ActivityRepository',
|
||||||
|
'Récupération des activités pour le voyage: $tripId',
|
||||||
|
);
|
||||||
|
|
||||||
// Modifié pour éviter l'erreur d'index composite
|
// Modifié pour éviter l'erreur d'index composite
|
||||||
// On récupère d'abord par tripId, puis on trie en mémoire
|
// On récupère d'abord par tripId, puis on trie en mémoire
|
||||||
final querySnapshot = await _firestore
|
final querySnapshot = await _firestore
|
||||||
@@ -51,28 +68,51 @@ class ActivityRepository {
|
|||||||
// Tri en mémoire par date de mise à jour (plus récent en premier)
|
// Tri en mémoire par date de mise à jour (plus récent en premier)
|
||||||
activities.sort((a, b) => b.updatedAt.compareTo(a.updatedAt));
|
activities.sort((a, b) => b.updatedAt.compareTo(a.updatedAt));
|
||||||
|
|
||||||
print('ActivityRepository: ${activities.length} activités trouvées');
|
_errorService.logInfo(
|
||||||
|
'ActivityRepository',
|
||||||
|
'${activities.length} activités trouvées',
|
||||||
|
);
|
||||||
return activities;
|
return activities;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityRepository: Erreur lors de la récupération: $e');
|
_errorService.logError(
|
||||||
_errorService.logError('activity_repository', 'Erreur récupération activités: $e');
|
'ActivityRepository',
|
||||||
|
'Erreur lors de la récupération: $e',
|
||||||
|
);
|
||||||
|
_errorService.logError(
|
||||||
|
'activity_repository',
|
||||||
|
'Erreur récupération activités: $e',
|
||||||
|
);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Récupère une activité par son ID (alias pour getActivityById pour compatibilité)
|
||||||
|
Future<Activity?> getActivity(String tripId, String activityId) async {
|
||||||
|
return getActivityById(activityId);
|
||||||
|
}
|
||||||
|
|
||||||
/// Récupère une activité par son ID
|
/// Récupère une activité par son ID
|
||||||
Future<Activity?> getActivityById(String activityId) async {
|
Future<Activity?> getActivityById(String activityId) async {
|
||||||
try {
|
try {
|
||||||
final doc = await _firestore.collection(_collection).doc(activityId).get();
|
final doc = await _firestore
|
||||||
|
.collection(_collection)
|
||||||
|
.doc(activityId)
|
||||||
|
.get();
|
||||||
|
|
||||||
if (doc.exists) {
|
if (doc.exists) {
|
||||||
return Activity.fromSnapshot(doc);
|
return Activity.fromSnapshot(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityRepository: Erreur récupération activité: $e');
|
_errorService.logError(
|
||||||
_errorService.logError('activity_repository', 'Erreur récupération activité: $e');
|
'ActivityRepository',
|
||||||
|
'Erreur récupération activité: $e',
|
||||||
|
);
|
||||||
|
_errorService.logError(
|
||||||
|
'activity_repository',
|
||||||
|
'Erreur récupération activité: $e',
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,18 +120,30 @@ class ActivityRepository {
|
|||||||
/// Met à jour une activité
|
/// Met à jour une activité
|
||||||
Future<bool> updateActivity(Activity activity) async {
|
Future<bool> updateActivity(Activity activity) async {
|
||||||
try {
|
try {
|
||||||
print('ActivityRepository: Mise à jour de l\'activité: ${activity.id}');
|
_errorService.logInfo(
|
||||||
|
'ActivityRepository',
|
||||||
|
'Mise à jour de l\'activité: ${activity.id}',
|
||||||
|
);
|
||||||
|
|
||||||
await _firestore
|
await _firestore
|
||||||
.collection(_collection)
|
.collection(_collection)
|
||||||
.doc(activity.id)
|
.doc(activity.id)
|
||||||
.update(activity.copyWith(updatedAt: DateTime.now()).toMap());
|
.update(activity.copyWith(updatedAt: DateTime.now()).toMap());
|
||||||
|
|
||||||
print('ActivityRepository: Activité mise à jour avec succès');
|
_errorService.logSuccess(
|
||||||
|
'ActivityRepository',
|
||||||
|
'Activité mise à jour avec succès',
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityRepository: Erreur lors de la mise à jour: $e');
|
_errorService.logError(
|
||||||
_errorService.logError('activity_repository', 'Erreur mise à jour activité: $e');
|
'ActivityRepository',
|
||||||
|
'Erreur lors de la mise à jour: $e',
|
||||||
|
);
|
||||||
|
_errorService.logError(
|
||||||
|
'activity_repository',
|
||||||
|
'Erreur mise à jour activité: $e',
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,50 +151,75 @@ class ActivityRepository {
|
|||||||
/// Supprime une activité
|
/// Supprime une activité
|
||||||
Future<bool> deleteActivity(String activityId) async {
|
Future<bool> deleteActivity(String activityId) async {
|
||||||
try {
|
try {
|
||||||
print('ActivityRepository: Suppression de l\'activité: $activityId');
|
_errorService.logInfo(
|
||||||
|
'ActivityRepository',
|
||||||
|
'Suppression de l\'activité: $activityId',
|
||||||
|
);
|
||||||
|
|
||||||
await _firestore.collection(_collection).doc(activityId).delete();
|
await _firestore.collection(_collection).doc(activityId).delete();
|
||||||
|
|
||||||
print('ActivityRepository: Activité supprimée avec succès');
|
_errorService.logSuccess(
|
||||||
|
'ActivityRepository',
|
||||||
|
'Activité supprimée avec succès',
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityRepository: Erreur lors de la suppression: $e');
|
_errorService.logError(
|
||||||
_errorService.logError('activity_repository', 'Erreur suppression activité: $e');
|
'ActivityRepository',
|
||||||
|
'Erreur lors de la suppression: $e',
|
||||||
|
);
|
||||||
|
_errorService.logError(
|
||||||
|
'activity_repository',
|
||||||
|
'Erreur suppression activité: $e',
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Vote pour une activité
|
/// Vote pour une activité
|
||||||
Future<bool> voteForActivity(String activityId, String userId, int vote) async {
|
Future<bool> voteForActivity(
|
||||||
|
String activityId,
|
||||||
|
String userId,
|
||||||
|
int vote,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
// Validation des paramètres
|
// Validation des paramètres
|
||||||
if (activityId.isEmpty) {
|
if (activityId.isEmpty) {
|
||||||
print('ActivityRepository: ID d\'activité vide');
|
_errorService.logError('ActivityRepository', 'ID d\'activité vide');
|
||||||
_errorService.logError('activity_repository', 'ID d\'activité vide pour le vote');
|
_errorService.logError(
|
||||||
|
'activity_repository',
|
||||||
|
'ID d\'activité vide pour le vote',
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userId.isEmpty) {
|
if (userId.isEmpty) {
|
||||||
print('ActivityRepository: ID d\'utilisateur vide');
|
_errorService.logError('ActivityRepository', 'ID d\'utilisateur vide');
|
||||||
_errorService.logError('activity_repository', 'ID d\'utilisateur vide pour le vote');
|
_errorService.logError(
|
||||||
|
'activity_repository',
|
||||||
|
'ID d\'utilisateur vide pour le vote',
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
print('ActivityRepository: Vote pour l\'activité $activityId: $vote');
|
_errorService.logInfo(
|
||||||
|
'ActivityRepository',
|
||||||
|
'Vote pour l\'activité $activityId: $vote',
|
||||||
|
);
|
||||||
|
|
||||||
// vote: 1 pour positif, -1 pour négatif, 0 pour supprimer le vote
|
// vote: 1 pour positif, -1 pour négatif, 0 pour supprimer le vote
|
||||||
final activityRef = _firestore.collection(_collection).doc(activityId);
|
final activityRef = _firestore.collection(_collection).doc(activityId);
|
||||||
|
|
||||||
await _firestore.runTransaction((transaction) async {
|
await _firestore.runTransaction((transaction) async {
|
||||||
final snapshot = await transaction.get(activityRef);
|
final snapshot = await transaction.get(activityRef);
|
||||||
|
|
||||||
if (!snapshot.exists) {
|
if (!snapshot.exists) {
|
||||||
throw Exception('Activité non trouvée');
|
throw Exception('Activité non trouvée');
|
||||||
}
|
}
|
||||||
|
|
||||||
final activity = Activity.fromSnapshot(snapshot);
|
final activity = Activity.fromSnapshot(snapshot);
|
||||||
final newVotes = Map<String, int>.from(activity.votes);
|
final newVotes = Map<String, int>.from(activity.votes);
|
||||||
|
|
||||||
if (vote == 0) {
|
if (vote == 0) {
|
||||||
// Supprimer le vote
|
// Supprimer le vote
|
||||||
newVotes.remove(userId);
|
newVotes.remove(userId);
|
||||||
@@ -150,17 +227,20 @@ class ActivityRepository {
|
|||||||
// Ajouter ou modifier le vote
|
// Ajouter ou modifier le vote
|
||||||
newVotes[userId] = vote;
|
newVotes[userId] = vote;
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction.update(activityRef, {
|
transaction.update(activityRef, {
|
||||||
'votes': newVotes,
|
'votes': newVotes,
|
||||||
'updatedAt': Timestamp.fromDate(DateTime.now()),
|
'updatedAt': Timestamp.fromDate(DateTime.now()),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
print('ActivityRepository: Vote enregistré avec succès');
|
_errorService.logSuccess(
|
||||||
|
'ActivityRepository',
|
||||||
|
'Vote enregistré avec succès',
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityRepository: Erreur lors du vote: $e');
|
_errorService.logError('ActivityRepository', 'Erreur lors du vote: $e');
|
||||||
_errorService.logError('activity_repository', 'Erreur vote: $e');
|
_errorService.logError('activity_repository', 'Erreur vote: $e');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -174,18 +254,24 @@ class ActivityRepository {
|
|||||||
.where('tripId', isEqualTo: tripId)
|
.where('tripId', isEqualTo: tripId)
|
||||||
.snapshots()
|
.snapshots()
|
||||||
.map((snapshot) {
|
.map((snapshot) {
|
||||||
final activities = snapshot.docs
|
final activities = snapshot.docs
|
||||||
.map((doc) => Activity.fromSnapshot(doc))
|
.map((doc) => Activity.fromSnapshot(doc))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
// Tri en mémoire par date de mise à jour (plus récent en premier)
|
// Tri en mémoire par date de mise à jour (plus récent en premier)
|
||||||
activities.sort((a, b) => b.updatedAt.compareTo(a.updatedAt));
|
activities.sort((a, b) => b.updatedAt.compareTo(a.updatedAt));
|
||||||
|
|
||||||
return activities;
|
return activities;
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityRepository: Erreur stream activités: $e');
|
_errorService.logError(
|
||||||
_errorService.logError('activity_repository', 'Erreur stream activités: $e');
|
'ActivityRepository',
|
||||||
|
'Erreur stream activités: $e',
|
||||||
|
);
|
||||||
|
_errorService.logError(
|
||||||
|
'activity_repository',
|
||||||
|
'Erreur stream activités: $e',
|
||||||
|
);
|
||||||
return Stream.value([]);
|
return Stream.value([]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,34 +279,46 @@ class ActivityRepository {
|
|||||||
/// Ajoute plusieurs activités en lot
|
/// Ajoute plusieurs activités en lot
|
||||||
Future<List<String>> addActivitiesBatch(List<Activity> activities) async {
|
Future<List<String>> addActivitiesBatch(List<Activity> activities) async {
|
||||||
try {
|
try {
|
||||||
print('ActivityRepository: Ajout en lot de ${activities.length} activités');
|
_errorService.logInfo(
|
||||||
|
'ActivityRepository',
|
||||||
|
'Ajout en lot de ${activities.length} activités',
|
||||||
|
);
|
||||||
|
|
||||||
final batch = _firestore.batch();
|
final batch = _firestore.batch();
|
||||||
final addedIds = <String>[];
|
final addedIds = <String>[];
|
||||||
|
|
||||||
for (final activity in activities) {
|
for (final activity in activities) {
|
||||||
final docRef = _firestore.collection(_collection).doc();
|
final docRef = _firestore.collection(_collection).doc();
|
||||||
final activityWithId = activity.copyWith(id: docRef.id);
|
final activityWithId = activity.copyWith(id: docRef.id);
|
||||||
batch.set(docRef, activityWithId.toMap());
|
batch.set(docRef, activityWithId.toMap());
|
||||||
addedIds.add(docRef.id);
|
addedIds.add(docRef.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
await batch.commit();
|
await batch.commit();
|
||||||
|
|
||||||
print('ActivityRepository: ${addedIds.length} activités ajoutées en lot');
|
_errorService.logSuccess(
|
||||||
|
'ActivityRepository',
|
||||||
|
'${addedIds.length} activités ajoutées en lot',
|
||||||
|
);
|
||||||
return addedIds;
|
return addedIds;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityRepository: Erreur ajout en lot: $e');
|
_errorService.logError('ActivityRepository', 'Erreur ajout en lot: $e');
|
||||||
_errorService.logError('activity_repository', 'Erreur ajout en lot: $e');
|
_errorService.logError('activity_repository', 'Erreur ajout en lot: $e');
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recherche des activités par catégorie
|
/// Recherche des activités par catégorie
|
||||||
Future<List<Activity>> getActivitiesByCategory(String tripId, String category) async {
|
Future<List<Activity>> getActivitiesByCategory(
|
||||||
|
String tripId,
|
||||||
|
String category,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
print('ActivityRepository: Recherche par catégorie: $category pour le voyage: $tripId');
|
_errorService.logInfo(
|
||||||
|
'ActivityRepository',
|
||||||
|
'Recherche par catégorie: $category pour le voyage: $tripId',
|
||||||
|
);
|
||||||
|
|
||||||
// Récupérer toutes les activités du voyage puis filtrer en mémoire
|
// Récupérer toutes les activités du voyage puis filtrer en mémoire
|
||||||
final querySnapshot = await _firestore
|
final querySnapshot = await _firestore
|
||||||
.collection(_collection)
|
.collection(_collection)
|
||||||
@@ -237,32 +335,44 @@ class ActivityRepository {
|
|||||||
|
|
||||||
return activities;
|
return activities;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityRepository: Erreur recherche par catégorie: $e');
|
_errorService.logError(
|
||||||
_errorService.logError('activity_repository', 'Erreur recherche par catégorie: $e');
|
'ActivityRepository',
|
||||||
|
'Erreur recherche par catégorie: $e',
|
||||||
|
);
|
||||||
|
_errorService.logError(
|
||||||
|
'activity_repository',
|
||||||
|
'Erreur recherche par catégorie: $e',
|
||||||
|
);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Récupère les activités les mieux notées d'un voyage
|
/// Récupère les activités les mieux notées d'un voyage
|
||||||
Future<List<Activity>> getTopRatedActivities(String tripId, {int limit = 10}) async {
|
Future<List<Activity>> getTopRatedActivities(
|
||||||
|
String tripId, {
|
||||||
|
int limit = 10,
|
||||||
|
}) async {
|
||||||
try {
|
try {
|
||||||
final activities = await getActivitiesByTrip(tripId);
|
final activities = await getActivitiesByTrip(tripId);
|
||||||
|
|
||||||
// Trier par nombre de votes positifs puis par note Google
|
// Trier par nombre de votes positifs puis par note Google
|
||||||
activities.sort((a, b) {
|
activities.sort((a, b) {
|
||||||
final aScore = a.totalVotes;
|
final aScore = a.totalVotes;
|
||||||
final bScore = b.totalVotes;
|
final bScore = b.totalVotes;
|
||||||
|
|
||||||
if (aScore != bScore) {
|
if (aScore != bScore) {
|
||||||
return bScore.compareTo(aScore);
|
return bScore.compareTo(aScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (b.rating ?? 0).compareTo(a.rating ?? 0);
|
return (b.rating ?? 0).compareTo(a.rating ?? 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
return activities.take(limit).toList();
|
return activities.take(limit).toList();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityRepository: Erreur activités top rated: $e');
|
_errorService.logError(
|
||||||
|
'ActivityRepository',
|
||||||
|
'Erreur activités top rated: $e',
|
||||||
|
);
|
||||||
_errorService.logError('activity_repository', 'Erreur top rated: $e');
|
_errorService.logError('activity_repository', 'Erreur top rated: $e');
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -281,11 +391,14 @@ class ActivityRepository {
|
|||||||
if (querySnapshot.docs.isNotEmpty) {
|
if (querySnapshot.docs.isNotEmpty) {
|
||||||
return Activity.fromSnapshot(querySnapshot.docs.first);
|
return Activity.fromSnapshot(querySnapshot.docs.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityRepository: Erreur recherche activité existante: $e');
|
_errorService.logError(
|
||||||
|
'ActivityRepository',
|
||||||
|
'Erreur recherche activité existante: $e',
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
import 'package:travel_mate/services/error_service.dart';
|
import 'package:travel_mate/services/error_service.dart';
|
||||||
import '../models/group.dart';
|
import '../models/group.dart';
|
||||||
import '../models/group_member.dart';
|
import '../models/group_member.dart';
|
||||||
|
|
||||||
class GroupRepository {
|
class GroupRepository {
|
||||||
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
|
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
|
||||||
|
final FirebaseAuth _auth = FirebaseAuth.instance;
|
||||||
final _errorService = ErrorService();
|
final _errorService = ErrorService();
|
||||||
|
|
||||||
CollectionReference get _groupsCollection => _firestore.collection('groups');
|
CollectionReference get _groupsCollection => _firestore.collection('groups');
|
||||||
@@ -20,8 +22,10 @@ class GroupRepository {
|
|||||||
try {
|
try {
|
||||||
return await _firestore.runTransaction<String>((transaction) async {
|
return await _firestore.runTransaction<String>((transaction) async {
|
||||||
final groupRef = _groupsCollection.doc();
|
final groupRef = _groupsCollection.doc();
|
||||||
|
|
||||||
final groupData = group.toMap();
|
// Ajouter les IDs des membres à la liste memberIds
|
||||||
|
final memberIds = members.map((m) => m.userId).toList();
|
||||||
|
final groupData = group.copyWith(memberIds: memberIds).toMap();
|
||||||
transaction.set(groupRef, groupData);
|
transaction.set(groupRef, groupData);
|
||||||
|
|
||||||
for (var member in members) {
|
for (var member in members) {
|
||||||
@@ -36,52 +40,15 @@ class GroupRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream<List<Group>> getGroupsByUserId(String userId) {
|
Stream<List<Group>> getGroupsByUserId(String userId) {
|
||||||
return _groupsCollection
|
return _groupsCollection
|
||||||
|
.where('memberIds', arrayContains: userId)
|
||||||
.snapshots()
|
.snapshots()
|
||||||
.asyncMap((snapshot) async {
|
.map((snapshot) {
|
||||||
|
return snapshot.docs.map((doc) {
|
||||||
List<Group> userGroups = [];
|
final groupData = doc.data() as Map<String, dynamic>;
|
||||||
|
return Group.fromMap(groupData, doc.id);
|
||||||
for (var groupDoc in snapshot.docs) {
|
}).toList();
|
||||||
try {
|
|
||||||
final groupId = groupDoc.id;
|
|
||||||
|
|
||||||
// Vérifier si l'utilisateur est membre
|
|
||||||
final memberDoc = await groupDoc.reference
|
|
||||||
.collection('members')
|
|
||||||
.doc(userId)
|
|
||||||
.get();
|
|
||||||
|
|
||||||
if (memberDoc.exists) {
|
|
||||||
final groupData = groupDoc.data() as Map<String, dynamic>;
|
|
||||||
final group = Group.fromMap(groupData, groupId);
|
|
||||||
|
|
||||||
final members = await getGroupMembers(groupId);
|
|
||||||
userGroups.add(group.copyWith(members: members));
|
|
||||||
} else {
|
|
||||||
_errorService.logInfo('group_repository.dart','Utilisateur NON membre de $groupId');
|
|
||||||
}
|
|
||||||
} catch (e, stackTrace) {
|
|
||||||
_errorService.logError(e.toString(), stackTrace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return userGroups;
|
|
||||||
})
|
|
||||||
.distinct((prev, next) {
|
|
||||||
// Comparer les listes pour éviter les doublons
|
|
||||||
if (prev.length != next.length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vérifier si les IDs sont identiques
|
|
||||||
final prevIds = prev.map((g) => g.id).toSet();
|
|
||||||
final nextIds = next.map((g) => g.id).toSet();
|
|
||||||
|
|
||||||
final identical = prevIds.difference(nextIds).isEmpty &&
|
|
||||||
nextIds.difference(prevIds).isEmpty;
|
|
||||||
|
|
||||||
return identical;
|
|
||||||
})
|
})
|
||||||
.handleError((error, stackTrace) {
|
.handleError((error, stackTrace) {
|
||||||
_errorService.logError(error, stackTrace);
|
_errorService.logError(error, stackTrace);
|
||||||
@@ -92,12 +59,12 @@ class GroupRepository {
|
|||||||
Future<Group?> getGroupById(String groupId) async {
|
Future<Group?> getGroupById(String groupId) async {
|
||||||
try {
|
try {
|
||||||
final doc = await _groupsCollection.doc(groupId).get();
|
final doc = await _groupsCollection.doc(groupId).get();
|
||||||
|
|
||||||
if (!doc.exists) return null;
|
if (!doc.exists) return null;
|
||||||
|
|
||||||
final group = Group.fromMap(doc.data() as Map<String, dynamic>, doc.id);
|
final group = Group.fromMap(doc.data() as Map<String, dynamic>, doc.id);
|
||||||
final members = await getGroupMembers(groupId);
|
final members = await getGroupMembers(groupId);
|
||||||
|
|
||||||
return group.copyWith(members: members);
|
return group.copyWith(members: members);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Erreur lors de la récupération du groupe: $e');
|
throw Exception('Erreur lors de la récupération du groupe: $e');
|
||||||
@@ -106,34 +73,69 @@ class GroupRepository {
|
|||||||
|
|
||||||
Future<Group?> getGroupByTripId(String tripId) async {
|
Future<Group?> getGroupByTripId(String tripId) async {
|
||||||
try {
|
try {
|
||||||
final querySnapshot = await _groupsCollection
|
final userId = _auth.currentUser?.uid;
|
||||||
|
if (userId == null) return null;
|
||||||
|
|
||||||
|
// Tentative 1: Requête optimisée avec memberIds
|
||||||
|
var querySnapshot = await _groupsCollection
|
||||||
.where('tripId', isEqualTo: tripId)
|
.where('tripId', isEqualTo: tripId)
|
||||||
|
.where('memberIds', arrayContains: userId)
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
|
// Tentative 2: Fallback pour le créateur (si memberIds est manquant - anciennes données)
|
||||||
|
if (querySnapshot.docs.isEmpty) {
|
||||||
|
querySnapshot = await _groupsCollection
|
||||||
|
.where('tripId', isEqualTo: tripId)
|
||||||
|
.where('createdBy', isEqualTo: userId)
|
||||||
|
.limit(1)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
// Si on trouve le groupe via le fallback, on lance une migration
|
||||||
|
if (querySnapshot.docs.isNotEmpty) {
|
||||||
|
_migrateGroupData(querySnapshot.docs.first.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (querySnapshot.docs.isEmpty) return null;
|
if (querySnapshot.docs.isEmpty) return null;
|
||||||
|
|
||||||
final doc = querySnapshot.docs.first;
|
final doc = querySnapshot.docs.first;
|
||||||
final group = Group.fromMap(doc.data() as Map<String, dynamic>, doc.id);
|
final group = Group.fromMap(doc.data() as Map<String, dynamic>, doc.id);
|
||||||
final members = await getGroupMembers(doc.id);
|
final members = await getGroupMembers(doc.id);
|
||||||
|
|
||||||
return group.copyWith(members: members);
|
return group.copyWith(members: members);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Erreur lors de la récupération du groupe: $e');
|
throw Exception('Erreur lors de la récupération du groupe: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Méthode utilitaire pour migrer les anciennes données
|
||||||
|
Future<void> _migrateGroupData(String groupId) async {
|
||||||
|
try {
|
||||||
|
final members = await getGroupMembers(groupId);
|
||||||
|
final memberIds = members.map((m) => m.userId).toList();
|
||||||
|
|
||||||
|
if (memberIds.isNotEmpty) {
|
||||||
|
await _groupsCollection.doc(groupId).update({'memberIds': memberIds});
|
||||||
|
_errorService.logSuccess(
|
||||||
|
'GroupRepository',
|
||||||
|
'Migration réussie pour le groupe $groupId',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
_errorService.logError(
|
||||||
|
'GroupRepository',
|
||||||
|
'Erreur de migration pour le groupe $groupId: $e',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<List<GroupMember>> getGroupMembers(String groupId) async {
|
Future<List<GroupMember>> getGroupMembers(String groupId) async {
|
||||||
try {
|
try {
|
||||||
final snapshot = await _membersCollection(groupId).get();
|
final snapshot = await _membersCollection(groupId).get();
|
||||||
return snapshot.docs
|
return snapshot.docs.map((doc) {
|
||||||
.map((doc) {
|
return GroupMember.fromMap(doc.data() as Map<String, dynamic>, doc.id);
|
||||||
return GroupMember.fromMap(
|
}).toList();
|
||||||
doc.data() as Map<String, dynamic>,
|
|
||||||
doc.id,
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.toList();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Erreur lors de la récupération des membres: $e');
|
throw Exception('Erreur lors de la récupération des membres: $e');
|
||||||
}
|
}
|
||||||
@@ -141,10 +143,22 @@ class GroupRepository {
|
|||||||
|
|
||||||
Future<void> addMember(String groupId, GroupMember member) async {
|
Future<void> addMember(String groupId, GroupMember member) async {
|
||||||
try {
|
try {
|
||||||
|
// 1. Récupérer le groupe pour avoir le tripId
|
||||||
|
final group = await getGroupById(groupId);
|
||||||
|
if (group == null) throw Exception('Groupe introuvable');
|
||||||
|
|
||||||
|
// 2. Ajouter le membre dans la sous-collection members du groupe
|
||||||
await _membersCollection(groupId).doc(member.userId).set(member.toMap());
|
await _membersCollection(groupId).doc(member.userId).set(member.toMap());
|
||||||
|
|
||||||
|
// 3. Mettre à jour la liste memberIds du groupe
|
||||||
await _groupsCollection.doc(groupId).update({
|
await _groupsCollection.doc(groupId).update({
|
||||||
'updatedAt': DateTime.now().millisecondsSinceEpoch,
|
'updatedAt': DateTime.now().millisecondsSinceEpoch,
|
||||||
|
'memberIds': FieldValue.arrayUnion([member.userId]),
|
||||||
|
});
|
||||||
|
|
||||||
|
// 4. Mettre à jour la liste participants du voyage
|
||||||
|
await _firestore.collection('trips').doc(group.tripId).update({
|
||||||
|
'participants': FieldValue.arrayUnion([member.userId]),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Erreur lors de l\'ajout du membre: $e');
|
throw Exception('Erreur lors de l\'ajout du membre: $e');
|
||||||
@@ -153,10 +167,22 @@ class GroupRepository {
|
|||||||
|
|
||||||
Future<void> removeMember(String groupId, String userId) async {
|
Future<void> removeMember(String groupId, String userId) async {
|
||||||
try {
|
try {
|
||||||
|
// 1. Récupérer le groupe pour avoir le tripId
|
||||||
|
final group = await getGroupById(groupId);
|
||||||
|
if (group == null) throw Exception('Groupe introuvable');
|
||||||
|
|
||||||
|
// 2. Supprimer le membre de la sous-collection members du groupe
|
||||||
await _membersCollection(groupId).doc(userId).delete();
|
await _membersCollection(groupId).doc(userId).delete();
|
||||||
|
|
||||||
|
// 3. Mettre à jour la liste memberIds du groupe
|
||||||
await _groupsCollection.doc(groupId).update({
|
await _groupsCollection.doc(groupId).update({
|
||||||
'updatedAt': DateTime.now().millisecondsSinceEpoch,
|
'updatedAt': DateTime.now().millisecondsSinceEpoch,
|
||||||
|
'memberIds': FieldValue.arrayRemove([userId]),
|
||||||
|
});
|
||||||
|
|
||||||
|
// 4. Mettre à jour la liste participants du voyage
|
||||||
|
await _firestore.collection('trips').doc(group.tripId).update({
|
||||||
|
'participants': FieldValue.arrayRemove([userId]),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Erreur lors de la suppression du membre: $e');
|
throw Exception('Erreur lors de la suppression du membre: $e');
|
||||||
@@ -165,8 +191,11 @@ class GroupRepository {
|
|||||||
|
|
||||||
Future<void> updateGroup(String groupId, Group group) async {
|
Future<void> updateGroup(String groupId, Group group) async {
|
||||||
try {
|
try {
|
||||||
await _groupsCollection.doc(groupId).update(
|
await _groupsCollection
|
||||||
group.toMap()..['updatedAt'] = DateTime.now().millisecondsSinceEpoch,
|
.doc(groupId)
|
||||||
|
.update(
|
||||||
|
group.toMap()
|
||||||
|
..['updatedAt'] = DateTime.now().millisecondsSinceEpoch,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Erreur lors de la mise à jour du groupe: $e');
|
throw Exception('Erreur lors de la mise à jour du groupe: $e');
|
||||||
@@ -174,38 +203,42 @@ class GroupRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteGroup(String tripId) async {
|
Future<void> deleteGroup(String tripId) async {
|
||||||
try {
|
try {
|
||||||
final querySnapshot = await _groupsCollection
|
final userId = _auth.currentUser?.uid;
|
||||||
.where('tripId', isEqualTo: tripId)
|
if (userId == null) throw Exception('Utilisateur non connecté');
|
||||||
.limit(1)
|
|
||||||
.get();
|
|
||||||
|
|
||||||
if (querySnapshot.docs.isEmpty) {
|
final querySnapshot = await _groupsCollection
|
||||||
throw Exception('Aucun groupe trouvé pour ce voyage');
|
.where('tripId', isEqualTo: tripId)
|
||||||
|
.where('createdBy', isEqualTo: userId)
|
||||||
|
.limit(1)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
if (querySnapshot.docs.isEmpty) {
|
||||||
|
throw Exception('Aucun groupe trouvé pour ce voyage');
|
||||||
|
}
|
||||||
|
|
||||||
|
final groupDoc = querySnapshot.docs.first;
|
||||||
|
final groupId = groupDoc.id;
|
||||||
|
|
||||||
|
final membersSnapshot = await _membersCollection(groupId).get();
|
||||||
|
for (var doc in membersSnapshot.docs) {
|
||||||
|
await doc.reference.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
await _groupsCollection.doc(groupId).delete();
|
||||||
|
} catch (e) {
|
||||||
|
throw Exception('Erreur lors de la suppression du groupe: $e');
|
||||||
}
|
}
|
||||||
|
|
||||||
final groupDoc = querySnapshot.docs.first;
|
|
||||||
final groupId = groupDoc.id;
|
|
||||||
|
|
||||||
final membersSnapshot = await _membersCollection(groupId).get();
|
|
||||||
for (var doc in membersSnapshot.docs) {
|
|
||||||
await doc.reference.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
await _groupsCollection.doc(groupId).delete();
|
|
||||||
} catch (e) {
|
|
||||||
throw Exception('Erreur lors de la suppression du groupe: $e');
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Stream<List<GroupMember>> watchGroupMembers(String groupId) {
|
Stream<List<GroupMember>> watchGroupMembers(String groupId) {
|
||||||
return _membersCollection(groupId).snapshots().map(
|
return _membersCollection(groupId).snapshots().map(
|
||||||
(snapshot) => snapshot.docs
|
(snapshot) => snapshot.docs
|
||||||
.map((doc) => GroupMember.fromMap(
|
.map(
|
||||||
doc.data() as Map<String, dynamic>,
|
(doc) =>
|
||||||
doc.id,
|
GroupMember.fromMap(doc.data() as Map<String, dynamic>, doc.id),
|
||||||
))
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class MessageRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supprimer un message
|
// Supprimer un message (marquer comme supprimé)
|
||||||
Future<void> deleteMessage({
|
Future<void> deleteMessage({
|
||||||
required String groupId,
|
required String groupId,
|
||||||
required String messageId,
|
required String messageId,
|
||||||
@@ -52,7 +52,10 @@ class MessageRepository {
|
|||||||
.doc(groupId)
|
.doc(groupId)
|
||||||
.collection('messages')
|
.collection('messages')
|
||||||
.doc(messageId)
|
.doc(messageId)
|
||||||
.delete();
|
.update({
|
||||||
|
'isDeleted': true,
|
||||||
|
'text': '',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifier un message
|
// Modifier un message
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:http/http.dart' as http;
|
|||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import '../models/activity.dart';
|
import '../models/activity.dart';
|
||||||
import '../services/error_service.dart';
|
import '../services/error_service.dart';
|
||||||
|
import '../services/logger_service.dart';
|
||||||
|
|
||||||
/// Service pour rechercher des activités touristiques via Google Places API
|
/// Service pour rechercher des activités touristiques via Google Places API
|
||||||
class ActivityPlacesService {
|
class ActivityPlacesService {
|
||||||
@@ -24,7 +25,7 @@ class ActivityPlacesService {
|
|||||||
int offset = 0,
|
int offset = 0,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
print(
|
LoggerService.info(
|
||||||
'ActivityPlacesService: Recherche d\'activités pour: $destination (max: $maxResults, offset: $offset)',
|
'ActivityPlacesService: Recherche d\'activités pour: $destination (max: $maxResults, offset: $offset)',
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ class ActivityPlacesService {
|
|||||||
final uniqueActivities = _removeDuplicates(allActivities);
|
final uniqueActivities = _removeDuplicates(allActivities);
|
||||||
uniqueActivities.sort((a, b) => (b.rating ?? 0).compareTo(a.rating ?? 0));
|
uniqueActivities.sort((a, b) => (b.rating ?? 0).compareTo(a.rating ?? 0));
|
||||||
|
|
||||||
print(
|
LoggerService.info(
|
||||||
'ActivityPlacesService: ${uniqueActivities.length} activités trouvées au total',
|
'ActivityPlacesService: ${uniqueActivities.length} activités trouvées au total',
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -81,20 +82,22 @@ class ActivityPlacesService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (startIndex >= uniqueActivities.length) {
|
if (startIndex >= uniqueActivities.length) {
|
||||||
print(
|
LoggerService.info(
|
||||||
'ActivityPlacesService: Offset $startIndex dépasse le nombre total (${uniqueActivities.length})',
|
'ActivityPlacesService: Offset $startIndex dépasse le nombre total (${uniqueActivities.length})',
|
||||||
);
|
);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
final paginatedResults = uniqueActivities.sublist(startIndex, endIndex);
|
final paginatedResults = uniqueActivities.sublist(startIndex, endIndex);
|
||||||
print(
|
LoggerService.info(
|
||||||
'ActivityPlacesService: Retour de ${paginatedResults.length} activités (offset: $offset, max: $maxResults)',
|
'ActivityPlacesService: Retour de ${paginatedResults.length} activités (offset: $offset, max: $maxResults)',
|
||||||
);
|
);
|
||||||
|
|
||||||
return paginatedResults;
|
return paginatedResults;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityPlacesService: Erreur lors de la recherche: $e');
|
LoggerService.error(
|
||||||
|
'ActivityPlacesService: Erreur lors de la recherche: $e',
|
||||||
|
);
|
||||||
_errorService.logError('activity_places_service', e);
|
_errorService.logError('activity_places_service', e);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -105,7 +108,9 @@ class ActivityPlacesService {
|
|||||||
try {
|
try {
|
||||||
// Vérifier que la clé API est configurée
|
// Vérifier que la clé API est configurée
|
||||||
if (_apiKey.isEmpty) {
|
if (_apiKey.isEmpty) {
|
||||||
print('ActivityPlacesService: Clé API Google Maps manquante');
|
LoggerService.error(
|
||||||
|
'ActivityPlacesService: Clé API Google Maps manquante',
|
||||||
|
);
|
||||||
throw Exception('Clé API Google Maps non configurée');
|
throw Exception('Clé API Google Maps non configurée');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,16 +118,20 @@ class ActivityPlacesService {
|
|||||||
final url =
|
final url =
|
||||||
'https://maps.googleapis.com/maps/api/geocode/json?address=$encodedDestination&key=$_apiKey';
|
'https://maps.googleapis.com/maps/api/geocode/json?address=$encodedDestination&key=$_apiKey';
|
||||||
|
|
||||||
print('ActivityPlacesService: Géocodage de "$destination"');
|
LoggerService.info('ActivityPlacesService: Géocodage de "$destination"');
|
||||||
print('ActivityPlacesService: URL = $url');
|
LoggerService.info('ActivityPlacesService: URL = $url');
|
||||||
|
|
||||||
final response = await http.get(Uri.parse(url));
|
final response = await http.get(Uri.parse(url));
|
||||||
|
|
||||||
print('ActivityPlacesService: Status code = ${response.statusCode}');
|
LoggerService.info(
|
||||||
|
'ActivityPlacesService: Status code = ${response.statusCode}',
|
||||||
|
);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
print('ActivityPlacesService: Réponse géocodage = ${data['status']}');
|
LoggerService.info(
|
||||||
|
'ActivityPlacesService: Réponse géocodage = ${data['status']}',
|
||||||
|
);
|
||||||
|
|
||||||
if (data['status'] == 'OK' && data['results'].isNotEmpty) {
|
if (data['status'] == 'OK' && data['results'].isNotEmpty) {
|
||||||
final location = data['results'][0]['geometry']['location'];
|
final location = data['results'][0]['geometry']['location'];
|
||||||
@@ -130,10 +139,12 @@ class ActivityPlacesService {
|
|||||||
'lat': location['lat'].toDouble(),
|
'lat': location['lat'].toDouble(),
|
||||||
'lng': location['lng'].toDouble(),
|
'lng': location['lng'].toDouble(),
|
||||||
};
|
};
|
||||||
print('ActivityPlacesService: Coordonnées trouvées = $coordinates');
|
LoggerService.info(
|
||||||
|
'ActivityPlacesService: Coordonnées trouvées = $coordinates',
|
||||||
|
);
|
||||||
return coordinates;
|
return coordinates;
|
||||||
} else {
|
} else {
|
||||||
print(
|
LoggerService.error(
|
||||||
'ActivityPlacesService: Erreur API = ${data['error_message'] ?? data['status']}',
|
'ActivityPlacesService: Erreur API = ${data['error_message'] ?? data['status']}',
|
||||||
);
|
);
|
||||||
if (data['status'] == 'REQUEST_DENIED') {
|
if (data['status'] == 'REQUEST_DENIED') {
|
||||||
@@ -154,7 +165,7 @@ class ActivityPlacesService {
|
|||||||
throw Exception('Erreur HTTP ${response.statusCode}');
|
throw Exception('Erreur HTTP ${response.statusCode}');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityPlacesService: Erreur géocodage: $e');
|
LoggerService.error('ActivityPlacesService: Erreur géocodage: $e');
|
||||||
rethrow; // Rethrow pour permettre la gestion d'erreur en amont
|
rethrow; // Rethrow pour permettre la gestion d'erreur en amont
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,7 +205,9 @@ class ActivityPlacesService {
|
|||||||
activities.add(activity);
|
activities.add(activity);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityPlacesService: Erreur conversion place: $e');
|
LoggerService.error(
|
||||||
|
'ActivityPlacesService: Erreur conversion place: $e',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +217,9 @@ class ActivityPlacesService {
|
|||||||
|
|
||||||
return [];
|
return [];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityPlacesService: Erreur recherche par catégorie: $e');
|
LoggerService.error(
|
||||||
|
'ActivityPlacesService: Erreur recherche par catégorie: $e',
|
||||||
|
);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,7 +275,7 @@ class ActivityPlacesService {
|
|||||||
updatedAt: DateTime.now(),
|
updatedAt: DateTime.now(),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityPlacesService: Erreur conversion place: $e');
|
LoggerService.error('ActivityPlacesService: Erreur conversion place: $e');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,7 +300,9 @@ class ActivityPlacesService {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityPlacesService: Erreur récupération détails: $e');
|
LoggerService.error(
|
||||||
|
'ActivityPlacesService: Erreur récupération détails: $e',
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -326,7 +343,7 @@ class ActivityPlacesService {
|
|||||||
int radius = 5000,
|
int radius = 5000,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
print(
|
LoggerService.info(
|
||||||
'ActivityPlacesService: Recherche textuelle: $query à $destination',
|
'ActivityPlacesService: Recherche textuelle: $query à $destination',
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -364,7 +381,9 @@ class ActivityPlacesService {
|
|||||||
activities.add(activity);
|
activities.add(activity);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityPlacesService: Erreur conversion place: $e');
|
LoggerService.error(
|
||||||
|
'ActivityPlacesService: Erreur conversion place: $e',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,7 +393,9 @@ class ActivityPlacesService {
|
|||||||
|
|
||||||
return [];
|
return [];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityPlacesService: Erreur recherche textuelle: $e');
|
LoggerService.error(
|
||||||
|
'ActivityPlacesService: Erreur recherche textuelle: $e',
|
||||||
|
);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -423,11 +444,11 @@ class ActivityPlacesService {
|
|||||||
if (latitude != null && longitude != null) {
|
if (latitude != null && longitude != null) {
|
||||||
lat = latitude;
|
lat = latitude;
|
||||||
lng = longitude;
|
lng = longitude;
|
||||||
print(
|
LoggerService.info(
|
||||||
'ActivityPlacesService: Utilisation des coordonnées pré-géolocalisées: $lat, $lng',
|
'ActivityPlacesService: Utilisation des coordonnées pré-géolocalisées: $lat, $lng',
|
||||||
);
|
);
|
||||||
} else if (destination != null) {
|
} else if (destination != null) {
|
||||||
print(
|
LoggerService.info(
|
||||||
'ActivityPlacesService: Géolocalisation de la destination: $destination',
|
'ActivityPlacesService: Géolocalisation de la destination: $destination',
|
||||||
);
|
);
|
||||||
final coordinates = await _geocodeDestination(destination);
|
final coordinates = await _geocodeDestination(destination);
|
||||||
@@ -437,7 +458,7 @@ class ActivityPlacesService {
|
|||||||
throw Exception('Destination ou coordonnées requises');
|
throw Exception('Destination ou coordonnées requises');
|
||||||
}
|
}
|
||||||
|
|
||||||
print(
|
LoggerService.info(
|
||||||
'ActivityPlacesService: Recherche paginée aux coordonnées: $lat, $lng (page: ${nextPageToken ?? "première"})',
|
'ActivityPlacesService: Recherche paginée aux coordonnées: $lat, $lng (page: ${nextPageToken ?? "première"})',
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -464,7 +485,9 @@ class ActivityPlacesService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityPlacesService: Erreur recherche paginée: $e');
|
LoggerService.error(
|
||||||
|
'ActivityPlacesService: Erreur recherche paginée: $e',
|
||||||
|
);
|
||||||
_errorService.logError('activity_places_service', e);
|
_errorService.logError('activity_places_service', e);
|
||||||
return {
|
return {
|
||||||
'activities': <Activity>[],
|
'activities': <Activity>[],
|
||||||
@@ -519,7 +542,9 @@ class ActivityPlacesService {
|
|||||||
activities.add(activity);
|
activities.add(activity);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityPlacesService: Erreur conversion place: $e');
|
LoggerService.error(
|
||||||
|
'ActivityPlacesService: Erreur conversion place: $e',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -537,7 +562,9 @@ class ActivityPlacesService {
|
|||||||
'hasMoreData': false,
|
'hasMoreData': false,
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityPlacesService: Erreur recherche catégorie paginée: $e');
|
LoggerService.error(
|
||||||
|
'ActivityPlacesService: Erreur recherche catégorie paginée: $e',
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
'activities': <Activity>[],
|
'activities': <Activity>[],
|
||||||
'nextPageToken': null,
|
'nextPageToken': null,
|
||||||
@@ -595,7 +622,9 @@ class ActivityPlacesService {
|
|||||||
activities.add(activity);
|
activities.add(activity);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ActivityPlacesService: Erreur conversion place: $e');
|
LoggerService.error(
|
||||||
|
'ActivityPlacesService: Erreur conversion place: $e',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,7 +642,7 @@ class ActivityPlacesService {
|
|||||||
'hasMoreData': false,
|
'hasMoreData': false,
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(
|
LoggerService.error(
|
||||||
'ActivityPlacesService: Erreur recherche toutes catégories paginée: $e',
|
'ActivityPlacesService: Erreur recherche toutes catégories paginée: $e',
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
/// - [Settlement] for individual payment recommendations
|
/// - [Settlement] for individual payment recommendations
|
||||||
/// - [UserBalance] for per-user balance information
|
/// - [UserBalance] for per-user balance information
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import '../models/group_balance.dart';
|
import '../models/group_balance.dart';
|
||||||
import '../models/expense.dart';
|
import '../models/expense.dart';
|
||||||
import '../models/group_statistics.dart';
|
import '../models/group_statistics.dart';
|
||||||
@@ -59,7 +60,10 @@ class BalanceService {
|
|||||||
try {
|
try {
|
||||||
return await _balanceRepository.calculateGroupBalance(groupId);
|
return await _balanceRepository.calculateGroupBalance(groupId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('BalanceService', 'Erreur calcul balance groupe: $e');
|
_errorService.logError(
|
||||||
|
'BalanceService',
|
||||||
|
'Erreur calcul balance groupe: $e',
|
||||||
|
);
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,7 +84,9 @@ class BalanceService {
|
|||||||
|
|
||||||
/// Stream de la balance en temps réel
|
/// Stream de la balance en temps réel
|
||||||
Stream<GroupBalance> getGroupBalanceStream(String groupId) {
|
Stream<GroupBalance> getGroupBalanceStream(String groupId) {
|
||||||
return _expenseRepository.getExpensesStream(groupId).asyncMap((expenses) async {
|
return _expenseRepository.getExpensesStream(groupId).asyncMap((
|
||||||
|
expenses,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
final userBalances = calculateUserBalances(expenses);
|
final userBalances = calculateUserBalances(expenses);
|
||||||
final settlements = optimizeSettlements(userBalances);
|
final settlements = optimizeSettlements(userBalances);
|
||||||
@@ -145,7 +151,7 @@ class BalanceService {
|
|||||||
/// Optimiser les règlements (algorithme avancé)
|
/// Optimiser les règlements (algorithme avancé)
|
||||||
List<Settlement> optimizeSettlements(List<UserBalance> balances) {
|
List<Settlement> optimizeSettlements(List<UserBalance> balances) {
|
||||||
final settlements = <Settlement>[];
|
final settlements = <Settlement>[];
|
||||||
|
|
||||||
// Filtrer les utilisateurs avec une balance significative (> 0.01€)
|
// Filtrer les utilisateurs avec une balance significative (> 0.01€)
|
||||||
final creditors = balances
|
final creditors = balances
|
||||||
.where((b) => b.shouldReceive && b.balance > 0.01)
|
.where((b) => b.shouldReceive && b.balance > 0.01)
|
||||||
@@ -164,10 +170,10 @@ class BalanceService {
|
|||||||
|
|
||||||
// Utiliser des copies mutables pour les calculs
|
// Utiliser des copies mutables pour les calculs
|
||||||
final creditorsRemaining = Map<String, double>.fromEntries(
|
final creditorsRemaining = Map<String, double>.fromEntries(
|
||||||
creditors.map((c) => MapEntry(c.userId, c.balance))
|
creditors.map((c) => MapEntry(c.userId, c.balance)),
|
||||||
);
|
);
|
||||||
final debtorsRemaining = Map<String, double>.fromEntries(
|
final debtorsRemaining = Map<String, double>.fromEntries(
|
||||||
debtors.map((d) => MapEntry(d.userId, -d.balance))
|
debtors.map((d) => MapEntry(d.userId, -d.balance)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Algorithme glouton optimisé
|
// Algorithme glouton optimisé
|
||||||
@@ -185,16 +191,19 @@ class BalanceService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (settlementAmount > 0.01) {
|
if (settlementAmount > 0.01) {
|
||||||
settlements.add(Settlement(
|
settlements.add(
|
||||||
fromUserId: debtor.userId,
|
Settlement(
|
||||||
fromUserName: debtor.userName,
|
fromUserId: debtor.userId,
|
||||||
toUserId: creditor.userId,
|
fromUserName: debtor.userName,
|
||||||
toUserName: creditor.userName,
|
toUserId: creditor.userId,
|
||||||
amount: settlementAmount,
|
toUserName: creditor.userName,
|
||||||
));
|
amount: settlementAmount,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// Mettre à jour les montants restants
|
// Mettre à jour les montants restants
|
||||||
creditorsRemaining[creditor.userId] = creditRemaining - settlementAmount;
|
creditorsRemaining[creditor.userId] =
|
||||||
|
creditRemaining - settlementAmount;
|
||||||
debtorsRemaining[debtor.userId] = debtRemaining - settlementAmount;
|
debtorsRemaining[debtor.userId] = debtRemaining - settlementAmount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,7 +213,10 @@ class BalanceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Calculer le montant optimal pour un règlement
|
/// Calculer le montant optimal pour un règlement
|
||||||
double _calculateOptimalSettlementAmount(double creditAmount, double debtAmount) {
|
double _calculateOptimalSettlementAmount(
|
||||||
|
double creditAmount,
|
||||||
|
double debtAmount,
|
||||||
|
) {
|
||||||
final amount = [creditAmount, debtAmount].reduce((a, b) => a < b ? a : b);
|
final amount = [creditAmount, debtAmount].reduce((a, b) => a < b ? a : b);
|
||||||
// Arrondir à 2 décimales
|
// Arrondir à 2 décimales
|
||||||
return (amount * 100).round() / 100;
|
return (amount * 100).round() / 100;
|
||||||
@@ -213,36 +225,50 @@ class BalanceService {
|
|||||||
/// Valider les règlements calculés
|
/// Valider les règlements calculés
|
||||||
List<Settlement> _validateSettlements(List<Settlement> settlements) {
|
List<Settlement> _validateSettlements(List<Settlement> settlements) {
|
||||||
// Supprimer les règlements trop petits
|
// Supprimer les règlements trop petits
|
||||||
final validSettlements = settlements
|
final validSettlements = settlements.where((s) => s.amount > 0.01).toList();
|
||||||
.where((s) => s.amount > 0.01)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
// Log pour debug en cas de problème
|
// Log pour debug en cas de problème
|
||||||
final totalSettlements = validSettlements.fold(0.0, (sum, s) => sum + s.amount);
|
final totalSettlements = validSettlements.fold(
|
||||||
_errorService.logInfo('BalanceService',
|
0.0,
|
||||||
'Règlements calculés: ${validSettlements.length}, Total: ${totalSettlements.toStringAsFixed(2)}€');
|
(sum, s) => sum + s.amount,
|
||||||
|
);
|
||||||
|
_errorService.logInfo(
|
||||||
|
'BalanceService',
|
||||||
|
'Règlements calculés: ${validSettlements.length}, Total: ${totalSettlements.toStringAsFixed(2)}€',
|
||||||
|
);
|
||||||
|
|
||||||
return validSettlements;
|
return validSettlements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculer la dette entre deux utilisateurs spécifiques
|
/// Calculer la dette entre deux utilisateurs spécifiques
|
||||||
double calculateDebtBetweenUsers(String groupId, String userId1, String userId2) {
|
double calculateDebtBetweenUsers(
|
||||||
|
String groupId,
|
||||||
|
String userId1,
|
||||||
|
String userId2,
|
||||||
|
) {
|
||||||
// Cette méthode pourrait être utile pour des fonctionnalités avancées
|
// Cette méthode pourrait être utile pour des fonctionnalités avancées
|
||||||
// comme "Combien me doit X ?" ou "Combien je dois à Y ?"
|
// comme "Combien me doit X ?" ou "Combien je dois à Y ?"
|
||||||
return 0.0; // TODO: Implémenter si nécessaire
|
|
||||||
|
// On peut utiliser optimizeSettlements pour avoir la réponse précise
|
||||||
|
// Cependant, cela nécessite d'avoir les dépenses.
|
||||||
|
// Comme cette méthode est synchrone et ne prend pas les dépenses en entrée,
|
||||||
|
// elle est difficile à implémenter correctement sans changer sa signature.
|
||||||
|
// Pour l'instant, on retourne 0.0 car elle n'est pas utilisée.
|
||||||
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Analyser les tendances de dépenses par catégorie
|
/// Analyser les tendances de dépenses par catégorie
|
||||||
Map<String, double> analyzeCategorySpending(List<Expense> expenses) {
|
Map<String, double> analyzeCategorySpending(List<Expense> expenses) {
|
||||||
final categoryTotals = <String, double>{};
|
final categoryTotals = <String, double>{};
|
||||||
|
|
||||||
for (final expense in expenses) {
|
for (final expense in expenses) {
|
||||||
if (expense.isArchived) continue;
|
if (expense.isArchived) continue;
|
||||||
|
|
||||||
final categoryName = expense.category.displayName;
|
final categoryName = expense.category.displayName;
|
||||||
categoryTotals[categoryName] = (categoryTotals[categoryName] ?? 0) + expense.amountInEur;
|
categoryTotals[categoryName] =
|
||||||
|
(categoryTotals[categoryName] ?? 0) + expense.amountInEur;
|
||||||
}
|
}
|
||||||
|
|
||||||
return categoryTotals;
|
return categoryTotals;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,9 +279,12 @@ class BalanceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final nonArchivedExpenses = expenses.where((e) => !e.isArchived).toList();
|
final nonArchivedExpenses = expenses.where((e) => !e.isArchived).toList();
|
||||||
final totalAmount = nonArchivedExpenses.fold(0.0, (sum, e) => sum + e.amountInEur);
|
final totalAmount = nonArchivedExpenses.fold(
|
||||||
|
0.0,
|
||||||
|
(sum, e) => sum + e.amountInEur,
|
||||||
|
);
|
||||||
final averageAmount = totalAmount / nonArchivedExpenses.length;
|
final averageAmount = totalAmount / nonArchivedExpenses.length;
|
||||||
|
|
||||||
final categorySpending = analyzeCategorySpending(nonArchivedExpenses);
|
final categorySpending = analyzeCategorySpending(nonArchivedExpenses);
|
||||||
final topCategory = categorySpending.entries
|
final topCategory = categorySpending.entries
|
||||||
.reduce((a, b) => a.value > b.value ? a : b)
|
.reduce((a, b) => a.value > b.value ? a : b)
|
||||||
@@ -279,11 +308,14 @@ class BalanceService {
|
|||||||
try {
|
try {
|
||||||
// Ici vous pourriez enregistrer le règlement en base
|
// Ici vous pourriez enregistrer le règlement en base
|
||||||
// ou créer une transaction de règlement
|
// ou créer une transaction de règlement
|
||||||
|
|
||||||
// Pour l'instant, on pourrait juste recalculer
|
// Pour l'instant, on pourrait juste recalculer
|
||||||
await Future.delayed(const Duration(milliseconds: 100));
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
|
||||||
_errorService.logSuccess('BalanceService', 'Règlement marqué comme effectué');
|
_errorService.logSuccess(
|
||||||
|
'BalanceService',
|
||||||
|
'Règlement marqué comme effectué',
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('BalanceService', 'Erreur mark settlement: $e');
|
_errorService.logError('BalanceService', 'Erreur mark settlement: $e');
|
||||||
rethrow;
|
rethrow;
|
||||||
@@ -312,4 +344,4 @@ class _UserBalanceCalculator {
|
|||||||
balance: _totalPaid - _totalOwed,
|
balance: _totalPaid - _totalOwed,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,33 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../components/error/error_content.dart';
|
import '../components/error/error_content.dart';
|
||||||
|
import 'logger_service.dart';
|
||||||
|
|
||||||
/// Service for handling application errors and user notifications.
|
/// Service for handling application errors and user notifications.
|
||||||
///
|
///
|
||||||
/// This singleton service provides centralized error handling capabilities
|
/// This singleton service provides centralized error handling capabilities
|
||||||
/// including displaying error dialogs, snackbars, and logging errors for
|
/// including displaying error dialogs, snackbars, and logging errors for
|
||||||
/// debugging purposes. It uses a global navigator key to show notifications
|
/// debugging purposes. It uses a global navigator key to show notifications
|
||||||
/// from anywhere in the application.
|
/// from anywhere in the application.
|
||||||
class ErrorService {
|
class ErrorService {
|
||||||
static final ErrorService _instance = ErrorService._internal();
|
static final ErrorService _instance = ErrorService._internal();
|
||||||
|
|
||||||
/// Factory constructor that returns the singleton instance.
|
/// Factory constructor that returns the singleton instance.
|
||||||
factory ErrorService() => _instance;
|
factory ErrorService() => _instance;
|
||||||
|
|
||||||
/// Private constructor for singleton pattern.
|
/// Private constructor for singleton pattern.
|
||||||
ErrorService._internal();
|
ErrorService._internal();
|
||||||
|
|
||||||
/// Global navigator key for accessing context from anywhere in the app.
|
/// Global navigator key for accessing context from anywhere in the app.
|
||||||
///
|
///
|
||||||
/// This key should be assigned to the MaterialApp's navigatorKey property
|
/// This key should be assigned to the MaterialApp's navigatorKey property
|
||||||
/// to enable error notifications from any part of the application.
|
/// to enable error notifications from any part of the application.
|
||||||
static GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
static GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
/// Displays an error message in a dialog.
|
/// Displays an error message in a dialog.
|
||||||
///
|
///
|
||||||
/// Shows a modal dialog with the error message and optional retry functionality.
|
/// Shows a modal dialog with the error message and optional retry functionality.
|
||||||
/// The dialog appearance can be customized with different icons and colors.
|
/// The dialog appearance can be customized with different icons and colors.
|
||||||
///
|
///
|
||||||
/// [message] - The error message to display
|
/// [message] - The error message to display
|
||||||
/// [title] - The dialog title (defaults to 'Error')
|
/// [title] - The dialog title (defaults to 'Error')
|
||||||
/// [onRetry] - Optional callback for retry functionality
|
/// [onRetry] - Optional callback for retry functionality
|
||||||
@@ -53,10 +54,10 @@ class ErrorService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Displays an error or success message in a snackbar.
|
/// Displays an error or success message in a snackbar.
|
||||||
///
|
///
|
||||||
/// Shows a floating snackbar at the bottom of the screen with the message.
|
/// Shows a floating snackbar at the bottom of the screen with the message.
|
||||||
/// The appearance changes based on whether it's an error or success message.
|
/// The appearance changes based on whether it's an error or success message.
|
||||||
///
|
///
|
||||||
/// [message] - The message to display
|
/// [message] - The message to display
|
||||||
/// [onRetry] - Optional callback for retry functionality
|
/// [onRetry] - Optional callback for retry functionality
|
||||||
/// [isError] - Whether this is an error (true) or success (false) message
|
/// [isError] - Whether this is an error (true) or success (false) message
|
||||||
@@ -89,36 +90,35 @@ class ErrorService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Logs error messages to the console during development.
|
/// Logs error messages to the console during development.
|
||||||
///
|
///
|
||||||
/// Formats and displays error information including source, error message,
|
/// Formats and displays error information including source, error message,
|
||||||
/// and optional stack trace in a visually distinct format.
|
/// and optional stack trace in a visually distinct format.
|
||||||
///
|
///
|
||||||
/// [source] - The source or location where the error occurred
|
/// [source] - The source or location where the error occurred
|
||||||
/// [error] - The error object or message
|
/// [error] - The error object or message
|
||||||
/// [stackTrace] - Optional stack trace for debugging
|
/// [stackTrace] - Optional stack trace for debugging
|
||||||
void logError(String source, dynamic error, [StackTrace? stackTrace]) {
|
void logError(String source, dynamic error, [StackTrace? stackTrace]) {
|
||||||
print('═══════════════════════════════════');
|
LoggerService.error(
|
||||||
print('❌ ERROR in $source');
|
'❌ ERROR in $source\nMessage: $error',
|
||||||
print('Message: $error');
|
name: source,
|
||||||
if (stackTrace != null) {
|
error: error,
|
||||||
print('StackTrace: $stackTrace');
|
stackTrace: stackTrace,
|
||||||
}
|
);
|
||||||
print('═══════════════════════════════════');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Logs informational messages to the console during development.
|
/// Logs informational messages to the console during development.
|
||||||
///
|
///
|
||||||
/// [source] - The source or location of the information
|
/// [source] - The source or location of the information
|
||||||
/// [message] - The informational message
|
/// [message] - The informational message
|
||||||
void logInfo(String source, String message) {
|
void logInfo(String source, String message) {
|
||||||
print('ℹ️ [$source] $message');
|
LoggerService.info('ℹ️ $message', name: source);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Logs success messages to the console during development.
|
/// Logs success messages to the console during development.
|
||||||
///
|
///
|
||||||
/// [source] - The source or location of the success
|
/// [source] - The source or location of the success
|
||||||
/// [message] - The success message
|
/// [message] - The success message
|
||||||
void logSuccess(String source, String message) {
|
void logSuccess(String source, String message) {
|
||||||
print('✅ [$source] $message');
|
LoggerService.info('✅ $message', name: source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
30
lib/services/logger_service.dart
Normal file
30
lib/services/logger_service.dart
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import 'dart:developer' as developer;
|
||||||
|
|
||||||
|
class LoggerService {
|
||||||
|
static void log(String message, {String name = 'App'}) {
|
||||||
|
developer.log(message, name: name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void error(
|
||||||
|
String message, {
|
||||||
|
String name = 'App',
|
||||||
|
Object? error,
|
||||||
|
StackTrace? stackTrace,
|
||||||
|
}) {
|
||||||
|
developer.log(
|
||||||
|
message,
|
||||||
|
name: name,
|
||||||
|
error: error,
|
||||||
|
stackTrace: stackTrace,
|
||||||
|
level: 1000,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void info(String message, {String name = 'App'}) {
|
||||||
|
developer.log(message, name: name, level: 800);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void warning(String message, {String name = 'App'}) {
|
||||||
|
developer.log(message, name: name, level: 900);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,6 @@ class PlaceImageService {
|
|||||||
|
|
||||||
/// Récupère l'URL de l'image d'un lieu depuis Google Places API
|
/// Récupère l'URL de l'image d'un lieu depuis Google Places API
|
||||||
Future<String?> getPlaceImageUrl(String location) async {
|
Future<String?> getPlaceImageUrl(String location) async {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// ÉTAPE 1: Vérifier d'abord si une image existe déjà dans le Storage
|
// ÉTAPE 1: Vérifier d'abord si une image existe déjà dans le Storage
|
||||||
final existingUrl = await _checkExistingImage(location);
|
final existingUrl = await _checkExistingImage(location);
|
||||||
@@ -19,26 +18,25 @@ class PlaceImageService {
|
|||||||
return existingUrl;
|
return existingUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (_apiKey.isEmpty) {
|
if (_apiKey.isEmpty) {
|
||||||
_errorService.logError('PlaceImageService', 'Google Maps API key manquante');
|
_errorService.logError(
|
||||||
|
'PlaceImageService',
|
||||||
|
'Google Maps API key manquante',
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ÉTAPE 2: Recherche via Google Places API seulement si aucune image n'existe
|
// ÉTAPE 2: Recherche via Google Places API seulement si aucune image n'existe
|
||||||
final searchTerms = _generateSearchTerms(location);
|
final searchTerms = _generateSearchTerms(location);
|
||||||
|
|
||||||
for (final searchTerm in searchTerms) {
|
for (final searchTerm in searchTerms) {
|
||||||
|
|
||||||
// 1. Rechercher le lieu
|
// 1. Rechercher le lieu
|
||||||
final placeId = await _getPlaceIdForTerm(searchTerm);
|
final placeId = await _getPlaceIdForTerm(searchTerm);
|
||||||
if (placeId == null) continue;
|
if (placeId == null) continue;
|
||||||
|
|
||||||
|
|
||||||
// 2. Récupérer les détails du lieu avec les photos
|
// 2. Récupérer les détails du lieu avec les photos
|
||||||
final photoReference = await _getPhotoReference(placeId);
|
final photoReference = await _getPhotoReference(placeId);
|
||||||
if (photoReference == null) continue;
|
if (photoReference == null) continue;
|
||||||
|
|
||||||
|
|
||||||
// 3. Télécharger et sauvegarder l'image (seulement si pas d'image existante)
|
// 3. Télécharger et sauvegarder l'image (seulement si pas d'image existante)
|
||||||
final imageUrl = await _downloadAndSaveImage(photoReference, location);
|
final imageUrl = await _downloadAndSaveImage(photoReference, location);
|
||||||
@@ -46,11 +44,13 @@ class PlaceImageService {
|
|||||||
return imageUrl;
|
return imageUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors de la récupération de l\'image: $e');
|
_errorService.logError(
|
||||||
|
'PlaceImageService',
|
||||||
|
'Erreur lors de la récupération de l\'image: $e',
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,11 +58,11 @@ class PlaceImageService {
|
|||||||
/// Génère différents termes de recherche pour optimiser les résultats
|
/// Génère différents termes de recherche pour optimiser les résultats
|
||||||
List<String> _generateSearchTerms(String location) {
|
List<String> _generateSearchTerms(String location) {
|
||||||
final terms = <String>[];
|
final terms = <String>[];
|
||||||
|
|
||||||
// Ajouter des termes spécifiques pour les villes connues
|
// Ajouter des termes spécifiques pour les villes connues
|
||||||
final citySpecificTerms = _getCitySpecificTerms(location.toLowerCase());
|
final citySpecificTerms = _getCitySpecificTerms(location.toLowerCase());
|
||||||
terms.addAll(citySpecificTerms);
|
terms.addAll(citySpecificTerms);
|
||||||
|
|
||||||
// Termes génériques avec attractions
|
// Termes génériques avec attractions
|
||||||
terms.addAll([
|
terms.addAll([
|
||||||
'$location attractions touristiques monuments',
|
'$location attractions touristiques monuments',
|
||||||
@@ -74,14 +74,14 @@ class PlaceImageService {
|
|||||||
'$location skyline',
|
'$location skyline',
|
||||||
location, // Terme original en dernier
|
location, // Terme original en dernier
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return terms;
|
return terms;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retourne des termes spécifiques pour des villes connues
|
/// Retourne des termes spécifiques pour des villes connues
|
||||||
List<String> _getCitySpecificTerms(String location) {
|
List<String> _getCitySpecificTerms(String location) {
|
||||||
final specific = <String>[];
|
final specific = <String>[];
|
||||||
|
|
||||||
if (location.contains('paris')) {
|
if (location.contains('paris')) {
|
||||||
specific.addAll([
|
specific.addAll([
|
||||||
'Tour Eiffel Paris',
|
'Tour Eiffel Paris',
|
||||||
@@ -120,20 +120,23 @@ class PlaceImageService {
|
|||||||
'Tokyo Skytree',
|
'Tokyo Skytree',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return specific;
|
return specific;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recherche un place ID pour un terme spécifique
|
/// Recherche un place ID pour un terme spécifique
|
||||||
Future<String?> _getPlaceIdForTerm(String searchTerm) async {
|
Future<String?> _getPlaceIdForTerm(String searchTerm) async {
|
||||||
// Essayer d'abord avec les attractions touristiques
|
// Essayer d'abord avec les attractions touristiques
|
||||||
String? placeId = await _searchPlaceWithType(searchTerm, 'tourist_attraction');
|
String? placeId = await _searchPlaceWithType(
|
||||||
|
searchTerm,
|
||||||
|
'tourist_attraction',
|
||||||
|
);
|
||||||
if (placeId != null) return placeId;
|
if (placeId != null) return placeId;
|
||||||
|
|
||||||
// Puis avec les points d'intérêt
|
// Puis avec les points d'intérêt
|
||||||
placeId = await _searchPlaceWithType(searchTerm, 'point_of_interest');
|
placeId = await _searchPlaceWithType(searchTerm, 'point_of_interest');
|
||||||
if (placeId != null) return placeId;
|
if (placeId != null) return placeId;
|
||||||
|
|
||||||
// Enfin recherche générale
|
// Enfin recherche générale
|
||||||
return await _searchPlaceGeneral(searchTerm);
|
return await _searchPlaceGeneral(searchTerm);
|
||||||
}
|
}
|
||||||
@@ -146,14 +149,14 @@ class PlaceImageService {
|
|||||||
'?query=${Uri.encodeComponent('$location attractions monuments')}'
|
'?query=${Uri.encodeComponent('$location attractions monuments')}'
|
||||||
'&type=$type'
|
'&type=$type'
|
||||||
'&fields=place_id,name,types,rating'
|
'&fields=place_id,name,types,rating'
|
||||||
'&key=$_apiKey'
|
'&key=$_apiKey',
|
||||||
);
|
);
|
||||||
|
|
||||||
final response = await http.get(url);
|
final response = await http.get(url);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
|
|
||||||
if (data['status'] == 'OK' && data['results'].isNotEmpty) {
|
if (data['status'] == 'OK' && data['results'].isNotEmpty) {
|
||||||
// Prioriser les résultats avec des ratings élevés
|
// Prioriser les résultats avec des ratings élevés
|
||||||
final results = data['results'] as List;
|
final results = data['results'] as List;
|
||||||
@@ -162,7 +165,7 @@ class PlaceImageService {
|
|||||||
final bRating = b['rating'] ?? 0.0;
|
final bRating = b['rating'] ?? 0.0;
|
||||||
return bRating.compareTo(aRating);
|
return bRating.compareTo(aRating);
|
||||||
});
|
});
|
||||||
|
|
||||||
return results.first['place_id'];
|
return results.first['place_id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,14 +183,14 @@ class PlaceImageService {
|
|||||||
'?input=${Uri.encodeComponent(location)}'
|
'?input=${Uri.encodeComponent(location)}'
|
||||||
'&inputtype=textquery'
|
'&inputtype=textquery'
|
||||||
'&fields=place_id'
|
'&fields=place_id'
|
||||||
'&key=$_apiKey'
|
'&key=$_apiKey',
|
||||||
);
|
);
|
||||||
|
|
||||||
final response = await http.get(url);
|
final response = await http.get(url);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
|
|
||||||
if (data['status'] == 'OK' && data['candidates'].isNotEmpty) {
|
if (data['status'] == 'OK' && data['candidates'].isNotEmpty) {
|
||||||
return data['candidates'][0]['place_id'];
|
return data['candidates'][0]['place_id'];
|
||||||
}
|
}
|
||||||
@@ -205,24 +208,23 @@ class PlaceImageService {
|
|||||||
'https://maps.googleapis.com/maps/api/place/details/json'
|
'https://maps.googleapis.com/maps/api/place/details/json'
|
||||||
'?place_id=$placeId'
|
'?place_id=$placeId'
|
||||||
'&fields=photos'
|
'&fields=photos'
|
||||||
'&key=$_apiKey'
|
'&key=$_apiKey',
|
||||||
);
|
);
|
||||||
|
|
||||||
final response = await http.get(url);
|
final response = await http.get(url);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
|
|
||||||
if (data['status'] == 'OK' &&
|
if (data['status'] == 'OK' &&
|
||||||
data['result'] != null &&
|
data['result'] != null &&
|
||||||
data['result']['photos'] != null &&
|
data['result']['photos'] != null &&
|
||||||
data['result']['photos'].isNotEmpty) {
|
data['result']['photos'].isNotEmpty) {
|
||||||
|
|
||||||
final photos = data['result']['photos'] as List;
|
final photos = data['result']['photos'] as List;
|
||||||
|
|
||||||
// Trier les photos pour obtenir les meilleures
|
// Trier les photos pour obtenir les meilleures
|
||||||
final sortedPhotos = _sortPhotosByQuality(photos);
|
final sortedPhotos = _sortPhotosByQuality(photos);
|
||||||
|
|
||||||
if (sortedPhotos.isNotEmpty) {
|
if (sortedPhotos.isNotEmpty) {
|
||||||
return sortedPhotos.first['photo_reference'];
|
return sortedPhotos.first['photo_reference'];
|
||||||
}
|
}
|
||||||
@@ -230,7 +232,10 @@ class PlaceImageService {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors de la récupération de la référence photo: $e');
|
_errorService.logError(
|
||||||
|
'PlaceImageService',
|
||||||
|
'Erreur lors de la récupération de la référence photo: $e',
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,64 +243,68 @@ class PlaceImageService {
|
|||||||
/// Trie les photos par qualité (largeur/hauteur et popularité)
|
/// Trie les photos par qualité (largeur/hauteur et popularité)
|
||||||
List<Map<String, dynamic>> _sortPhotosByQuality(List photos) {
|
List<Map<String, dynamic>> _sortPhotosByQuality(List photos) {
|
||||||
final photoList = photos.cast<Map<String, dynamic>>();
|
final photoList = photos.cast<Map<String, dynamic>>();
|
||||||
|
|
||||||
photoList.sort((a, b) {
|
photoList.sort((a, b) {
|
||||||
// Priorité 1: Photos horizontales (largeur > hauteur)
|
// Priorité 1: Photos horizontales (largeur > hauteur)
|
||||||
final aWidth = a['width'] ?? 0;
|
final aWidth = a['width'] ?? 0;
|
||||||
final aHeight = a['height'] ?? 0;
|
final aHeight = a['height'] ?? 0;
|
||||||
final bWidth = b['width'] ?? 0;
|
final bWidth = b['width'] ?? 0;
|
||||||
final bHeight = b['height'] ?? 0;
|
final bHeight = b['height'] ?? 0;
|
||||||
|
|
||||||
final aIsHorizontal = aWidth > aHeight;
|
final aIsHorizontal = aWidth > aHeight;
|
||||||
final bIsHorizontal = bWidth > bHeight;
|
final bIsHorizontal = bWidth > bHeight;
|
||||||
|
|
||||||
if (aIsHorizontal && !bIsHorizontal) return -1;
|
if (aIsHorizontal && !bIsHorizontal) return -1;
|
||||||
if (!aIsHorizontal && bIsHorizontal) return 1;
|
if (!aIsHorizontal && bIsHorizontal) return 1;
|
||||||
|
|
||||||
// Priorité 2: Résolution plus élevée
|
// Priorité 2: Résolution plus élevée
|
||||||
final aResolution = aWidth * aHeight;
|
final aResolution = aWidth * aHeight;
|
||||||
final bResolution = bWidth * bHeight;
|
final bResolution = bWidth * bHeight;
|
||||||
|
|
||||||
if (aResolution != bResolution) {
|
if (aResolution != bResolution) {
|
||||||
return bResolution.compareTo(aResolution);
|
return bResolution.compareTo(aResolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priorité 3: Ratio d'aspect optimal pour paysage (1.5-2.0)
|
// Priorité 3: Ratio d'aspect optimal pour paysage (1.5-2.0)
|
||||||
final aRatio = aWidth > 0 ? aWidth / aHeight : 0;
|
final aRatio = aWidth > 0 ? aWidth / aHeight : 0;
|
||||||
final bRatio = bWidth > 0 ? bWidth / bHeight : 0;
|
final bRatio = bWidth > 0 ? bWidth / bHeight : 0;
|
||||||
|
|
||||||
final idealRatio = 1.7; // Ratio 16:9 environ
|
final idealRatio = 1.7; // Ratio 16:9 environ
|
||||||
final aDiff = (aRatio - idealRatio).abs();
|
final aDiff = (aRatio - idealRatio).abs();
|
||||||
final bDiff = (bRatio - idealRatio).abs();
|
final bDiff = (bRatio - idealRatio).abs();
|
||||||
|
|
||||||
return aDiff.compareTo(bDiff);
|
return aDiff.compareTo(bDiff);
|
||||||
});
|
});
|
||||||
|
|
||||||
return photoList;
|
return photoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Télécharge l'image et la sauvegarde dans Firebase Storage
|
/// Télécharge l'image et la sauvegarde dans Firebase Storage
|
||||||
Future<String?> _downloadAndSaveImage(String photoReference, String location) async {
|
Future<String?> _downloadAndSaveImage(
|
||||||
|
String photoReference,
|
||||||
|
String location,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
// URL pour télécharger l'image en haute qualité et format horizontal
|
// URL pour télécharger l'image en haute qualité et format horizontal
|
||||||
final imageUrl = 'https://maps.googleapis.com/maps/api/place/photo'
|
final imageUrl =
|
||||||
'?maxwidth=1200' // Augmenté pour une meilleure qualité
|
'https://maps.googleapis.com/maps/api/place/photo'
|
||||||
'&maxheight=800' // Ratio horizontal ~1.5:1
|
'?maxwidth=1200' // Augmenté pour une meilleure qualité
|
||||||
|
'&maxheight=800' // Ratio horizontal ~1.5:1
|
||||||
'&photo_reference=$photoReference'
|
'&photo_reference=$photoReference'
|
||||||
'&key=$_apiKey';
|
'&key=$_apiKey';
|
||||||
|
|
||||||
|
|
||||||
// Télécharger l'image
|
// Télécharger l'image
|
||||||
final response = await http.get(Uri.parse(imageUrl));
|
final response = await http.get(Uri.parse(imageUrl));
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
// Créer un nom de fichier unique basé sur la localisation normalisée
|
// Créer un nom de fichier unique basé sur la localisation normalisée
|
||||||
final normalizedLocation = _normalizeLocationName(location);
|
final normalizedLocation = _normalizeLocationName(location);
|
||||||
final fileName = '${normalizedLocation}_${DateTime.now().millisecondsSinceEpoch}.jpg';
|
final fileName =
|
||||||
|
'${normalizedLocation}_${DateTime.now().millisecondsSinceEpoch}.jpg';
|
||||||
|
|
||||||
// Référence vers Firebase Storage
|
// Référence vers Firebase Storage
|
||||||
final storageRef = _storage.ref().child('trip_images/$fileName');
|
final storageRef = _storage.ref().child('trip_images/$fileName');
|
||||||
|
|
||||||
// Upload de l'image avec métadonnées
|
// Upload de l'image avec métadonnées
|
||||||
final uploadTask = await storageRef.putData(
|
final uploadTask = await storageRef.putData(
|
||||||
response.bodyBytes,
|
response.bodyBytes,
|
||||||
@@ -309,15 +318,17 @@ class PlaceImageService {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Récupérer l'URL de téléchargement
|
// Récupérer l'URL de téléchargement
|
||||||
final downloadUrl = await uploadTask.ref.getDownloadURL();
|
final downloadUrl = await uploadTask.ref.getDownloadURL();
|
||||||
return downloadUrl;
|
return downloadUrl;
|
||||||
} else {
|
} else {}
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors du téléchargement/sauvegarde: $e');
|
_errorService.logError(
|
||||||
|
'PlaceImageService',
|
||||||
|
'Erreur lors du téléchargement/sauvegarde: $e',
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -326,45 +337,52 @@ class PlaceImageService {
|
|||||||
Future<String?> _checkExistingImage(String location) async {
|
Future<String?> _checkExistingImage(String location) async {
|
||||||
try {
|
try {
|
||||||
final normalizedLocation = _normalizeLocationName(location);
|
final normalizedLocation = _normalizeLocationName(location);
|
||||||
|
|
||||||
final listResult = await _storage.ref('trip_images').listAll();
|
final listResult = await _storage.ref('trip_images').listAll();
|
||||||
|
|
||||||
for (final item in listResult.items) {
|
for (final item in listResult.items) {
|
||||||
try {
|
try {
|
||||||
final metadata = await item.getMetadata();
|
final metadata = await item.getMetadata();
|
||||||
final storedNormalizedLocation = metadata.customMetadata?['normalizedLocation'];
|
final storedNormalizedLocation =
|
||||||
|
metadata.customMetadata?['normalizedLocation'];
|
||||||
final storedLocation = metadata.customMetadata?['location'];
|
final storedLocation = metadata.customMetadata?['location'];
|
||||||
|
|
||||||
// Méthode 1: Vérifier avec la location normalisée (nouvelles images)
|
// Méthode 1: Vérifier avec la location normalisée (nouvelles images)
|
||||||
if (storedNormalizedLocation != null && storedNormalizedLocation == normalizedLocation) {
|
if (storedNormalizedLocation != null &&
|
||||||
|
storedNormalizedLocation == normalizedLocation) {
|
||||||
final url = await item.getDownloadURL();
|
final url = await item.getDownloadURL();
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Méthode 2: Vérifier avec la location originale normalisée (anciennes images)
|
// Méthode 2: Vérifier avec la location originale normalisée (anciennes images)
|
||||||
if (storedLocation != null) {
|
if (storedLocation != null) {
|
||||||
final storedLocationNormalized = _normalizeLocationName(storedLocation);
|
final storedLocationNormalized = _normalizeLocationName(
|
||||||
|
storedLocation,
|
||||||
|
);
|
||||||
if (storedLocationNormalized == normalizedLocation) {
|
if (storedLocationNormalized == normalizedLocation) {
|
||||||
final url = await item.getDownloadURL();
|
final url = await item.getDownloadURL();
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Méthode 3: Essayer de deviner depuis le nom du fichier (fallback)
|
// Méthode 3: Essayer de deviner depuis le nom du fichier (fallback)
|
||||||
final fileName = item.name;
|
final fileName = item.name;
|
||||||
if (fileName.toLowerCase().contains(normalizedLocation.toLowerCase())) {
|
if (fileName.toLowerCase().contains(
|
||||||
|
normalizedLocation.toLowerCase(),
|
||||||
|
)) {
|
||||||
try {
|
try {
|
||||||
final url = await item.getDownloadURL();
|
final url = await item.getDownloadURL();
|
||||||
return url;
|
return url;
|
||||||
} catch (urlError) {
|
} catch (urlError) {
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors de la récupération de l\'URL: $urlError');
|
_errorService.logError(
|
||||||
|
'PlaceImageService',
|
||||||
|
'Erreur lors de la récupération de l\'URL: $urlError',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return null;
|
return null;
|
||||||
@@ -384,23 +402,26 @@ class PlaceImageService {
|
|||||||
Future<void> cleanupUnusedImages(List<String> usedImageUrls) async {
|
Future<void> cleanupUnusedImages(List<String> usedImageUrls) async {
|
||||||
try {
|
try {
|
||||||
final listResult = await _storage.ref('trip_images').listAll();
|
final listResult = await _storage.ref('trip_images').listAll();
|
||||||
int deletedCount = 0;
|
|
||||||
|
|
||||||
for (final item in listResult.items) {
|
for (final item in listResult.items) {
|
||||||
try {
|
try {
|
||||||
final url = await item.getDownloadURL();
|
final url = await item.getDownloadURL();
|
||||||
|
|
||||||
if (!usedImageUrls.contains(url)) {
|
if (!usedImageUrls.contains(url)) {
|
||||||
await item.delete();
|
await item.delete();
|
||||||
deletedCount++;
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors du nettoyage: $e');
|
_errorService.logError(
|
||||||
|
'PlaceImageService',
|
||||||
|
'Erreur lors du nettoyage: $e',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors du nettoyage: $e');
|
_errorService.logError(
|
||||||
|
'PlaceImageService',
|
||||||
|
'Erreur lors du nettoyage: $e',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,18 +429,19 @@ class PlaceImageService {
|
|||||||
Future<void> cleanupDuplicateImages() async {
|
Future<void> cleanupDuplicateImages() async {
|
||||||
try {
|
try {
|
||||||
final listResult = await _storage.ref('trip_images').listAll();
|
final listResult = await _storage.ref('trip_images').listAll();
|
||||||
|
|
||||||
// Grouper les images par location normalisée
|
// Grouper les images par location normalisée
|
||||||
final Map<String, List<Reference>> locationGroups = {};
|
final Map<String, List<Reference>> locationGroups = {};
|
||||||
|
|
||||||
for (final item in listResult.items) {
|
for (final item in listResult.items) {
|
||||||
String locationKey = 'unknown';
|
String locationKey = 'unknown';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final metadata = await item.getMetadata();
|
final metadata = await item.getMetadata();
|
||||||
final storedNormalizedLocation = metadata.customMetadata?['normalizedLocation'];
|
final storedNormalizedLocation =
|
||||||
|
metadata.customMetadata?['normalizedLocation'];
|
||||||
final storedLocation = metadata.customMetadata?['location'];
|
final storedLocation = metadata.customMetadata?['location'];
|
||||||
|
|
||||||
if (storedNormalizedLocation != null) {
|
if (storedNormalizedLocation != null) {
|
||||||
locationKey = storedNormalizedLocation;
|
locationKey = storedNormalizedLocation;
|
||||||
} else if (storedLocation != null) {
|
} else if (storedLocation != null) {
|
||||||
@@ -440,43 +462,44 @@ class PlaceImageService {
|
|||||||
locationKey = parts.take(parts.length - 1).join('_');
|
locationKey = parts.take(parts.length - 1).join('_');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!locationGroups.containsKey(locationKey)) {
|
if (!locationGroups.containsKey(locationKey)) {
|
||||||
locationGroups[locationKey] = [];
|
locationGroups[locationKey] = [];
|
||||||
}
|
}
|
||||||
locationGroups[locationKey]!.add(item);
|
locationGroups[locationKey]!.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supprimer les doublons (garder le plus récent)
|
// Supprimer les doublons (garder le plus récent)
|
||||||
int deletedCount = 0;
|
|
||||||
for (final entry in locationGroups.entries) {
|
for (final entry in locationGroups.entries) {
|
||||||
final location = entry.key;
|
|
||||||
final images = entry.value;
|
final images = entry.value;
|
||||||
|
|
||||||
if (images.length > 1) {
|
if (images.length > 1) {
|
||||||
|
|
||||||
// Trier par timestamp (garder le plus récent)
|
// Trier par timestamp (garder le plus récent)
|
||||||
images.sort((a, b) {
|
images.sort((a, b) {
|
||||||
final aTimestamp = _extractTimestampFromName(a.name);
|
final aTimestamp = _extractTimestampFromName(a.name);
|
||||||
final bTimestamp = _extractTimestampFromName(b.name);
|
final bTimestamp = _extractTimestampFromName(b.name);
|
||||||
return bTimestamp.compareTo(aTimestamp); // Plus récent en premier
|
return bTimestamp.compareTo(aTimestamp); // Plus récent en premier
|
||||||
});
|
});
|
||||||
|
|
||||||
// Supprimer tous sauf le premier (plus récent)
|
// Supprimer tous sauf le premier (plus récent)
|
||||||
for (int i = 1; i < images.length; i++) {
|
for (int i = 1; i < images.length; i++) {
|
||||||
try {
|
try {
|
||||||
await images[i].delete();
|
await images[i].delete();
|
||||||
deletedCount++;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors de la suppression du doublon: $e');
|
_errorService.logError(
|
||||||
|
'PlaceImageService',
|
||||||
|
'Erreur lors de la suppression du doublon: $e',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors du nettoyage des doublons: $e');
|
_errorService.logError(
|
||||||
|
'PlaceImageService',
|
||||||
|
'Erreur lors du nettoyage des doublons: $e',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,7 +522,10 @@ class PlaceImageService {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors de la recherche d\'image existante: $e');
|
_errorService.logError(
|
||||||
|
'PlaceImageService',
|
||||||
|
'Erreur lors de la recherche d\'image existante: $e',
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -510,7 +536,10 @@ class PlaceImageService {
|
|||||||
final ref = _storage.refFromURL(imageUrl);
|
final ref = _storage.refFromURL(imageUrl);
|
||||||
await ref.delete();
|
await ref.delete();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors de la suppression de l\'image: $e');
|
_errorService.logError(
|
||||||
|
'PlaceImageService',
|
||||||
|
'Erreur lors de la suppression de l\'image: $e',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,17 +14,18 @@
|
|||||||
/// Example usage:
|
/// Example usage:
|
||||||
/// ```dart
|
/// ```dart
|
||||||
/// final storageService = StorageService();
|
/// final storageService = StorageService();
|
||||||
///
|
///
|
||||||
/// // Upload a receipt image
|
/// // Upload a receipt image
|
||||||
/// final receiptUrl = await storageService.uploadReceiptImage(groupId, imageFile);
|
/// final receiptUrl = await storageService.uploadReceiptImage(groupId, imageFile);
|
||||||
///
|
///
|
||||||
/// // Upload a profile image
|
/// // Upload a profile image
|
||||||
/// final profileUrl = await storageService.uploadProfileImage(userId, imageFile);
|
/// final profileUrl = await storageService.uploadProfileImage(userId, imageFile);
|
||||||
///
|
///
|
||||||
/// // Delete a file
|
/// // Delete a file
|
||||||
/// await storageService.deleteFile(fileUrl);
|
/// await storageService.deleteFile(fileUrl);
|
||||||
/// ```
|
/// ```
|
||||||
library;
|
library;
|
||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:firebase_storage/firebase_storage.dart';
|
import 'package:firebase_storage/firebase_storage.dart';
|
||||||
@@ -36,34 +37,32 @@ import 'error_service.dart';
|
|||||||
class StorageService {
|
class StorageService {
|
||||||
/// Firebase Storage instance for file operations
|
/// Firebase Storage instance for file operations
|
||||||
final FirebaseStorage _storage;
|
final FirebaseStorage _storage;
|
||||||
|
|
||||||
/// Service for error handling and logging
|
/// Service for error handling and logging
|
||||||
final ErrorService _errorService;
|
final ErrorService _errorService;
|
||||||
|
|
||||||
/// Constructor for StorageService.
|
/// Constructor for StorageService.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [storage]: Optional Firebase Storage instance (auto-created if null)
|
/// [storage]: Optional Firebase Storage instance (auto-created if null)
|
||||||
/// [errorService]: Optional error service instance (auto-created if null)
|
/// [errorService]: Optional error service instance (auto-created if null)
|
||||||
StorageService({
|
StorageService({FirebaseStorage? storage, ErrorService? errorService})
|
||||||
FirebaseStorage? storage,
|
: _storage = storage ?? FirebaseStorage.instance,
|
||||||
ErrorService? errorService,
|
_errorService = errorService ?? ErrorService();
|
||||||
}) : _storage = storage ?? FirebaseStorage.instance,
|
|
||||||
_errorService = errorService ?? ErrorService();
|
|
||||||
|
|
||||||
/// Uploads a receipt image for an expense with automatic compression.
|
/// Uploads a receipt image for an expense with automatic compression.
|
||||||
///
|
///
|
||||||
/// Validates the image file, compresses it to JPEG format with 85% quality,
|
/// Validates the image file, compresses it to JPEG format with 85% quality,
|
||||||
/// generates a unique filename, and uploads it with appropriate metadata.
|
/// generates a unique filename, and uploads it with appropriate metadata.
|
||||||
/// Monitors upload progress and logs it for debugging purposes.
|
/// Monitors upload progress and logs it for debugging purposes.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [groupId]: ID of the group this receipt belongs to
|
/// [groupId]: ID of the group this receipt belongs to
|
||||||
/// [imageFile]: The image file to upload
|
/// [imageFile]: The image file to upload
|
||||||
///
|
///
|
||||||
/// Returns:
|
/// Returns:
|
||||||
/// A Future<String> containing the download URL of the uploaded image
|
/// A `Future<String>` containing the download URL of the uploaded image
|
||||||
///
|
///
|
||||||
/// Throws:
|
/// Throws:
|
||||||
/// Exception if file validation fails or upload encounters an error
|
/// Exception if file validation fails or upload encounters an error
|
||||||
Future<String> uploadReceiptImage(String groupId, File imageFile) async {
|
Future<String> uploadReceiptImage(String groupId, File imageFile) async {
|
||||||
@@ -95,8 +94,12 @@ class StorageService {
|
|||||||
|
|
||||||
// Progress monitoring (optional)
|
// Progress monitoring (optional)
|
||||||
uploadTask.snapshotEvents.listen((TaskSnapshot snapshot) {
|
uploadTask.snapshotEvents.listen((TaskSnapshot snapshot) {
|
||||||
final progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
|
final progress =
|
||||||
_errorService.logInfo('StorageService', 'Upload progress: ${progress.toStringAsFixed(1)}%');
|
(snapshot.bytesTransferred / snapshot.totalBytes) * 100;
|
||||||
|
_errorService.logInfo(
|
||||||
|
'StorageService',
|
||||||
|
'Upload progress: ${progress.toStringAsFixed(1)}%',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wait for completion
|
// Wait for completion
|
||||||
@@ -105,9 +108,11 @@ class StorageService {
|
|||||||
// Get download URL
|
// Get download URL
|
||||||
final downloadUrl = await snapshot.ref.getDownloadURL();
|
final downloadUrl = await snapshot.ref.getDownloadURL();
|
||||||
|
|
||||||
_errorService.logSuccess('StorageService', 'Image uploaded successfully: $fileName');
|
_errorService.logSuccess(
|
||||||
|
'StorageService',
|
||||||
|
'Image uploaded successfully: $fileName',
|
||||||
|
);
|
||||||
return downloadUrl;
|
return downloadUrl;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('StorageService', 'Error uploading image: $e');
|
_errorService.logError('StorageService', 'Error uploading image: $e');
|
||||||
rethrow;
|
rethrow;
|
||||||
@@ -115,10 +120,10 @@ class StorageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Deletes a receipt image from storage.
|
/// Deletes a receipt image from storage.
|
||||||
///
|
///
|
||||||
/// Extracts the storage reference from the provided URL and deletes the file.
|
/// Extracts the storage reference from the provided URL and deletes the file.
|
||||||
/// Does not throw errors to avoid blocking expense deletion operations.
|
/// Does not throw errors to avoid blocking expense deletion operations.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [imageUrl]: The download URL of the image to delete
|
/// [imageUrl]: The download URL of the image to delete
|
||||||
Future<void> deleteReceiptImage(String imageUrl) async {
|
Future<void> deleteReceiptImage(String imageUrl) async {
|
||||||
@@ -137,17 +142,17 @@ class StorageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Compresses an image to optimize storage space and upload speed.
|
/// Compresses an image to optimize storage space and upload speed.
|
||||||
///
|
///
|
||||||
/// Reads the image file, decodes it, resizes it if too large (max 1024x1024),
|
/// Reads the image file, decodes it, resizes it if too large (max 1024x1024),
|
||||||
/// and encodes it as JPEG with 85% quality for optimal balance between
|
/// and encodes it as JPEG with 85% quality for optimal balance between
|
||||||
/// file size and image quality.
|
/// file size and image quality.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [imageFile]: The image file to compress
|
/// [imageFile]: The image file to compress
|
||||||
///
|
///
|
||||||
/// Returns:
|
/// Returns:
|
||||||
/// A Future<Uint8List> containing the compressed image bytes
|
/// A `Future<Uint8List>` containing the compressed image bytes
|
||||||
///
|
///
|
||||||
/// Throws:
|
/// Throws:
|
||||||
/// Exception if the image cannot be decoded or processed
|
/// Exception if the image cannot be decoded or processed
|
||||||
Future<Uint8List> _compressImage(File imageFile) async {
|
Future<Uint8List> _compressImage(File imageFile) async {
|
||||||
@@ -175,9 +180,11 @@ class StorageService {
|
|||||||
|
|
||||||
// Encode as JPEG with compression
|
// Encode as JPEG with compression
|
||||||
final compressedBytes = img.encodeJpg(image, quality: 85);
|
final compressedBytes = img.encodeJpg(image, quality: 85);
|
||||||
|
|
||||||
_errorService.logInfo('StorageService',
|
_errorService.logInfo(
|
||||||
'Image compressed: ${bytes.length} → ${compressedBytes.length} bytes');
|
'StorageService',
|
||||||
|
'Image compressed: ${bytes.length} → ${compressedBytes.length} bytes',
|
||||||
|
);
|
||||||
|
|
||||||
return Uint8List.fromList(compressedBytes);
|
return Uint8List.fromList(compressedBytes);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -188,13 +195,13 @@ class StorageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Validates an image file before upload.
|
/// Validates an image file before upload.
|
||||||
///
|
///
|
||||||
/// Checks file existence, size constraints (max 10MB), and file extension
|
/// Checks file existence, size constraints (max 10MB), and file extension
|
||||||
/// to ensure only valid image files are processed for upload.
|
/// to ensure only valid image files are processed for upload.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [imageFile]: The image file to validate
|
/// [imageFile]: The image file to validate
|
||||||
///
|
///
|
||||||
/// Throws:
|
/// Throws:
|
||||||
/// Exception if validation fails (file doesn't exist, too large, or invalid extension)
|
/// Exception if validation fails (file doesn't exist, too large, or invalid extension)
|
||||||
void _validateImageFile(File imageFile) {
|
void _validateImageFile(File imageFile) {
|
||||||
@@ -219,13 +226,13 @@ class StorageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Generates a unique filename for a receipt image.
|
/// Generates a unique filename for a receipt image.
|
||||||
///
|
///
|
||||||
/// Creates a filename using timestamp, microseconds, and group ID to ensure
|
/// Creates a filename using timestamp, microseconds, and group ID to ensure
|
||||||
/// uniqueness and prevent naming conflicts when multiple receipts are uploaded.
|
/// uniqueness and prevent naming conflicts when multiple receipts are uploaded.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [groupId]: ID of the group this receipt belongs to
|
/// [groupId]: ID of the group this receipt belongs to
|
||||||
///
|
///
|
||||||
/// Returns:
|
/// Returns:
|
||||||
/// A unique filename string for the receipt image
|
/// A unique filename string for the receipt image
|
||||||
String _generateReceiptFileName(String groupId) {
|
String _generateReceiptFileName(String groupId) {
|
||||||
@@ -235,21 +242,23 @@ class StorageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Uploads multiple images simultaneously (for future features).
|
/// Uploads multiple images simultaneously (for future features).
|
||||||
///
|
///
|
||||||
/// Processes multiple image files in parallel for batch upload scenarios.
|
/// Processes multiple image files in parallel for batch upload scenarios.
|
||||||
/// Each image is validated, compressed, and uploaded with unique filenames.
|
/// Each image is validated, compressed, and uploaded with unique filenames.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// [groupId]: ID of the group these images belong to
|
/// [groupId]: ID of the group these images belong to
|
||||||
/// [imageFiles]: List of image files to upload
|
/// [imageFiles]: List of image files to upload
|
||||||
///
|
///
|
||||||
/// Returns:
|
/// Returns:
|
||||||
/// A Future<List<String>> containing download URLs of uploaded images
|
/// A `Future<List<String>>` containing download URLs of uploaded images
|
||||||
Future<List<String>> uploadMultipleImages(
|
Future<List<String>> uploadMultipleImages(
|
||||||
String groupId,
|
String groupId,
|
||||||
List<File> imageFiles,
|
List<File> imageFiles,
|
||||||
) async {
|
) async {
|
||||||
final uploadTasks = imageFiles.map((file) => uploadReceiptImage(groupId, file));
|
final uploadTasks = imageFiles.map(
|
||||||
|
(file) => uploadReceiptImage(groupId, file),
|
||||||
|
);
|
||||||
return await Future.wait(uploadTasks);
|
return await Future.wait(uploadTasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +268,10 @@ class StorageService {
|
|||||||
final ref = _storage.refFromURL(imageUrl);
|
final ref = _storage.refFromURL(imageUrl);
|
||||||
return await ref.getMetadata();
|
return await ref.getMetadata();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('StorageService', 'Erreur récupération metadata: $e');
|
_errorService.logError(
|
||||||
|
'StorageService',
|
||||||
|
'Erreur récupération metadata: $e',
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -274,14 +286,17 @@ class StorageService {
|
|||||||
// Vérifier l'âge du fichier
|
// Vérifier l'âge du fichier
|
||||||
final metadata = await ref.getMetadata();
|
final metadata = await ref.getMetadata();
|
||||||
final uploadDate = metadata.timeCreated;
|
final uploadDate = metadata.timeCreated;
|
||||||
|
|
||||||
if (uploadDate != null) {
|
if (uploadDate != null) {
|
||||||
final daysSinceUpload = DateTime.now().difference(uploadDate).inDays;
|
final daysSinceUpload = DateTime.now().difference(uploadDate).inDays;
|
||||||
|
|
||||||
// Supprimer les fichiers de plus de 30 jours sans dépense associée
|
// Supprimer les fichiers de plus de 30 jours sans dépense associée
|
||||||
if (daysSinceUpload > 30) {
|
if (daysSinceUpload > 30) {
|
||||||
await ref.delete();
|
await ref.delete();
|
||||||
_errorService.logInfo('StorageService', 'Image orpheline supprimée: ${ref.name}');
|
_errorService.logInfo(
|
||||||
|
'StorageService',
|
||||||
|
'Image orpheline supprimée: ${ref.name}',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,17 +310,20 @@ class StorageService {
|
|||||||
try {
|
try {
|
||||||
final groupRef = _storage.ref().child('receipts/$groupId');
|
final groupRef = _storage.ref().child('receipts/$groupId');
|
||||||
final listResult = await groupRef.listAll();
|
final listResult = await groupRef.listAll();
|
||||||
|
|
||||||
int totalSize = 0;
|
int totalSize = 0;
|
||||||
for (final ref in listResult.items) {
|
for (final ref in listResult.items) {
|
||||||
final metadata = await ref.getMetadata();
|
final metadata = await ref.getMetadata();
|
||||||
totalSize += metadata.size ?? 0;
|
totalSize += metadata.size ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return totalSize;
|
return totalSize;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_errorService.logError('StorageService', 'Erreur calcul taille storage: $e');
|
_errorService.logError(
|
||||||
|
'StorageService',
|
||||||
|
'Erreur calcul taille storage: $e',
|
||||||
|
);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ import 'package:http/http.dart' as http;
|
|||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import '../models/trip.dart';
|
import '../models/trip.dart';
|
||||||
import 'error_service.dart';
|
import 'error_service.dart';
|
||||||
|
import 'logger_service.dart';
|
||||||
|
|
||||||
/// Service pour géocoder les destinations des voyages
|
/// Service pour géocoder les destinations des voyages
|
||||||
class TripGeocodingService {
|
class TripGeocodingService {
|
||||||
static final TripGeocodingService _instance = TripGeocodingService._internal();
|
static final TripGeocodingService _instance =
|
||||||
|
TripGeocodingService._internal();
|
||||||
factory TripGeocodingService() => _instance;
|
factory TripGeocodingService() => _instance;
|
||||||
TripGeocodingService._internal();
|
TripGeocodingService._internal();
|
||||||
|
|
||||||
@@ -16,35 +18,41 @@ class TripGeocodingService {
|
|||||||
/// Géocode la destination d'un voyage et retourne un Trip mis à jour
|
/// Géocode la destination d'un voyage et retourne un Trip mis à jour
|
||||||
Future<Trip> geocodeTrip(Trip trip) async {
|
Future<Trip> geocodeTrip(Trip trip) async {
|
||||||
try {
|
try {
|
||||||
print('🌍 [TripGeocoding] Géocodage de "${trip.location}"');
|
LoggerService.info('🌍 [TripGeocoding] Géocodage de "${trip.location}"');
|
||||||
|
|
||||||
// Vérifier si on a déjà des coordonnées récentes
|
// Vérifier si on a déjà des coordonnées récentes
|
||||||
if (trip.hasRecentCoordinates) {
|
if (trip.hasRecentCoordinates) {
|
||||||
print('✅ [TripGeocoding] Coordonnées récentes trouvées, pas de géocodage nécessaire');
|
LoggerService.info(
|
||||||
|
'✅ [TripGeocoding] Coordonnées récentes trouvées, pas de géocodage nécessaire',
|
||||||
|
);
|
||||||
return trip;
|
return trip;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_apiKey.isEmpty) {
|
if (_apiKey.isEmpty) {
|
||||||
print('❌ [TripGeocoding] Clé API Google Maps manquante');
|
LoggerService.error('❌ [TripGeocoding] Clé API Google Maps manquante');
|
||||||
throw Exception('Clé API Google Maps non configurée');
|
throw Exception('Clé API Google Maps non configurée');
|
||||||
}
|
}
|
||||||
|
|
||||||
final coordinates = await _geocodeDestination(trip.location);
|
final coordinates = await _geocodeDestination(trip.location);
|
||||||
|
|
||||||
if (coordinates != null) {
|
if (coordinates != null) {
|
||||||
print('✅ [TripGeocoding] Coordonnées trouvées: ${coordinates['lat']}, ${coordinates['lng']}');
|
LoggerService.info(
|
||||||
|
'✅ [TripGeocoding] Coordonnées trouvées: ${coordinates['lat']}, ${coordinates['lng']}',
|
||||||
|
);
|
||||||
|
|
||||||
return trip.copyWith(
|
return trip.copyWith(
|
||||||
latitude: coordinates['lat'],
|
latitude: coordinates['lat'],
|
||||||
longitude: coordinates['lng'],
|
longitude: coordinates['lng'],
|
||||||
lastGeocodingUpdate: DateTime.now(),
|
lastGeocodingUpdate: DateTime.now(),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
print('⚠️ [TripGeocoding] Impossible de géocoder "${trip.location}"');
|
LoggerService.warning(
|
||||||
|
'⚠️ [TripGeocoding] Impossible de géocoder "${trip.location}"',
|
||||||
|
);
|
||||||
return trip;
|
return trip;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('❌ [TripGeocoding] Erreur lors du géocodage: $e');
|
LoggerService.error('❌ [TripGeocoding] Erreur lors du géocodage: $e');
|
||||||
_errorService.logError('trip_geocoding_service', e);
|
_errorService.logError('trip_geocoding_service', e);
|
||||||
return trip; // Retourner le voyage original en cas d'erreur
|
return trip; // Retourner le voyage original en cas d'erreur
|
||||||
}
|
}
|
||||||
@@ -53,18 +61,23 @@ class TripGeocodingService {
|
|||||||
/// Géocode une destination et retourne les coordonnées
|
/// Géocode une destination et retourne les coordonnées
|
||||||
Future<Map<String, double>?> _geocodeDestination(String destination) async {
|
Future<Map<String, double>?> _geocodeDestination(String destination) async {
|
||||||
try {
|
try {
|
||||||
final url = 'https://maps.googleapis.com/maps/api/geocode/json'
|
final url =
|
||||||
|
'https://maps.googleapis.com/maps/api/geocode/json'
|
||||||
'?address=${Uri.encodeComponent(destination)}'
|
'?address=${Uri.encodeComponent(destination)}'
|
||||||
'&key=$_apiKey';
|
'&key=$_apiKey';
|
||||||
|
|
||||||
print('🌐 [TripGeocoding] URL = $url');
|
LoggerService.info('🌐 [TripGeocoding] URL = $url');
|
||||||
|
|
||||||
final response = await http.get(Uri.parse(url));
|
final response = await http.get(Uri.parse(url));
|
||||||
print('📡 [TripGeocoding] Status code = ${response.statusCode}');
|
LoggerService.info(
|
||||||
|
'📡 [TripGeocoding] Status code = ${response.statusCode}',
|
||||||
|
);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
print('📋 [TripGeocoding] Réponse géocodage = ${data['status']}');
|
LoggerService.info(
|
||||||
|
'📋 [TripGeocoding] Réponse géocodage = ${data['status']}',
|
||||||
|
);
|
||||||
|
|
||||||
if (data['status'] == 'OK' && data['results'].isNotEmpty) {
|
if (data['status'] == 'OK' && data['results'].isNotEmpty) {
|
||||||
final location = data['results'][0]['geometry']['location'];
|
final location = data['results'][0]['geometry']['location'];
|
||||||
@@ -72,18 +85,24 @@ class TripGeocodingService {
|
|||||||
'lat': (location['lat'] as num).toDouble(),
|
'lat': (location['lat'] as num).toDouble(),
|
||||||
'lng': (location['lng'] as num).toDouble(),
|
'lng': (location['lng'] as num).toDouble(),
|
||||||
};
|
};
|
||||||
print('📍 [TripGeocoding] Coordonnées trouvées = $coordinates');
|
LoggerService.info(
|
||||||
|
'📍 [TripGeocoding] Coordonnées trouvées = $coordinates',
|
||||||
|
);
|
||||||
return coordinates;
|
return coordinates;
|
||||||
} else {
|
} else {
|
||||||
print('⚠️ [TripGeocoding] Erreur API = ${data['error_message'] ?? data['status']}');
|
LoggerService.warning(
|
||||||
|
'⚠️ [TripGeocoding] Erreur API = ${data['error_message'] ?? data['status']}',
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print('❌ [TripGeocoding] Erreur HTTP ${response.statusCode}');
|
LoggerService.error(
|
||||||
|
'❌ [TripGeocoding] Erreur HTTP ${response.statusCode}',
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('❌ [TripGeocoding] Exception lors du géocodage: $e');
|
LoggerService.error('❌ [TripGeocoding] Exception lors du géocodage: $e');
|
||||||
_errorService.logError('trip_geocoding_service', e);
|
_errorService.logError('trip_geocoding_service', e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -96,23 +115,25 @@ class TripGeocodingService {
|
|||||||
|
|
||||||
/// Géocode plusieurs voyages en batch
|
/// Géocode plusieurs voyages en batch
|
||||||
Future<List<Trip>> geocodeTrips(List<Trip> trips) async {
|
Future<List<Trip>> geocodeTrips(List<Trip> trips) async {
|
||||||
print('🔄 [TripGeocoding] Géocodage de ${trips.length} voyages');
|
LoggerService.info(
|
||||||
|
'🔄 [TripGeocoding] Géocodage de ${trips.length} voyages',
|
||||||
|
);
|
||||||
|
|
||||||
final List<Trip> geocodedTrips = [];
|
final List<Trip> geocodedTrips = [];
|
||||||
|
|
||||||
for (final trip in trips) {
|
for (final trip in trips) {
|
||||||
if (needsGeocoding(trip)) {
|
if (needsGeocoding(trip)) {
|
||||||
final geocodedTrip = await geocodeTrip(trip);
|
final geocodedTrip = await geocodeTrip(trip);
|
||||||
geocodedTrips.add(geocodedTrip);
|
geocodedTrips.add(geocodedTrip);
|
||||||
|
|
||||||
// Petit délai pour éviter de saturer l'API Google
|
// Petit délai pour éviter de saturer l'API Google
|
||||||
await Future.delayed(const Duration(milliseconds: 200));
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
} else {
|
} else {
|
||||||
geocodedTrips.add(trip);
|
geocodedTrips.add(trip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print('✅ [TripGeocoding] Géocodage terminé');
|
LoggerService.info('✅ [TripGeocoding] Géocodage terminé');
|
||||||
return geocodedTrips;
|
return geocodedTrips;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
pubspec.lock
20
pubspec.lock
@@ -617,7 +617,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "4.1.2"
|
version: "4.1.2"
|
||||||
image:
|
image:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: image
|
name: image
|
||||||
sha256: "4e973fcf4caae1a4be2fa0a13157aa38a8f9cb049db6529aa00b4d71abc4d928"
|
sha256: "4e973fcf4caae1a4be2fa0a13157aa38a8f9cb049db6529aa00b4d71abc4d928"
|
||||||
@@ -825,7 +825,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "3.2.1"
|
version: "3.2.1"
|
||||||
path:
|
path:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: path
|
name: path
|
||||||
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
|
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
|
||||||
@@ -1024,6 +1024,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.0"
|
version: "3.0.0"
|
||||||
|
simple_gesture_detector:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: simple_gesture_detector
|
||||||
|
sha256: ba2cd5af24ff20a0b8d609cec3f40e5b0744d2a71804a2616ae086b9c19d19a3
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.1"
|
||||||
sky_engine:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
@@ -1125,6 +1133,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.4.0"
|
version: "3.4.0"
|
||||||
|
table_calendar:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: table_calendar
|
||||||
|
sha256: "0c0c6219878b363a2d5f40c7afb159d845f253d061dc3c822aa0d5fe0f721982"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "3.2.0"
|
||||||
term_glyph:
|
term_glyph:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ dependencies:
|
|||||||
location: ^8.0.1
|
location: ^8.0.1
|
||||||
flutter_bloc : ^9.1.1
|
flutter_bloc : ^9.1.1
|
||||||
equatable: ^2.0.5
|
equatable: ^2.0.5
|
||||||
|
table_calendar: ^3.1.0
|
||||||
|
|
||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
@@ -58,6 +59,8 @@ dependencies:
|
|||||||
sign_in_with_apple: ^7.0.1
|
sign_in_with_apple: ^7.0.1
|
||||||
sign_in_button: ^4.0.1
|
sign_in_button: ^4.0.1
|
||||||
cached_network_image: ^3.3.1
|
cached_network_image: ^3.3.1
|
||||||
|
path: ^1.9.1
|
||||||
|
image: ^4.5.4
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_launcher_icons: ^0.13.1
|
flutter_launcher_icons: ^0.13.1
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ void main() async {
|
|||||||
if (stats['tripsWithImages'] > 0) {
|
if (stats['tripsWithImages'] > 0) {
|
||||||
await tripImageService.cleanupUnusedImages(userId);
|
await tripImageService.cleanupUnusedImages(userId);
|
||||||
|
|
||||||
final newStats = await tripImageService.getImageStatistics(userId);
|
await tripImageService.getImageStatistics(userId);
|
||||||
} else {}
|
} else {}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// ignore_for_file: avoid_print
|
||||||
import 'package:firebase_core/firebase_core.dart';
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
import 'package:firebase_storage/firebase_storage.dart';
|
import 'package:firebase_storage/firebase_storage.dart';
|
||||||
import 'package:travel_mate/firebase_options.dart';
|
import 'package:travel_mate/firebase_options.dart';
|
||||||
@@ -32,7 +33,7 @@ void main() async {
|
|||||||
final location = customMeta['location'] ?? 'Inconnue';
|
final location = customMeta['location'] ?? 'Inconnue';
|
||||||
final normalizedLocation =
|
final normalizedLocation =
|
||||||
customMeta['normalizedLocation'] ?? 'Non définie';
|
customMeta['normalizedLocation'] ?? 'Non définie';
|
||||||
final source = customMeta['source'] ?? 'Inconnue';
|
|
||||||
final uploadedAt = customMeta['uploadedAt'] ?? 'Inconnue';
|
final uploadedAt = customMeta['uploadedAt'] ?? 'Inconnue';
|
||||||
|
|
||||||
// Récupérer l'URL de téléchargement
|
// Récupérer l'URL de téléchargement
|
||||||
@@ -76,18 +77,17 @@ void main() async {
|
|||||||
|
|
||||||
int totalDuplicates = 0;
|
int totalDuplicates = 0;
|
||||||
for (final entry in locationGroups.entries) {
|
for (final entry in locationGroups.entries) {
|
||||||
final location = entry.key;
|
|
||||||
final images = entry.value;
|
final images = entry.value;
|
||||||
|
|
||||||
if (images.length > 1) {
|
if (images.length > 1) {
|
||||||
totalDuplicates += images.length - 1;
|
totalDuplicates += images.length - 1;
|
||||||
|
|
||||||
for (int i = 0; i < images.length; i++) {
|
for (int i = 0; i < images.length; i++) {}
|
||||||
final image = images[i];
|
|
||||||
}
|
|
||||||
} else {}
|
} else {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalDuplicates > 0) {}
|
if (totalDuplicates > 0) {}
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
print('Erreur globale: $e');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// ignore_for_file: avoid_print
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@@ -13,7 +14,7 @@ void main() {
|
|||||||
print('✓ Téléchargement d\'une nouvelle image depuis Google Places');
|
print('✓ Téléchargement d\'une nouvelle image depuis Google Places');
|
||||||
existingImage = 'https://storage.googleapis.com/image1.jpg';
|
existingImage = 'https://storage.googleapis.com/image1.jpg';
|
||||||
print('✓ Image sauvée: $existingImage');
|
print('✓ Image sauvée: $existingImage');
|
||||||
|
|
||||||
expect(existingImage, isNotNull);
|
expect(existingImage, isNotNull);
|
||||||
|
|
||||||
// Scénario 2: Rechargement (image existante)
|
// Scénario 2: Rechargement (image existante)
|
||||||
@@ -34,7 +35,7 @@ void main() {
|
|||||||
print('✓ Nouvelle destination, aucune image existante');
|
print('✓ Nouvelle destination, aucune image existante');
|
||||||
print('✓ Téléchargement autorisé pour cette nouvelle destination');
|
print('✓ Téléchargement autorisé pour cette nouvelle destination');
|
||||||
differentLocationImage = 'https://storage.googleapis.com/image2.jpg';
|
differentLocationImage = 'https://storage.googleapis.com/image2.jpg';
|
||||||
|
|
||||||
expect(differentLocationImage, isNotNull);
|
expect(differentLocationImage, isNotNull);
|
||||||
expect(differentLocationImage, isNot(equals(existingImage)));
|
expect(differentLocationImage, isNot(equals(existingImage)));
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// ignore_for_file: avoid_print
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
// ignore_for_file: avoid_print
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:travel_mate/services/place_image_service.dart';
|
import 'package:travel_mate/services/place_image_service.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('PlaceImageService Tests', () {
|
group('PlaceImageService Tests', () {
|
||||||
late PlaceImageService placeImageService;
|
late PlaceImageService placeImageService;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
placeImageService = PlaceImageService();
|
placeImageService = PlaceImageService();
|
||||||
});
|
});
|
||||||
@@ -12,9 +13,9 @@ void main() {
|
|||||||
test('should generate search terms correctly for Paris', () {
|
test('should generate search terms correctly for Paris', () {
|
||||||
// Cette fonction n'est pas publique, mais nous pouvons tester indirectement
|
// Cette fonction n'est pas publique, mais nous pouvons tester indirectement
|
||||||
// en vérifiant que différentes villes génèrent des termes appropriés
|
// en vérifiant que différentes villes génèrent des termes appropriés
|
||||||
|
|
||||||
final cities = ['Paris', 'London', 'Rome', 'New York', 'Tokyo'];
|
final cities = ['Paris', 'London', 'Rome', 'New York', 'Tokyo'];
|
||||||
|
|
||||||
for (String city in cities) {
|
for (String city in cities) {
|
||||||
print('Testing search terms generation for: $city');
|
print('Testing search terms generation for: $city');
|
||||||
// Le test indirect sera fait lors de l'appel réel à l'API
|
// Le test indirect sera fait lors de l'appel réel à l'API
|
||||||
@@ -23,14 +24,8 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should prioritize tourist attractions in search terms', () {
|
test('should prioritize tourist attractions in search terms', () {
|
||||||
const testCases = [
|
const testCases = ['Paris', 'London', 'Rome', 'New York', 'Tokyo'];
|
||||||
'Paris',
|
|
||||||
'London',
|
|
||||||
'Rome',
|
|
||||||
'New York',
|
|
||||||
'Tokyo'
|
|
||||||
];
|
|
||||||
|
|
||||||
for (String city in testCases) {
|
for (String city in testCases) {
|
||||||
print('City: $city should have tourist attraction terms');
|
print('City: $city should have tourist attraction terms');
|
||||||
expect(city.length, greaterThan(0));
|
expect(city.length, greaterThan(0));
|
||||||
@@ -41,7 +36,7 @@ void main() {
|
|||||||
test('should handle API key missing gracefully', () async {
|
test('should handle API key missing gracefully', () async {
|
||||||
// Test avec une clé API vide
|
// Test avec une clé API vide
|
||||||
final result = await placeImageService.getPlaceImageUrl('Paris');
|
final result = await placeImageService.getPlaceImageUrl('Paris');
|
||||||
|
|
||||||
// Devrait retourner null si pas de clé API
|
// Devrait retourner null si pas de clé API
|
||||||
expect(result, isNull);
|
expect(result, isNull);
|
||||||
});
|
});
|
||||||
@@ -57,12 +52,12 @@ void main() {
|
|||||||
'Louvre Paris',
|
'Louvre Paris',
|
||||||
'Champs-Élysées Paris',
|
'Champs-Élysées Paris',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (String term in parisTerms) {
|
for (String term in parisTerms) {
|
||||||
expect(term.contains('Paris'), true);
|
expect(term.contains('Paris'), true);
|
||||||
print('Generated term: $term');
|
print('Generated term: $term');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test des termes spécifiques pour Londres
|
// Test des termes spécifiques pour Londres
|
||||||
const londonTerms = [
|
const londonTerms = [
|
||||||
'Big Ben London',
|
'Big Ben London',
|
||||||
@@ -71,7 +66,7 @@ void main() {
|
|||||||
'Buckingham Palace London',
|
'Buckingham Palace London',
|
||||||
'Tower of London',
|
'Tower of London',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (String term in londonTerms) {
|
for (String term in londonTerms) {
|
||||||
expect(term.contains('London') || term.contains('Eye'), true);
|
expect(term.contains('London') || term.contains('Eye'), true);
|
||||||
print('Generated term: $term');
|
print('Generated term: $term');
|
||||||
@@ -88,7 +83,7 @@ void main() {
|
|||||||
'centre ville',
|
'centre ville',
|
||||||
'skyline',
|
'skyline',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (String term in genericTerms) {
|
for (String term in genericTerms) {
|
||||||
expect(term.isNotEmpty, true);
|
expect(term.isNotEmpty, true);
|
||||||
print('Generic term: $term');
|
print('Generic term: $term');
|
||||||
@@ -105,32 +100,34 @@ void main() {
|
|||||||
{'width': 300, 'height': 300}, // Carré
|
{'width': 300, 'height': 300}, // Carré
|
||||||
{'width': 1200, 'height': 800}, // Horizontal haute résolution
|
{'width': 1200, 'height': 800}, // Horizontal haute résolution
|
||||||
];
|
];
|
||||||
|
|
||||||
// Le tri devrait favoriser les photos horizontales
|
// Le tri devrait favoriser les photos horizontales
|
||||||
photos.sort((a, b) {
|
photos.sort((a, b) {
|
||||||
final aRatio = a['width']! / a['height']!;
|
final aRatio = a['width']! / a['height']!;
|
||||||
final bRatio = b['width']! / b['height']!;
|
final bRatio = b['width']! / b['height']!;
|
||||||
|
|
||||||
// Favoriser les ratios > 1 (horizontal)
|
// Favoriser les ratios > 1 (horizontal)
|
||||||
if (aRatio > 1 && bRatio <= 1) return -1;
|
if (aRatio > 1 && bRatio <= 1) return -1;
|
||||||
if (bRatio > 1 && aRatio <= 1) return 1;
|
if (bRatio > 1 && aRatio <= 1) return 1;
|
||||||
|
|
||||||
// Si les deux sont horizontaux, favoriser la plus haute résolution
|
// Si les deux sont horizontaux, favoriser la plus haute résolution
|
||||||
final aResolution = a['width']! * a['height']!;
|
final aResolution = a['width']! * a['height']!;
|
||||||
final bResolution = b['width']! * b['height']!;
|
final bResolution = b['width']! * b['height']!;
|
||||||
|
|
||||||
return bResolution.compareTo(aResolution);
|
return bResolution.compareTo(aResolution);
|
||||||
});
|
});
|
||||||
|
|
||||||
// La première photo devrait être celle avec la plus haute résolution horizontale
|
// La première photo devrait être celle avec la plus haute résolution horizontale
|
||||||
expect(photos.first['width'], 1200);
|
expect(photos.first['width'], 1200);
|
||||||
expect(photos.first['height'], 800);
|
expect(photos.first['height'], 800);
|
||||||
|
|
||||||
print('Photos triées par qualité:');
|
print('Photos triées par qualité:');
|
||||||
for (var photo in photos) {
|
for (var photo in photos) {
|
||||||
final ratio = photo['width']! / photo['height']!;
|
final ratio = photo['width']! / photo['height']!;
|
||||||
print('${photo['width']}x${photo['height']} (ratio: ${ratio.toStringAsFixed(2)})');
|
print(
|
||||||
|
'${photo['width']}x${photo['height']} (ratio: ${ratio.toStringAsFixed(2)})',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user