Compare commits

...

133 Commits

Author SHA1 Message Date
Van Leemput Dayron
e665dea82a feat(activities): add autocomplete & what's new popup
All checks were successful
Deploy TravelMate (Full Mobile) / deploy-android (push) Successful in 2m6s
Deploy TravelMate (Full Mobile) / deploy-ios (push) Successful in 4m3s
Features:
- Add autocomplete support for Activity search with Google Places API.
- Add "What's New" popup system to showcase new features on app update.
- Implement logic to detect fresh installs vs updates.

Fixes:
- Switch API key handling to use Firebase config for Release mode support.
- Refactor map pins to be consistent (red pins).
- UI fixes on Create Trip page (overflow issues).

Refactor:
- Make WhatsNewDialog reusable by accepting features list as parameter.
2026-01-13 17:36:51 +01:00
Van Leemput Dayron
b511ec5df0 Update map autocompletion
All checks were successful
Deploy TravelMate (Full Mobile) / deploy-android (push) Successful in 2m5s
Deploy TravelMate (Full Mobile) / deploy-ios (push) Successful in 3m53s
2026-01-13 17:15:22 +01:00
Van Leemput Dayron
c0e53cd3f6 feat: enhance global search and map experience
All checks were successful
Deploy TravelMate (Full Mobile) / deploy-android (push) Successful in 2m10s
Deploy TravelMate (Full Mobile) / deploy-ios (push) Successful in 4m19s
- Global Activity Search:
  - Allow searching activities globally (not just in destination).
  - Add distance warning for activities > 50km away.
- Create Trip UI:
  - Fix destination suggestion list overflow.
  - Prevent suggestion list from reappearing after selection.
- Map:
  - Add generic text search support (e.g., "Restaurants") on 'Enter'.
  - Display multiple results for generic searches.
  - Resize markers (User 60.0, Places 50.0).
  - Standardize place markers to red pin.
2026-01-13 16:59:04 +01:00
Van Leemput Dayron
4fc7abc5b4 test 36
All checks were successful
Deploy TravelMate (Full Mobile) / deploy-android (push) Successful in 2m16s
Deploy TravelMate (Full Mobile) / deploy-ios (push) Successful in 3m54s
2026-01-11 19:37:53 +01:00
Van Leemput Dayron
e04bf6f405 test 35
Some checks failed
Deploy TravelMate (Full Mobile) / deploy-android (push) Successful in 1m59s
Deploy TravelMate (Full Mobile) / deploy-ios (push) Failing after 28s
2026-01-11 19:34:17 +01:00
Van Leemput Dayron
bed761401f test 34
Some checks failed
Deploy TravelMate (Full Mobile) / deploy-android (push) Successful in 1m57s
Deploy TravelMate (Full Mobile) / deploy-ios (push) Failing after 3m8s
2026-01-11 19:25:16 +01:00
Van Leemput Dayron
55463649b2 test 33
Some checks failed
Deploy TravelMate (Full Mobile) / deploy-android (push) Successful in 1m55s
Deploy TravelMate (Full Mobile) / deploy-ios (push) Failing after 3m14s
2026-01-11 19:15:48 +01:00
Van Leemput Dayron
62d2aa17be test 32
Some checks failed
Deploy TravelMate (Full Mobile) / deploy-android (push) Successful in 2m16s
Deploy TravelMate (Full Mobile) / deploy-ios (push) Failing after 3m2s
2026-01-11 19:08:23 +01:00
Van Leemput Dayron
acfb2259cc test 31
Some checks failed
Deploy TravelMate Final Fix / deploy-all (push) Failing after 1m12s
2026-01-11 00:12:56 +01:00
Van Leemput Dayron
d1d2194861 test 30
Some checks failed
Deploy TravelMate (Full Mobile) / deploy-android (push) Successful in 2m2s
Deploy TravelMate (Full Mobile) / deploy-ios (push) Failing after 3m28s
2026-01-11 00:04:59 +01:00
Van Leemput Dayron
b542f98a91 test 29
Some checks failed
Deploy TravelMate (Android & iOS) / deploy-android (push) Successful in 1m59s
Deploy TravelMate (Android & iOS) / deploy-ios (push) Failing after 3m27s
2026-01-10 23:57:25 +01:00
Van Leemput Dayron
f983b869ba test 28
Some checks failed
Deploy TravelMate (Android & iOS) / deploy-android (push) Successful in 2m19s
Deploy TravelMate (Android & iOS) / deploy-ios (push) Failing after 3m24s
2026-01-10 23:49:53 +01:00
Van Leemput Dayron
ead346bb1b test 27
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Has been cancelled
2026-01-10 23:44:33 +01:00
Van Leemput Dayron
8d27e771a7 test 26
All checks were successful
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m18s
2026-01-10 23:40:18 +01:00
Van Leemput Dayron
31fe3a4260 test 25
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m7s
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 3m4s
2026-01-10 23:33:36 +01:00
Van Leemput Dayron
a2c6cd1d4f test 24
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m12s
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 3m13s
2026-01-10 23:26:05 +01:00
Van Leemput Dayron
5fe9f371b2 test 23
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m0s
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 3m7s
2026-01-10 23:19:44 +01:00
Van Leemput Dayron
b27fb7ed4c test 22
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m12s
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 3m19s
2026-01-10 23:12:47 +01:00
Van Leemput Dayron
919ef611bc test 21
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m15s
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 3m14s
2026-01-10 23:05:59 +01:00
Van Leemput Dayron
3eeed888b5 test 20
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m12s
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 3m25s
2026-01-10 22:57:46 +01:00
Van Leemput Dayron
322f611522 test 19
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m21s
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 3m21s
2026-01-10 22:50:49 +01:00
Van Leemput Dayron
a7d2634c5f test 18
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Has been cancelled
Deploy Flutter to Firebase iOS (Fixed) / deploy-ios (push) Failing after 2m59s
2026-01-10 22:39:47 +01:00
Van Leemput Dayron
ae125f1144 test 17
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m15s
Deploy Flutter to Firebase iOS (Fixed) / deploy-ios (push) Failing after 47s
2026-01-10 22:31:30 +01:00
Van Leemput Dayron
d66907f636 test 16
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m25s
Deploy Flutter to Firebase iOS (Final) / deploy-ios (push) Failing after 28s
2026-01-10 22:26:24 +01:00
Van Leemput Dayron
508d69a4f4 test 15
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m35s
Deploy Flutter to Firebase iOS (Final & Safe) / deploy-ios (push) Failing after 1m3s
2026-01-10 22:02:09 +01:00
Van Leemput Dayron
ee00415d23 Test 14
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m59s
Deploy Flutter to Firebase iOS (Final & Safe) / deploy-ios (push) Failing after 57s
2026-01-10 21:55:31 +01:00
Van Leemput Dayron
576b86fbbb Test 13
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 3m12s
Deploy Flutter to Firebase iOS (Safe Mode) / deploy-ios (push) Failing after 1m1s
2026-01-10 21:46:59 +01:00
Van Leemput Dayron
918742293b test 12 2026-01-10 21:38:04 +01:00
Van Leemput Dayron
19c06c71f8 test 11
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m42s
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 1m11s
2026-01-10 21:30:24 +01:00
Van Leemput Dayron
3e5f3a7ece test 10
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m24s
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 1m12s
2026-01-10 21:24:58 +01:00
Van Leemput Dayron
12fdd6da62 test 9
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m20s
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 45s
2026-01-10 21:20:16 +01:00
Van Leemput Dayron
15a7319239 test 8
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m23s
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 44s
2026-01-10 21:13:42 +01:00
Van Leemput Dayron
911fb86611 test 7
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m21s
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 48s
2026-01-10 21:08:13 +01:00
Van Leemput Dayron
8b4c66ba0d Test 6
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m25s
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 42s
2026-01-10 21:03:07 +01:00
Van Leemput Dayron
1352dc49cc Test 5
Some checks failed
Deploy Flutter to Firebase iOS / deploy-ios (push) Has been cancelled
Deploy Flutter to Firebase (Mac) / deploy-android (push) Has been cancelled
2026-01-10 20:51:13 +01:00
Van Leemput Dayron
51ffe2031d test 4
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m36s
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 47s
2026-01-10 20:23:02 +01:00
Van Leemput Dayron
c70ed9c504 test 3
Some checks failed
Deploy Flutter to Firebase iOS / deploy-ios (push) Failing after 13s
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m52s
2026-01-10 20:17:54 +01:00
Van Leemput Dayron
67d798f590 Test 2 ios
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m36s
Deploy Flutter to Firebase iOS / deploy-ios (push) Has been cancelled
2026-01-10 19:56:46 +01:00
Van Leemput Dayron
d60cce83c9 Firebase IOS distrivution
Some checks are pending
Deploy Flutter to Firebase iOS (Mac) / deploy-ios (push) Waiting to run
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 3m39s
2026-01-10 19:18:38 +01:00
Van Leemput Dayron
c03d2b969c preparing to deploy on ios 2026-01-03 16:25:33 +01:00
Van Leemput Dayron
4af4450b94 feat: add Firebase Analytics and make Google Maps Flutter dependencies direct.
All checks were successful
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 3m23s
2026-01-02 17:27:27 +01:00
Van Leemput Dayron
6be4bed2e0 Merge branch 'main' into release 2026-01-02 17:26:26 +01:00
Van Leemput Dayron
d13094c662 Fix problems 2026-01-02 17:24:59 +01:00
Van Leemput Dayron
a9c3087f53 feat: integrate Firebase Analytics, add Google Maps dependencies, and expose new GA4 metric API endpoints. 2026-01-02 17:10:03 +01:00
Van Leemput Dayron
1b6d40627d feat: Switch API key retrieval from flutter_dotenv to firebase_options.dart and update build version.
All checks were successful
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 3m4s
2025-12-30 17:10:12 +01:00
Van Leemput Dayron
67a7d1ad2a feat: Streamline Google Maps API key retrieval and update Google Maps Flutter dependencies.
All checks were successful
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m48s
2025-12-30 16:56:13 +01:00
Van Leemput Dayron
4ef550f48b Fix theme in settings
All checks were successful
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m59s
2025-12-30 16:34:05 +01:00
Van Leemput Dayron
993a5870c5 fix: enhance missing Google Maps API key error message with debug details including available keys and platform information.
All checks were successful
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m53s
2025-12-30 16:23:56 +01:00
Van Leemput Dayron
5a682bb6d7 refactor: Remove generic try-catch blocks and add explicit API error handling in activity places service.
All checks were successful
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 3m41s
2025-12-30 16:05:04 +01:00
Van Leemput Dayron
bb5a89a06d feat: clear navigation stack after successful authentication in login and signup flows 2025-12-30 15:53:53 +01:00
Van Leemput Dayron
3036eec3af Add backend to monitore the app in a desktop app 2025-12-30 15:37:10 +01:00
Van Leemput Dayron
63fc18ea74 feat: add password requirement display and enhance password validation on the signup page.
All checks were successful
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m40s
2025-12-15 16:02:50 +01:00
Van Leemput Dayron
ca3f62c709 Launch Android Firebase
All checks were successful
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m57s
2025-12-15 15:41:46 +01:00
Van Leemput Dayron
b13f0b87a3 Last Test Android
All checks were successful
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m49s
2025-12-15 15:33:01 +01:00
Van Leemput Dayron
8ec8f35a31 test 48
All checks were successful
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 2m43s
2025-12-15 14:37:19 +01:00
Van Leemput Dayron
230b7abf8b test 47
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 1m49s
2025-12-15 13:45:56 +01:00
Van Leemput Dayron
2abb080c09 Test 46
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 2m7s
2025-12-15 13:31:12 +01:00
Van Leemput Dayron
a34c1e5a3d test 45
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 1m46s
2025-12-15 13:27:39 +01:00
Van Leemput Dayron
68605dea78 test 44
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 1m36s
2025-12-15 13:24:06 +01:00
Van Leemput Dayron
59b708a160 test 43
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 15s
2025-12-15 01:16:32 +01:00
Van Leemput Dayron
2849dfaade Test 42
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 1m34s
2025-12-15 01:12:49 +01:00
Van Leemput Dayron
b08f9164e6 test 41
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 1m38s
2025-12-15 01:07:59 +01:00
Van Leemput Dayron
5fb9fbaf2b test 40
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 1m46s
2025-12-15 01:03:07 +01:00
Van Leemput Dayron
520c38782f test 39
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 2m14s
2025-12-15 00:59:03 +01:00
Van Leemput Dayron
5b21fb12e3 test 38
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 15s
2025-12-15 00:56:12 +01:00
Van Leemput Dayron
a49aa198f4 test 37
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 32s
2025-12-15 00:53:49 +01:00
Van Leemput Dayron
ef895ff892 test 36
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 16s
2025-12-15 00:51:11 +01:00
Van Leemput Dayron
06c8d2c589 Test
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 24s
2025-12-15 00:12:47 +01:00
Van Leemput Dayron
20be1ab64c test
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 23s
2025-12-14 21:21:13 +01:00
Van Leemput Dayron
795f0e8853 test
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 33s
2025-12-14 21:04:48 +01:00
Van Leemput Dayron
d3f2cc6eb0 test
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 35s
2025-12-13 12:49:25 +01:00
Van Leemput Dayron
e34780c9a7 test
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 16s
2025-12-13 12:45:26 +01:00
Van Leemput Dayron
495b0dc98f Test
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 5s
2025-12-13 12:43:30 +01:00
Van Leemput Dayron
7b03381f7c fix: Configure Ruby 3.0 and use bundle exec for Fastlane deployment, and remove outdated comments.
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 21s
2025-12-13 12:42:03 +01:00
Van Leemput Dayron
800a402046 test
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 12s
2025-12-13 12:37:37 +01:00
Van Leemput Dayron
50101d1196 chore: Adjust Gemfile.lock dependencies, including AWS and Google Cloud SDKs, and update Bundler version.
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 14s
2025-12-13 12:36:35 +01:00
Van Leemput Dayron
ae25ea73a8 Test Mac OS
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 12s
2025-12-13 12:29:57 +01:00
Van Leemput Dayron
407425a2b9 chore: remove unnecessary comment from Fastfile
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 12s
2025-12-13 12:27:26 +01:00
Van Leemput Dayron
088f4a2833 feat: Migrate Android deployment workflow to macOS runner, simplifying setup steps and updating Fastlane descriptions.
Some checks failed
Deploy Flutter to Firebase (Mac) / deploy-android (push) Failing after 22s
2025-12-13 12:25:39 +01:00
Van Leemput Dayron
c63124b16b fix: Increase Gradle JVM memory allocation in Android deployment workflow to 3072m.
Some checks failed
Deploy Flutter to Firebase / deploy-android (push) Failing after 22m42s
2025-12-13 11:47:08 +01:00
Van Leemput Dayron
329708fe6c Test N°22
Some checks failed
Deploy Flutter to Firebase / deploy-android (push) Failing after 9m42s
2025-12-12 16:56:00 +01:00
Van Leemput Dayron
e5b2be5245 Retry
Some checks failed
Deploy Flutter to Firebase / deploy-android (push) Failing after 14m25s
2025-12-09 16:26:23 +01:00
Van Leemput Dayron
0fb1634a91 fix: Configure Gradle JVM memory with GRADLE_OPTS and update workflow comments.
Some checks failed
Deploy Flutter to Firebase / deploy-android (push) Failing after 14m55s
2025-12-09 16:02:56 +01:00
Van Leemput Dayron
8634edc916 feat: Enforce portrait orientation across platforms and switch Android Fastlane deployment from APK to AAB.
Some checks failed
Deploy Flutter to Firebase / deploy-android (push) Failing after 13m51s
2025-12-09 15:29:00 +01:00
Van Leemput Dayron
1211569078 ci: add step to create .env file from secrets in Android deploy workflow
Some checks failed
Deploy Flutter to Firebase / deploy-android (push) Failing after 12m5s
2025-12-09 15:04:33 +01:00
Van Leemput Dayron
26b970982c chore: ensure Android license acceptance step always succeeds in CI workflow.
Some checks failed
Deploy Flutter to Firebase / deploy-android (push) Failing after 11m0s
2025-12-09 14:51:22 +01:00
Van Leemput Dayron
e77393dd13 ci: update deploy-android workflow to trigger only on the release branch
Some checks failed
Deploy Flutter to Firebase / deploy-android (push) Failing after 1m23s
2025-12-09 14:47:36 +01:00
Van Leemput Dayron
020fa8823d ci: add Android SDK setup and license acceptance to the Android deployment workflow. 2025-12-09 14:47:04 +01:00
Van Leemput Dayron
959fc33fe4 refactor: use direct shell command for Flutter release APK build.
Some checks failed
Deploy Flutter to Firebase / deploy-android (push) Failing after 34s
2025-12-09 11:31:21 +01:00
Van Leemput Dayron
a57fc811d8 ci: Disable Flutter action cache in Android deployment workflow.
Some checks failed
Deploy Flutter to Firebase / deploy-android (push) Failing after 50s
2025-12-09 11:27:54 +01:00
Van Leemput Dayron
a96084ba17 ci: Update Ruby version to 3.3 in Android deployment workflow.
Some checks failed
Deploy Flutter to Firebase / deploy-android (push) Has been cancelled
2025-12-09 11:21:33 +01:00
Van Leemput Dayron
b96c988e80 feat: Set up Fastlane for Android with Firebase App Distribution and adjust build configurations.
Some checks failed
Deploy Flutter to Firebase / deploy-android (push) Has been cancelled
2025-12-09 11:07:09 +01:00
Van Leemput Dayron
14d2761832 ci: Add .env file creation for Google Maps API keys and fix Android package name in deploy workflow.
Some checks failed
Deploy Android to Play Store / build-and-deploy (push) Failing after 26m39s
2025-12-08 21:30:59 +01:00
Van Leemput Dayron
bd3fd28d3c Try resolving CI/CD
Some checks failed
Deploy Android to Play Store / build-and-deploy (push) Failing after 26m33s
2025-12-08 21:01:29 +01:00
Van Leemput Dayron
e8ef20d046 ci: Add Android SDK setup step to the Android deployment workflow.
Some checks failed
Deploy Android to Play Store / build-and-deploy (push) Has been cancelled
2025-12-08 20:48:02 +01:00
Van Leemput Dayron
9fc8d5d1de ci: Add Flutter action cache and remove explicit Flutter version.
Some checks failed
Deploy Android to Play Store / build-and-deploy (push) Failing after 20m38s
2025-12-08 18:20:03 +01:00
Van Leemput Dayron
73db84896a feat: Migrate Android deployment from Jenkins and Fastlane to Gitea Actions workflow.
Some checks failed
Deploy Android to Play Store / build-and-deploy (push) Failing after 4m10s
2025-12-08 18:04:42 +01:00
Van Leemput Dayron
9734532491 style: Fix indentation of Android build and deploy stage in Jenkinsfile 2025-12-08 17:08:35 +01:00
Van Leemput Dayron
7d38f54123 feat: Add retrieval and copying of Flutter .env file from Jenkins credentials for Android build. 2025-12-08 17:06:29 +01:00
Van Leemput Dayron
d02a627b86 fix: Remove Jenkins tools block and hardcode Java path in PATH environment variable. 2025-12-08 16:58:36 +01:00
Van Leemput Dayron
6ce40dd2d6 fix: Consolidate Jenkinsfile PATH environment variable into a single line and clarify related comments for JAVA_HOME and ANDROID_HOME. 2025-12-08 16:51:40 +01:00
Van Leemput Dayron
00ffdcf10b ci: Add JDK 17 tool definition and configure JAVA_HOME in Jenkinsfile. 2025-12-08 16:43:57 +01:00
Van Leemput Dayron
e4d38692fe ci: Add /usr/local/bin to the PATH environment variable in Jenkinsfile. 2025-12-08 16:23:06 +01:00
Van Leemput Dayron
1f93a4e42d ci: Migrate Android Play Store deployment from GitHub Actions to Jenkins using Fastlane. 2025-12-08 16:11:40 +01:00
Van Leemput Dayron
bf48971dc4 feat: Propagate user profile updates to group member details and remove trip code sharing UI.
Some checks failed
Deploy to Play Store / build_and_deploy (push) Has been cancelled
2025-12-06 16:43:40 +01:00
Van Leemput Dayron
13933fc56c Resolve map problem. 2025-12-06 15:50:19 +01:00
Van Leemput Dayron
ca28e0a780 feat: Implement platform-specific Google Maps API key handling and update app version.
Some checks failed
Deploy to Play Store / build_and_deploy (push) Has been cancelled
2025-12-06 14:43:22 +01:00
Van Leemput Dayron
34b5efb1fc feat: remove notifications settings option from settings content
Some checks failed
Deploy to Play Store / build_and_deploy (push) Has been cancelled
2025-12-05 18:45:34 +01:00
Van Leemput Dayron
f96a51c7cf refactor: standardize API error and success responses with explicit returns and JSON messages
Some checks failed
Deploy to Play Store / build_and_deploy (push) Has been cancelled
2025-12-05 18:42:59 +01:00
Van Leemput Dayron
cac0770467 feat: Introduce comprehensive unit tests for models and BLoCs using mockito and bloc_test, and refine TripBloc error handling.
Some checks failed
Deploy to Play Store / build_and_deploy (push) Has been cancelled
2025-12-05 11:55:20 +01:00
Van Leemput Dayron
9b11836409 feat: add high priority Android notifications and set chat input field line limits 2025-12-04 15:05:04 +01:00
Van Leemput Dayron
9f2bfcaa55 feat: Add full-screen receipt viewer, display trip participants in calendar, and restrict trip management options to creator. 2025-12-04 14:25:27 +01:00
Van Leemput Dayron
e174c1274d feat: Add map navigation, enhance FCM deep linking, localize Google Places API, and refine activity display. 2025-12-04 11:24:30 +01:00
Van Leemput Dayron
cf4c6447dd feat: Redesign calendar page with default week view, improved app bar, and a consolidated activity timeline. 2025-12-03 23:51:16 +01:00
Van Leemput Dayron
a74d76b485 Trying to do the notification for all users. 2025-12-03 17:32:06 +01:00
Van Leemput Dayron
fd19b88eef feat: Implement Apple Sign-In for Android by adding a callback function, updating redirect URI, and configuring the Android manifest. 2025-12-03 15:41:22 +01:00
Van Leemput Dayron
f3ae91ccf9 refactor: Centralize error and notification handling using a dedicated _errorService across various components. 2025-12-03 14:50:03 +01:00
Van Leemput Dayron
6757cb013a feat: integrate ErrorService for consistent error display and standardize bloc error messages. 2025-12-02 13:59:40 +01:00
Van Leemput Dayron
1e70b9e09f feat: Enable iOS push notifications and improve APNS token retrieval. 2025-11-28 20:27:29 +01:00
Van Leemput Dayron
b4bcc8f498 feat: Upgrade Firebase Functions dependencies, enhance notification service with APNS support and FCM 2025-11-28 20:18:24 +01:00
Van Leemput Dayron
68f546d0e8 Add notification 2025-11-28 19:16:37 +01:00
Van Leemput Dayron
0668fcad57 feat: refactor account deletion to handle requires-recent-login and update Android package ID. 2025-11-28 19:01:01 +01:00
Van Leemput Dayron
b1f86b1c6a build 2025-11-28 13:22:03 +01:00
Van Leemput Dayron
bf796a661c feat: Update Android namespace and application ID, and configure release signing.
Some checks failed
Deploy to Play Store / build_and_deploy (push) Has been cancelled
2025-11-28 13:07:01 +01:00
Van Leemput Dayron
272fce2e59 feat: add GitHub Actions workflow for automated Play Store deployment 2025-11-28 13:06:40 +01:00
Van Leemput Dayron
fd710b8cb8 feat: Add logger service and improve expense dialog with enhanced receipt management and calculation logic. 2025-11-28 12:54:54 +01:00
Van Leemput Dayron
cad9d42128 feat: Introduce memberIds for efficient group querying and management, updating related UI components and .gitignore. 2025-11-27 15:36:46 +01:00
Van Leemput Dayron
9198493dd5 Add vscode counter to gitignore 2025-11-26 18:11:35 +01:00
Van Leemput Dayron
f7eeb7c6f1 feat: Add calendar page, enhance activity search and approval logic, and refactor activity filtering UI. 2025-11-26 12:15:13 +01:00
Van Leemput Dayron
258f10b42b Implement message deletion functionality: add isDeleted flag to Message model, update deleteMessage method in MessageRepository, and adjust chat display for deleted messages. 2025-11-14 00:54:28 +01:00
Van Leemput Dayron
79cf3f4655 Enhance group member management: add last name support in GroupMember model, update member display in chat and trip details, and implement pseudo change functionality in chat group. 2025-11-14 00:34:28 +01:00
Van Leemput Dayron
c322bc079a Add functionality to manage account members: implement add and remove member events, update account repository methods, and integrate with trip details for participant management. 2025-11-14 00:03:38 +01:00
Van Leemput Dayron
9101a94691 Add sender avatar display and member list enhancements in chat group 2025-11-13 18:35:00 +01:00
123 changed files with 18467 additions and 4830 deletions

View File

@@ -1,82 +0,0 @@
# Details
Date : 2025-10-14 11:10:48
Directory c:\\Users\\dayro\\Documents\\coding\\travel_mate
Total : 67 files, 5159 codes, 328 comments, 739 blanks, all 6226 lines
[Summary](results.md) / Details / [Diff Summary](diff.md) / [Diff Details](diff-details.md)
## Files
| filename | language | code | comment | blank | total |
| :--- | :--- | ---: | ---: | ---: | ---: |
| [README.md](/README.md) | Markdown | 45 | 0 | 16 | 61 |
| [analysis\_options.yaml](/analysis_options.yaml) | YAML | 3 | 22 | 4 | 29 |
| [android/app/google-services.json](/android/app/google-services.json) | JSON | 54 | 0 | 0 | 54 |
| [android/app/src/debug/AndroidManifest.xml](/android/app/src/debug/AndroidManifest.xml) | XML | 3 | 4 | 1 | 8 |
| [android/app/src/main/AndroidManifest.xml](/android/app/src/main/AndroidManifest.xml) | XML | 40 | 11 | 1 | 52 |
| [android/app/src/main/res/drawable-v21/launch\_background.xml](/android/app/src/main/res/drawable-v21/launch_background.xml) | XML | 4 | 7 | 2 | 13 |
| [android/app/src/main/res/drawable/launch\_background.xml](/android/app/src/main/res/drawable/launch_background.xml) | XML | 4 | 7 | 2 | 13 |
| [android/app/src/main/res/values-night/styles.xml](/android/app/src/main/res/values-night/styles.xml) | XML | 9 | 9 | 1 | 19 |
| [android/app/src/main/res/values/styles.xml](/android/app/src/main/res/values/styles.xml) | XML | 9 | 9 | 1 | 19 |
| [android/app/src/profile/AndroidManifest.xml](/android/app/src/profile/AndroidManifest.xml) | XML | 3 | 4 | 1 | 8 |
| [android/build/reports/problems/problems-report.html](/android/build/reports/problems/problems-report.html) | HTML | 548 | 2 | 114 | 664 |
| [android/gradle.properties](/android/gradle.properties) | Properties | 3 | 0 | 1 | 4 |
| [android/gradle/wrapper/gradle-wrapper.properties](/android/gradle/wrapper/gradle-wrapper.properties) | Properties | 5 | 0 | 1 | 6 |
| [firebase.json](/firebase.json) | JSON | 1 | 0 | 0 | 1 |
| [ios/Podfile](/ios/Podfile) | Ruby | 32 | 2 | 10 | 44 |
| [ios/RunnerTests/RunnerTests.swift](/ios/RunnerTests/RunnerTests.swift) | Swift | 7 | 2 | 4 | 13 |
| [ios/Runner/AppDelegate.swift](/ios/Runner/AppDelegate.swift) | Swift | 14 | 0 | 2 | 16 |
| [ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json](/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json) | JSON | 122 | 0 | 1 | 123 |
| [ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json](/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json) | JSON | 23 | 0 | 1 | 24 |
| [ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md](/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md) | Markdown | 3 | 0 | 2 | 5 |
| [ios/Runner/Base.lproj/LaunchScreen.storyboard](/ios/Runner/Base.lproj/LaunchScreen.storyboard) | XML | 36 | 1 | 1 | 38 |
| [ios/Runner/Base.lproj/Main.storyboard](/ios/Runner/Base.lproj/Main.storyboard) | XML | 25 | 1 | 1 | 27 |
| [ios/Runner/Runner-Bridging-Header.h](/ios/Runner/Runner-Bridging-Header.h) | C++ | 1 | 0 | 1 | 2 |
| [lib/blocs/auth/auth\_bloc.dart](/lib/blocs/auth/auth_bloc.dart) | Dart | 129 | 1 | 20 | 150 |
| [lib/blocs/auth/auth\_event.dart](/lib/blocs/auth/auth_event.dart) | Dart | 40 | 0 | 15 | 55 |
| [lib/blocs/auth/auth\_state.dart](/lib/blocs/auth/auth_state.dart) | Dart | 28 | 0 | 14 | 42 |
| [lib/blocs/theme/theme\_bloc.dart](/lib/blocs/theme/theme_bloc.dart) | Dart | 40 | 1 | 5 | 46 |
| [lib/blocs/theme/theme\_event.dart](/lib/blocs/theme/theme_event.dart) | Dart | 14 | 0 | 6 | 20 |
| [lib/blocs/theme/theme\_state.dart](/lib/blocs/theme/theme_state.dart) | Dart | 16 | 0 | 5 | 21 |
| [lib/blocs/trip/trip\_bloc.dart](/lib/blocs/trip/trip_bloc.dart) | Dart | 103 | 1 | 14 | 118 |
| [lib/blocs/trip/trip\_event.dart](/lib/blocs/trip/trip_event.dart) | Dart | 51 | 0 | 20 | 71 |
| [lib/blocs/trip/trip\_state.dart](/lib/blocs/trip/trip_state.dart) | Dart | 27 | 0 | 13 | 40 |
| [lib/blocs/user/user\_bloc.dart](/lib/blocs/user/user_bloc.dart) | Dart | 0 | 0 | 1 | 1 |
| [lib/blocs/user/user\_event.dart](/lib/blocs/user/user_event.dart) | Dart | 0 | 0 | 1 | 1 |
| [lib/blocs/user/user\_state.dart](/lib/blocs/user/user_state.dart) | Dart | 0 | 0 | 1 | 1 |
| [lib/components/count/count\_content.dart](/lib/components/count/count_content.dart) | Dart | 25 | 0 | 3 | 28 |
| [lib/components/group/group\_content.dart](/lib/components/group/group_content.dart) | Dart | 115 | 2 | 12 | 129 |
| [lib/components/home/create\_trip\_content.dart](/lib/components/home/create_trip_content.dart) | Dart | 481 | 21 | 63 | 565 |
| [lib/components/home/home\_content.dart](/lib/components/home/home_content.dart) | Dart | 366 | 12 | 30 | 408 |
| [lib/components/home/show\_trip\_details\_content.dart](/lib/components/home/show_trip_details_content.dart) | Dart | 106 | 2 | 4 | 112 |
| [lib/components/map/map\_content.dart](/lib/components/map/map_content.dart) | Dart | 100 | 4 | 11 | 115 |
| [lib/components/profile/profile\_content.dart](/lib/components/profile/profile_content.dart) | Dart | 328 | 6 | 29 | 363 |
| [lib/components/settings/settings\_content.dart](/lib/components/settings/settings_content.dart) | Dart | 60 | 2 | 10 | 72 |
| [lib/components/settings/settings\_theme\_content.dart](/lib/components/settings/settings_theme_content.dart) | Dart | 123 | 4 | 10 | 137 |
| [lib/data/data\_sources/firestore\_data\_source.dart](/lib/data/data_sources/firestore_data_source.dart) | Dart | 0 | 0 | 1 | 1 |
| [lib/data/data\_sources/local\_data\_source.dart](/lib/data/data_sources/local_data_source.dart) | Dart | 0 | 0 | 1 | 1 |
| [lib/data/models/group.dart](/lib/data/models/group.dart) | Dart | 23 | 0 | 3 | 26 |
| [lib/data/models/message.dart](/lib/data/models/message.dart) | Dart | 14 | 0 | 1 | 15 |
| [lib/data/models/trip.dart](/lib/data/models/trip.dart) | Dart | 176 | 16 | 24 | 216 |
| [lib/data/models/user.dart](/lib/data/models/user.dart) | Dart | 61 | 6 | 13 | 80 |
| [lib/firebase\_options.dart](/lib/firebase_options.dart) | Dart | 60 | 12 | 5 | 77 |
| [lib/main.dart](/lib/main.dart) | Dart | 89 | 0 | 5 | 94 |
| [lib/pages/home.dart](/lib/pages/home.dart) | Dart | 147 | 6 | 13 | 166 |
| [lib/pages/login.dart](/lib/pages/login.dart) | Dart | 285 | 9 | 28 | 322 |
| [lib/pages/resetpswd.dart](/lib/pages/resetpswd.dart) | Dart | 92 | 2 | 13 | 107 |
| [lib/pages/signup.dart](/lib/pages/signup.dart) | Dart | 256 | 7 | 20 | 283 |
| [lib/providers/theme\_provider.dart](/lib/providers/theme_provider.dart) | Dart | 41 | 1 | 9 | 51 |
| [lib/providers/user\_provider.dart](/lib/providers/user_provider.dart) | Dart | 94 | 9 | 18 | 121 |
| [lib/repositories/auth\_repository.dart](/lib/repositories/auth_repository.dart) | Dart | 115 | 11 | 22 | 148 |
| [lib/repositories/trip\_repository.dart](/lib/repositories/trip_repository.dart) | Dart | 92 | 9 | 12 | 113 |
| [lib/repositories/user\_repository.dart](/lib/repositories/user_repository.dart) | Dart | 77 | 7 | 11 | 95 |
| [lib/services/auth\_service.dart](/lib/services/auth_service.dart) | Dart | 84 | 6 | 18 | 108 |
| [lib/services/group\_service.dart](/lib/services/group_service.dart) | Dart | 53 | 1 | 6 | 60 |
| [lib/services/message\_service.dart](/lib/services/message_service.dart) | Dart | 0 | 0 | 1 | 1 |
| [lib/services/trip\_service.dart](/lib/services/trip_service.dart) | Dart | 209 | 21 | 39 | 269 |
| [pubspec.yaml](/pubspec.yaml) | YAML | 31 | 58 | 14 | 103 |
| [test/widget\_test.dart](/test/widget_test.dart) | Dart | 14 | 10 | 7 | 31 |
[Summary](results.md) / Details / [Diff Summary](diff.md) / [Diff Details](diff-details.md)

View File

@@ -1,15 +0,0 @@
# Diff Details
Date : 2025-10-14 11:10:48
Directory c:\\Users\\dayro\\Documents\\coding\\travel_mate
Total : 0 files, 0 codes, 0 comments, 0 blanks, all 0 lines
[Summary](results.md) / [Details](details.md) / [Diff Summary](diff.md) / Diff Details
## Files
| filename | language | code | comment | blank | total |
| :--- | :--- | ---: | ---: | ---: | ---: |
[Summary](results.md) / [Details](details.md) / [Diff Summary](diff.md) / Diff Details

View File

@@ -1,2 +0,0 @@
"filename", "language", "", "comment", "blank", "total"
"Total", "-", , 0, 0, 0
1 filename language comment blank total
2 Total - 0 0 0

View File

@@ -1,19 +0,0 @@
# Diff Summary
Date : 2025-10-14 11:10:48
Directory c:\\Users\\dayro\\Documents\\coding\\travel_mate
Total : 0 files, 0 codes, 0 comments, 0 blanks, all 0 lines
[Summary](results.md) / [Details](details.md) / Diff Summary / [Diff Details](diff-details.md)
## Languages
| language | files | code | comment | blank | total |
| :--- | ---: | ---: | ---: | ---: | ---: |
## Directories
| path | files | code | comment | blank | total |
| :--- | ---: | ---: | ---: | ---: | ---: |
[Summary](results.md) / [Details](details.md) / Diff Summary / [Diff Details](diff-details.md)

View File

@@ -1,22 +0,0 @@
Date : 2025-10-14 11:10:48
Directory : c:\Users\dayro\Documents\coding\travel_mate
Total : 0 files, 0 codes, 0 comments, 0 blanks, all 0 lines
Languages
+----------+------------+------------+------------+------------+------------+
| language | files | code | comment | blank | total |
+----------+------------+------------+------------+------------+------------+
+----------+------------+------------+------------+------------+------------+
Directories
+------+------------+------------+------------+------------+------------+
| path | files | code | comment | blank | total |
+------+------------+------------+------------+------------+------------+
+------+------------+------------+------------+------------+------------+
Files
+----------+----------+------------+------------+------------+------------+
| filename | language | code | comment | blank | total |
+----------+----------+------------+------------+------------+------------+
| Total | | 0 | 0 | 0 | 0 |
+----------+----------+------------+------------+------------+------------+

View File

@@ -1,69 +0,0 @@
"filename", "language", "YAML", "Markdown", "Dart", "JSON", "Swift", "C++", "XML", "Ruby", "Properties", "HTML", "comment", "blank", "total"
"c:\Users\dayro\Documents\coding\travel_mate\README.md", "Markdown", 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 61
"c:\Users\dayro\Documents\coding\travel_mate\analysis_options.yaml", "YAML", 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 4, 29
"c:\Users\dayro\Documents\coding\travel_mate\android\app\google-services.json", "JSON", 0, 0, 0, 54, 0, 0, 0, 0, 0, 0, 0, 0, 54
"c:\Users\dayro\Documents\coding\travel_mate\android\app\src\debug\AndroidManifest.xml", "XML", 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 4, 1, 8
"c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\AndroidManifest.xml", "XML", 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 11, 1, 52
"c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\res\drawable-v21\launch_background.xml", "XML", 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 7, 2, 13
"c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\res\drawable\launch_background.xml", "XML", 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 7, 2, 13
"c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\res\values-night\styles.xml", "XML", 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 9, 1, 19
"c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\res\values\styles.xml", "XML", 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 9, 1, 19
"c:\Users\dayro\Documents\coding\travel_mate\android\app\src\profile\AndroidManifest.xml", "XML", 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 4, 1, 8
"c:\Users\dayro\Documents\coding\travel_mate\android\build\reports\problems\problems-report.html", "HTML", 0, 0, 0, 0, 0, 0, 0, 0, 0, 548, 2, 114, 664
"c:\Users\dayro\Documents\coding\travel_mate\android\gradle.properties", "Properties", 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 1, 4
"c:\Users\dayro\Documents\coding\travel_mate\android\gradle\wrapper\gradle-wrapper.properties", "Properties", 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 1, 6
"c:\Users\dayro\Documents\coding\travel_mate\firebase.json", "JSON", 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
"c:\Users\dayro\Documents\coding\travel_mate\ios\Podfile", "Ruby", 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 2, 10, 44
"c:\Users\dayro\Documents\coding\travel_mate\ios\RunnerTests\RunnerTests.swift", "Swift", 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 2, 4, 13
"c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\AppDelegate.swift", "Swift", 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 2, 16
"c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Assets.xcassets\AppIcon.appiconset\Contents.json", "JSON", 0, 0, 0, 122, 0, 0, 0, 0, 0, 0, 0, 1, 123
"c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Assets.xcassets\LaunchImage.imageset\Contents.json", "JSON", 0, 0, 0, 23, 0, 0, 0, 0, 0, 0, 0, 1, 24
"c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Assets.xcassets\LaunchImage.imageset\README.md", "Markdown", 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 5
"c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Base.lproj\LaunchScreen.storyboard", "XML", 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 1, 1, 38
"c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Base.lproj\Main.storyboard", "XML", 0, 0, 0, 0, 0, 0, 25, 0, 0, 0, 1, 1, 27
"c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Runner-Bridging-Header.h", "C++", 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 2
"c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\auth\auth_bloc.dart", "Dart", 0, 0, 129, 0, 0, 0, 0, 0, 0, 0, 1, 20, 150
"c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\auth\auth_event.dart", "Dart", 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 15, 55
"c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\auth\auth_state.dart", "Dart", 0, 0, 28, 0, 0, 0, 0, 0, 0, 0, 0, 14, 42
"c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\theme\theme_bloc.dart", "Dart", 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 1, 5, 46
"c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\theme\theme_event.dart", "Dart", 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 6, 20
"c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\theme\theme_state.dart", "Dart", 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 5, 21
"c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\trip\trip_bloc.dart", "Dart", 0, 0, 103, 0, 0, 0, 0, 0, 0, 0, 1, 14, 118
"c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\trip\trip_event.dart", "Dart", 0, 0, 51, 0, 0, 0, 0, 0, 0, 0, 0, 20, 71
"c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\trip\trip_state.dart", "Dart", 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 13, 40
"c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\user\user_bloc.dart", "Dart", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1
"c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\user\user_event.dart", "Dart", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1
"c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\user\user_state.dart", "Dart", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1
"c:\Users\dayro\Documents\coding\travel_mate\lib\components\count\count_content.dart", "Dart", 0, 0, 25, 0, 0, 0, 0, 0, 0, 0, 0, 3, 28
"c:\Users\dayro\Documents\coding\travel_mate\lib\components\group\group_content.dart", "Dart", 0, 0, 115, 0, 0, 0, 0, 0, 0, 0, 2, 12, 129
"c:\Users\dayro\Documents\coding\travel_mate\lib\components\home\create_trip_content.dart", "Dart", 0, 0, 481, 0, 0, 0, 0, 0, 0, 0, 21, 63, 565
"c:\Users\dayro\Documents\coding\travel_mate\lib\components\home\home_content.dart", "Dart", 0, 0, 366, 0, 0, 0, 0, 0, 0, 0, 12, 30, 408
"c:\Users\dayro\Documents\coding\travel_mate\lib\components\home\show_trip_details_content.dart", "Dart", 0, 0, 106, 0, 0, 0, 0, 0, 0, 0, 2, 4, 112
"c:\Users\dayro\Documents\coding\travel_mate\lib\components\map\map_content.dart", "Dart", 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 4, 11, 115
"c:\Users\dayro\Documents\coding\travel_mate\lib\components\profile\profile_content.dart", "Dart", 0, 0, 328, 0, 0, 0, 0, 0, 0, 0, 6, 29, 363
"c:\Users\dayro\Documents\coding\travel_mate\lib\components\settings\settings_content.dart", "Dart", 0, 0, 60, 0, 0, 0, 0, 0, 0, 0, 2, 10, 72
"c:\Users\dayro\Documents\coding\travel_mate\lib\components\settings\settings_theme_content.dart", "Dart", 0, 0, 123, 0, 0, 0, 0, 0, 0, 0, 4, 10, 137
"c:\Users\dayro\Documents\coding\travel_mate\lib\data\data_sources\firestore_data_source.dart", "Dart", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1
"c:\Users\dayro\Documents\coding\travel_mate\lib\data\data_sources\local_data_source.dart", "Dart", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1
"c:\Users\dayro\Documents\coding\travel_mate\lib\data\models\group.dart", "Dart", 0, 0, 23, 0, 0, 0, 0, 0, 0, 0, 0, 3, 26
"c:\Users\dayro\Documents\coding\travel_mate\lib\data\models\message.dart", "Dart", 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 1, 15
"c:\Users\dayro\Documents\coding\travel_mate\lib\data\models\trip.dart", "Dart", 0, 0, 176, 0, 0, 0, 0, 0, 0, 0, 16, 24, 216
"c:\Users\dayro\Documents\coding\travel_mate\lib\data\models\user.dart", "Dart", 0, 0, 61, 0, 0, 0, 0, 0, 0, 0, 6, 13, 80
"c:\Users\dayro\Documents\coding\travel_mate\lib\firebase_options.dart", "Dart", 0, 0, 60, 0, 0, 0, 0, 0, 0, 0, 12, 5, 77
"c:\Users\dayro\Documents\coding\travel_mate\lib\main.dart", "Dart", 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 0, 5, 94
"c:\Users\dayro\Documents\coding\travel_mate\lib\pages\home.dart", "Dart", 0, 0, 147, 0, 0, 0, 0, 0, 0, 0, 6, 13, 166
"c:\Users\dayro\Documents\coding\travel_mate\lib\pages\login.dart", "Dart", 0, 0, 285, 0, 0, 0, 0, 0, 0, 0, 9, 28, 322
"c:\Users\dayro\Documents\coding\travel_mate\lib\pages\resetpswd.dart", "Dart", 0, 0, 92, 0, 0, 0, 0, 0, 0, 0, 2, 13, 107
"c:\Users\dayro\Documents\coding\travel_mate\lib\pages\signup.dart", "Dart", 0, 0, 256, 0, 0, 0, 0, 0, 0, 0, 7, 20, 283
"c:\Users\dayro\Documents\coding\travel_mate\lib\providers\theme_provider.dart", "Dart", 0, 0, 41, 0, 0, 0, 0, 0, 0, 0, 1, 9, 51
"c:\Users\dayro\Documents\coding\travel_mate\lib\providers\user_provider.dart", "Dart", 0, 0, 94, 0, 0, 0, 0, 0, 0, 0, 9, 18, 121
"c:\Users\dayro\Documents\coding\travel_mate\lib\repositories\auth_repository.dart", "Dart", 0, 0, 115, 0, 0, 0, 0, 0, 0, 0, 11, 22, 148
"c:\Users\dayro\Documents\coding\travel_mate\lib\repositories\trip_repository.dart", "Dart", 0, 0, 92, 0, 0, 0, 0, 0, 0, 0, 9, 12, 113
"c:\Users\dayro\Documents\coding\travel_mate\lib\repositories\user_repository.dart", "Dart", 0, 0, 77, 0, 0, 0, 0, 0, 0, 0, 7, 11, 95
"c:\Users\dayro\Documents\coding\travel_mate\lib\services\auth_service.dart", "Dart", 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 6, 18, 108
"c:\Users\dayro\Documents\coding\travel_mate\lib\services\group_service.dart", "Dart", 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, 1, 6, 60
"c:\Users\dayro\Documents\coding\travel_mate\lib\services\message_service.dart", "Dart", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1
"c:\Users\dayro\Documents\coding\travel_mate\lib\services\trip_service.dart", "Dart", 0, 0, 209, 0, 0, 0, 0, 0, 0, 0, 21, 39, 269
"c:\Users\dayro\Documents\coding\travel_mate\pubspec.yaml", "YAML", 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58, 14, 103
"c:\Users\dayro\Documents\coding\travel_mate\test\widget_test.dart", "Dart", 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 10, 7, 31
"Total", "-", 34, 48, 4134, 200, 21, 1, 133, 32, 8, 548, 328, 739, 6226
1 filename language YAML Markdown Dart JSON Swift C++ XML Ruby Properties HTML comment blank total
2 c:\Users\dayro\Documents\coding\travel_mate\README.md Markdown 0 45 0 0 0 0 0 0 0 0 0 16 61
3 c:\Users\dayro\Documents\coding\travel_mate\analysis_options.yaml YAML 3 0 0 0 0 0 0 0 0 0 22 4 29
4 c:\Users\dayro\Documents\coding\travel_mate\android\app\google-services.json JSON 0 0 0 54 0 0 0 0 0 0 0 0 54
5 c:\Users\dayro\Documents\coding\travel_mate\android\app\src\debug\AndroidManifest.xml XML 0 0 0 0 0 0 3 0 0 0 4 1 8
6 c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\AndroidManifest.xml XML 0 0 0 0 0 0 40 0 0 0 11 1 52
7 c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\res\drawable-v21\launch_background.xml XML 0 0 0 0 0 0 4 0 0 0 7 2 13
8 c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\res\drawable\launch_background.xml XML 0 0 0 0 0 0 4 0 0 0 7 2 13
9 c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\res\values-night\styles.xml XML 0 0 0 0 0 0 9 0 0 0 9 1 19
10 c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\res\values\styles.xml XML 0 0 0 0 0 0 9 0 0 0 9 1 19
11 c:\Users\dayro\Documents\coding\travel_mate\android\app\src\profile\AndroidManifest.xml XML 0 0 0 0 0 0 3 0 0 0 4 1 8
12 c:\Users\dayro\Documents\coding\travel_mate\android\build\reports\problems\problems-report.html HTML 0 0 0 0 0 0 0 0 0 548 2 114 664
13 c:\Users\dayro\Documents\coding\travel_mate\android\gradle.properties Properties 0 0 0 0 0 0 0 0 3 0 0 1 4
14 c:\Users\dayro\Documents\coding\travel_mate\android\gradle\wrapper\gradle-wrapper.properties Properties 0 0 0 0 0 0 0 0 5 0 0 1 6
15 c:\Users\dayro\Documents\coding\travel_mate\firebase.json JSON 0 0 0 1 0 0 0 0 0 0 0 0 1
16 c:\Users\dayro\Documents\coding\travel_mate\ios\Podfile Ruby 0 0 0 0 0 0 0 32 0 0 2 10 44
17 c:\Users\dayro\Documents\coding\travel_mate\ios\RunnerTests\RunnerTests.swift Swift 0 0 0 0 7 0 0 0 0 0 2 4 13
18 c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\AppDelegate.swift Swift 0 0 0 0 14 0 0 0 0 0 0 2 16
19 c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Assets.xcassets\AppIcon.appiconset\Contents.json JSON 0 0 0 122 0 0 0 0 0 0 0 1 123
20 c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Assets.xcassets\LaunchImage.imageset\Contents.json JSON 0 0 0 23 0 0 0 0 0 0 0 1 24
21 c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Assets.xcassets\LaunchImage.imageset\README.md Markdown 0 3 0 0 0 0 0 0 0 0 0 2 5
22 c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Base.lproj\LaunchScreen.storyboard XML 0 0 0 0 0 0 36 0 0 0 1 1 38
23 c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Base.lproj\Main.storyboard XML 0 0 0 0 0 0 25 0 0 0 1 1 27
24 c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Runner-Bridging-Header.h C++ 0 0 0 0 0 1 0 0 0 0 0 1 2
25 c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\auth\auth_bloc.dart Dart 0 0 129 0 0 0 0 0 0 0 1 20 150
26 c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\auth\auth_event.dart Dart 0 0 40 0 0 0 0 0 0 0 0 15 55
27 c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\auth\auth_state.dart Dart 0 0 28 0 0 0 0 0 0 0 0 14 42
28 c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\theme\theme_bloc.dart Dart 0 0 40 0 0 0 0 0 0 0 1 5 46
29 c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\theme\theme_event.dart Dart 0 0 14 0 0 0 0 0 0 0 0 6 20
30 c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\theme\theme_state.dart Dart 0 0 16 0 0 0 0 0 0 0 0 5 21
31 c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\trip\trip_bloc.dart Dart 0 0 103 0 0 0 0 0 0 0 1 14 118
32 c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\trip\trip_event.dart Dart 0 0 51 0 0 0 0 0 0 0 0 20 71
33 c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\trip\trip_state.dart Dart 0 0 27 0 0 0 0 0 0 0 0 13 40
34 c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\user\user_bloc.dart Dart 0 0 0 0 0 0 0 0 0 0 0 1 1
35 c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\user\user_event.dart Dart 0 0 0 0 0 0 0 0 0 0 0 1 1
36 c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\user\user_state.dart Dart 0 0 0 0 0 0 0 0 0 0 0 1 1
37 c:\Users\dayro\Documents\coding\travel_mate\lib\components\count\count_content.dart Dart 0 0 25 0 0 0 0 0 0 0 0 3 28
38 c:\Users\dayro\Documents\coding\travel_mate\lib\components\group\group_content.dart Dart 0 0 115 0 0 0 0 0 0 0 2 12 129
39 c:\Users\dayro\Documents\coding\travel_mate\lib\components\home\create_trip_content.dart Dart 0 0 481 0 0 0 0 0 0 0 21 63 565
40 c:\Users\dayro\Documents\coding\travel_mate\lib\components\home\home_content.dart Dart 0 0 366 0 0 0 0 0 0 0 12 30 408
41 c:\Users\dayro\Documents\coding\travel_mate\lib\components\home\show_trip_details_content.dart Dart 0 0 106 0 0 0 0 0 0 0 2 4 112
42 c:\Users\dayro\Documents\coding\travel_mate\lib\components\map\map_content.dart Dart 0 0 100 0 0 0 0 0 0 0 4 11 115
43 c:\Users\dayro\Documents\coding\travel_mate\lib\components\profile\profile_content.dart Dart 0 0 328 0 0 0 0 0 0 0 6 29 363
44 c:\Users\dayro\Documents\coding\travel_mate\lib\components\settings\settings_content.dart Dart 0 0 60 0 0 0 0 0 0 0 2 10 72
45 c:\Users\dayro\Documents\coding\travel_mate\lib\components\settings\settings_theme_content.dart Dart 0 0 123 0 0 0 0 0 0 0 4 10 137
46 c:\Users\dayro\Documents\coding\travel_mate\lib\data\data_sources\firestore_data_source.dart Dart 0 0 0 0 0 0 0 0 0 0 0 1 1
47 c:\Users\dayro\Documents\coding\travel_mate\lib\data\data_sources\local_data_source.dart Dart 0 0 0 0 0 0 0 0 0 0 0 1 1
48 c:\Users\dayro\Documents\coding\travel_mate\lib\data\models\group.dart Dart 0 0 23 0 0 0 0 0 0 0 0 3 26
49 c:\Users\dayro\Documents\coding\travel_mate\lib\data\models\message.dart Dart 0 0 14 0 0 0 0 0 0 0 0 1 15
50 c:\Users\dayro\Documents\coding\travel_mate\lib\data\models\trip.dart Dart 0 0 176 0 0 0 0 0 0 0 16 24 216
51 c:\Users\dayro\Documents\coding\travel_mate\lib\data\models\user.dart Dart 0 0 61 0 0 0 0 0 0 0 6 13 80
52 c:\Users\dayro\Documents\coding\travel_mate\lib\firebase_options.dart Dart 0 0 60 0 0 0 0 0 0 0 12 5 77
53 c:\Users\dayro\Documents\coding\travel_mate\lib\main.dart Dart 0 0 89 0 0 0 0 0 0 0 0 5 94
54 c:\Users\dayro\Documents\coding\travel_mate\lib\pages\home.dart Dart 0 0 147 0 0 0 0 0 0 0 6 13 166
55 c:\Users\dayro\Documents\coding\travel_mate\lib\pages\login.dart Dart 0 0 285 0 0 0 0 0 0 0 9 28 322
56 c:\Users\dayro\Documents\coding\travel_mate\lib\pages\resetpswd.dart Dart 0 0 92 0 0 0 0 0 0 0 2 13 107
57 c:\Users\dayro\Documents\coding\travel_mate\lib\pages\signup.dart Dart 0 0 256 0 0 0 0 0 0 0 7 20 283
58 c:\Users\dayro\Documents\coding\travel_mate\lib\providers\theme_provider.dart Dart 0 0 41 0 0 0 0 0 0 0 1 9 51
59 c:\Users\dayro\Documents\coding\travel_mate\lib\providers\user_provider.dart Dart 0 0 94 0 0 0 0 0 0 0 9 18 121
60 c:\Users\dayro\Documents\coding\travel_mate\lib\repositories\auth_repository.dart Dart 0 0 115 0 0 0 0 0 0 0 11 22 148
61 c:\Users\dayro\Documents\coding\travel_mate\lib\repositories\trip_repository.dart Dart 0 0 92 0 0 0 0 0 0 0 9 12 113
62 c:\Users\dayro\Documents\coding\travel_mate\lib\repositories\user_repository.dart Dart 0 0 77 0 0 0 0 0 0 0 7 11 95
63 c:\Users\dayro\Documents\coding\travel_mate\lib\services\auth_service.dart Dart 0 0 84 0 0 0 0 0 0 0 6 18 108
64 c:\Users\dayro\Documents\coding\travel_mate\lib\services\group_service.dart Dart 0 0 53 0 0 0 0 0 0 0 1 6 60
65 c:\Users\dayro\Documents\coding\travel_mate\lib\services\message_service.dart Dart 0 0 0 0 0 0 0 0 0 0 0 1 1
66 c:\Users\dayro\Documents\coding\travel_mate\lib\services\trip_service.dart Dart 0 0 209 0 0 0 0 0 0 0 21 39 269
67 c:\Users\dayro\Documents\coding\travel_mate\pubspec.yaml YAML 31 0 0 0 0 0 0 0 0 0 58 14 103
68 c:\Users\dayro\Documents\coding\travel_mate\test\widget_test.dart Dart 0 0 14 0 0 0 0 0 0 0 10 7 31
69 Total - 34 48 4134 200 21 1 133 32 8 548 328 739 6226

File diff suppressed because one or more lines are too long

View File

@@ -1,81 +0,0 @@
# Summary
Date : 2025-10-14 11:10:48
Directory c:\\Users\\dayro\\Documents\\coding\\travel_mate
Total : 67 files, 5159 codes, 328 comments, 739 blanks, all 6226 lines
Summary / [Details](details.md) / [Diff Summary](diff.md) / [Diff Details](diff-details.md)
## Languages
| language | files | code | comment | blank | total |
| :--- | ---: | ---: | ---: | ---: | ---: |
| Dart | 43 | 4,134 | 189 | 557 | 4,880 |
| HTML | 1 | 548 | 2 | 114 | 664 |
| JSON | 4 | 200 | 0 | 2 | 202 |
| XML | 9 | 133 | 53 | 11 | 197 |
| Markdown | 2 | 48 | 0 | 18 | 66 |
| YAML | 2 | 34 | 80 | 18 | 132 |
| Ruby | 1 | 32 | 2 | 10 | 44 |
| Swift | 2 | 21 | 2 | 6 | 29 |
| Properties | 2 | 8 | 0 | 2 | 10 |
| C++ | 1 | 1 | 0 | 1 | 2 |
## Directories
| path | files | code | comment | blank | total |
| :--- | ---: | ---: | ---: | ---: | ---: |
| . | 67 | 5,159 | 328 | 739 | 6,226 |
| . (Files) | 4 | 80 | 80 | 34 | 194 |
| android | 11 | 682 | 53 | 125 | 860 |
| android (Files) | 1 | 3 | 0 | 1 | 4 |
| android\\app | 8 | 126 | 51 | 9 | 186 |
| android\\app (Files) | 1 | 54 | 0 | 0 | 54 |
| android\\app\\src | 7 | 72 | 51 | 9 | 132 |
| android\\app\\src\\debug | 1 | 3 | 4 | 1 | 8 |
| android\\app\\src\\main | 5 | 66 | 43 | 7 | 116 |
| android\\app\\src\\main (Files) | 1 | 40 | 11 | 1 | 52 |
| android\\app\\src\\main\\res | 4 | 26 | 32 | 6 | 64 |
| android\\app\\src\\main\\res\\drawable | 1 | 4 | 7 | 2 | 13 |
| android\\app\\src\\main\\res\\drawable-v21 | 1 | 4 | 7 | 2 | 13 |
| android\\app\\src\\main\\res\\values | 1 | 9 | 9 | 1 | 19 |
| android\\app\\src\\main\\res\\values-night | 1 | 9 | 9 | 1 | 19 |
| android\\app\\src\\profile | 1 | 3 | 4 | 1 | 8 |
| android\\build | 1 | 548 | 2 | 114 | 664 |
| android\\build\\reports | 1 | 548 | 2 | 114 | 664 |
| android\\build\\reports\\problems | 1 | 548 | 2 | 114 | 664 |
| android\\gradle | 1 | 5 | 0 | 1 | 6 |
| android\\gradle\\wrapper | 1 | 5 | 0 | 1 | 6 |
| ios | 9 | 263 | 6 | 23 | 292 |
| ios (Files) | 1 | 32 | 2 | 10 | 44 |
| ios\\Runner | 7 | 224 | 2 | 9 | 235 |
| ios\\Runner (Files) | 2 | 15 | 0 | 3 | 18 |
| ios\\RunnerTests | 1 | 7 | 2 | 4 | 13 |
| ios\\Runner\\Assets.xcassets | 3 | 148 | 0 | 4 | 152 |
| ios\\Runner\\Assets.xcassets\\AppIcon.appiconset | 1 | 122 | 0 | 1 | 123 |
| ios\\Runner\\Assets.xcassets\\LaunchImage.imageset | 2 | 26 | 0 | 3 | 29 |
| ios\\Runner\\Base.lproj | 2 | 61 | 2 | 2 | 65 |
| lib | 42 | 4,120 | 179 | 550 | 4,849 |
| lib (Files) | 2 | 149 | 12 | 10 | 171 |
| lib\\blocs | 12 | 448 | 3 | 115 | 566 |
| lib\\blocs\\auth | 3 | 197 | 1 | 49 | 247 |
| lib\\blocs\\theme | 3 | 70 | 1 | 16 | 87 |
| lib\\blocs\\trip | 3 | 181 | 1 | 47 | 229 |
| lib\\blocs\\user | 3 | 0 | 0 | 3 | 3 |
| lib\\components | 9 | 1,704 | 53 | 172 | 1,929 |
| lib\\components\\count | 1 | 25 | 0 | 3 | 28 |
| lib\\components\\group | 1 | 115 | 2 | 12 | 129 |
| lib\\components\\home | 3 | 953 | 35 | 97 | 1,085 |
| lib\\components\\map | 1 | 100 | 4 | 11 | 115 |
| lib\\components\\profile | 1 | 328 | 6 | 29 | 363 |
| lib\\components\\settings | 2 | 183 | 6 | 20 | 209 |
| lib\\data | 6 | 274 | 22 | 43 | 339 |
| lib\\data\\data_sources | 2 | 0 | 0 | 2 | 2 |
| lib\\data\\models | 4 | 274 | 22 | 41 | 337 |
| lib\\pages | 4 | 780 | 24 | 74 | 878 |
| lib\\providers | 2 | 135 | 10 | 27 | 172 |
| lib\\repositories | 3 | 284 | 27 | 45 | 356 |
| lib\\services | 4 | 346 | 28 | 64 | 438 |
| test | 1 | 14 | 10 | 7 | 31 |
Summary / [Details](details.md) / [Diff Summary](diff.md) / [Diff Details](diff-details.md)

View File

@@ -1,151 +0,0 @@
Date : 2025-10-14 11:10:48
Directory : c:\Users\dayro\Documents\coding\travel_mate
Total : 67 files, 5159 codes, 328 comments, 739 blanks, all 6226 lines
Languages
+------------+------------+------------+------------+------------+------------+
| language | files | code | comment | blank | total |
+------------+------------+------------+------------+------------+------------+
| Dart | 43 | 4,134 | 189 | 557 | 4,880 |
| HTML | 1 | 548 | 2 | 114 | 664 |
| JSON | 4 | 200 | 0 | 2 | 202 |
| XML | 9 | 133 | 53 | 11 | 197 |
| Markdown | 2 | 48 | 0 | 18 | 66 |
| YAML | 2 | 34 | 80 | 18 | 132 |
| Ruby | 1 | 32 | 2 | 10 | 44 |
| Swift | 2 | 21 | 2 | 6 | 29 |
| Properties | 2 | 8 | 0 | 2 | 10 |
| C++ | 1 | 1 | 0 | 1 | 2 |
+------------+------------+------------+------------+------------+------------+
Directories
+-----------------------------------------------------------------------------------------------------------+------------+------------+------------+------------+------------+
| path | files | code | comment | blank | total |
+-----------------------------------------------------------------------------------------------------------+------------+------------+------------+------------+------------+
| . | 67 | 5,159 | 328 | 739 | 6,226 |
| . (Files) | 4 | 80 | 80 | 34 | 194 |
| android | 11 | 682 | 53 | 125 | 860 |
| android (Files) | 1 | 3 | 0 | 1 | 4 |
| android\app | 8 | 126 | 51 | 9 | 186 |
| android\app (Files) | 1 | 54 | 0 | 0 | 54 |
| android\app\src | 7 | 72 | 51 | 9 | 132 |
| android\app\src\debug | 1 | 3 | 4 | 1 | 8 |
| android\app\src\main | 5 | 66 | 43 | 7 | 116 |
| android\app\src\main (Files) | 1 | 40 | 11 | 1 | 52 |
| android\app\src\main\res | 4 | 26 | 32 | 6 | 64 |
| android\app\src\main\res\drawable | 1 | 4 | 7 | 2 | 13 |
| android\app\src\main\res\drawable-v21 | 1 | 4 | 7 | 2 | 13 |
| android\app\src\main\res\values | 1 | 9 | 9 | 1 | 19 |
| android\app\src\main\res\values-night | 1 | 9 | 9 | 1 | 19 |
| android\app\src\profile | 1 | 3 | 4 | 1 | 8 |
| android\build | 1 | 548 | 2 | 114 | 664 |
| android\build\reports | 1 | 548 | 2 | 114 | 664 |
| android\build\reports\problems | 1 | 548 | 2 | 114 | 664 |
| android\gradle | 1 | 5 | 0 | 1 | 6 |
| android\gradle\wrapper | 1 | 5 | 0 | 1 | 6 |
| ios | 9 | 263 | 6 | 23 | 292 |
| ios (Files) | 1 | 32 | 2 | 10 | 44 |
| ios\Runner | 7 | 224 | 2 | 9 | 235 |
| ios\Runner (Files) | 2 | 15 | 0 | 3 | 18 |
| ios\RunnerTests | 1 | 7 | 2 | 4 | 13 |
| ios\Runner\Assets.xcassets | 3 | 148 | 0 | 4 | 152 |
| ios\Runner\Assets.xcassets\AppIcon.appiconset | 1 | 122 | 0 | 1 | 123 |
| ios\Runner\Assets.xcassets\LaunchImage.imageset | 2 | 26 | 0 | 3 | 29 |
| ios\Runner\Base.lproj | 2 | 61 | 2 | 2 | 65 |
| lib | 42 | 4,120 | 179 | 550 | 4,849 |
| lib (Files) | 2 | 149 | 12 | 10 | 171 |
| lib\blocs | 12 | 448 | 3 | 115 | 566 |
| lib\blocs\auth | 3 | 197 | 1 | 49 | 247 |
| lib\blocs\theme | 3 | 70 | 1 | 16 | 87 |
| lib\blocs\trip | 3 | 181 | 1 | 47 | 229 |
| lib\blocs\user | 3 | 0 | 0 | 3 | 3 |
| lib\components | 9 | 1,704 | 53 | 172 | 1,929 |
| lib\components\count | 1 | 25 | 0 | 3 | 28 |
| lib\components\group | 1 | 115 | 2 | 12 | 129 |
| lib\components\home | 3 | 953 | 35 | 97 | 1,085 |
| lib\components\map | 1 | 100 | 4 | 11 | 115 |
| lib\components\profile | 1 | 328 | 6 | 29 | 363 |
| lib\components\settings | 2 | 183 | 6 | 20 | 209 |
| lib\data | 6 | 274 | 22 | 43 | 339 |
| lib\data\data_sources | 2 | 0 | 0 | 2 | 2 |
| lib\data\models | 4 | 274 | 22 | 41 | 337 |
| lib\pages | 4 | 780 | 24 | 74 | 878 |
| lib\providers | 2 | 135 | 10 | 27 | 172 |
| lib\repositories | 3 | 284 | 27 | 45 | 356 |
| lib\services | 4 | 346 | 28 | 64 | 438 |
| test | 1 | 14 | 10 | 7 | 31 |
+-----------------------------------------------------------------------------------------------------------+------------+------------+------------+------------+------------+
Files
+-----------------------------------------------------------------------------------------------------------+------------+------------+------------+------------+------------+
| filename | language | code | comment | blank | total |
+-----------------------------------------------------------------------------------------------------------+------------+------------+------------+------------+------------+
| c:\Users\dayro\Documents\coding\travel_mate\README.md | Markdown | 45 | 0 | 16 | 61 |
| c:\Users\dayro\Documents\coding\travel_mate\analysis_options.yaml | YAML | 3 | 22 | 4 | 29 |
| c:\Users\dayro\Documents\coding\travel_mate\android\app\google-services.json | JSON | 54 | 0 | 0 | 54 |
| c:\Users\dayro\Documents\coding\travel_mate\android\app\src\debug\AndroidManifest.xml | XML | 3 | 4 | 1 | 8 |
| c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\AndroidManifest.xml | XML | 40 | 11 | 1 | 52 |
| c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\res\drawable-v21\launch_background.xml | XML | 4 | 7 | 2 | 13 |
| c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\res\drawable\launch_background.xml | XML | 4 | 7 | 2 | 13 |
| c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\res\values-night\styles.xml | XML | 9 | 9 | 1 | 19 |
| c:\Users\dayro\Documents\coding\travel_mate\android\app\src\main\res\values\styles.xml | XML | 9 | 9 | 1 | 19 |
| c:\Users\dayro\Documents\coding\travel_mate\android\app\src\profile\AndroidManifest.xml | XML | 3 | 4 | 1 | 8 |
| c:\Users\dayro\Documents\coding\travel_mate\android\build\reports\problems\problems-report.html | HTML | 548 | 2 | 114 | 664 |
| c:\Users\dayro\Documents\coding\travel_mate\android\gradle.properties | Properties | 3 | 0 | 1 | 4 |
| c:\Users\dayro\Documents\coding\travel_mate\android\gradle\wrapper\gradle-wrapper.properties | Properties | 5 | 0 | 1 | 6 |
| c:\Users\dayro\Documents\coding\travel_mate\firebase.json | JSON | 1 | 0 | 0 | 1 |
| c:\Users\dayro\Documents\coding\travel_mate\ios\Podfile | Ruby | 32 | 2 | 10 | 44 |
| c:\Users\dayro\Documents\coding\travel_mate\ios\RunnerTests\RunnerTests.swift | Swift | 7 | 2 | 4 | 13 |
| c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\AppDelegate.swift | Swift | 14 | 0 | 2 | 16 |
| c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Assets.xcassets\AppIcon.appiconset\Contents.json | JSON | 122 | 0 | 1 | 123 |
| c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Assets.xcassets\LaunchImage.imageset\Contents.json | JSON | 23 | 0 | 1 | 24 |
| c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Assets.xcassets\LaunchImage.imageset\README.md | Markdown | 3 | 0 | 2 | 5 |
| c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Base.lproj\LaunchScreen.storyboard | XML | 36 | 1 | 1 | 38 |
| c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Base.lproj\Main.storyboard | XML | 25 | 1 | 1 | 27 |
| c:\Users\dayro\Documents\coding\travel_mate\ios\Runner\Runner-Bridging-Header.h | C++ | 1 | 0 | 1 | 2 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\auth\auth_bloc.dart | Dart | 129 | 1 | 20 | 150 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\auth\auth_event.dart | Dart | 40 | 0 | 15 | 55 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\auth\auth_state.dart | Dart | 28 | 0 | 14 | 42 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\theme\theme_bloc.dart | Dart | 40 | 1 | 5 | 46 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\theme\theme_event.dart | Dart | 14 | 0 | 6 | 20 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\theme\theme_state.dart | Dart | 16 | 0 | 5 | 21 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\trip\trip_bloc.dart | Dart | 103 | 1 | 14 | 118 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\trip\trip_event.dart | Dart | 51 | 0 | 20 | 71 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\trip\trip_state.dart | Dart | 27 | 0 | 13 | 40 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\user\user_bloc.dart | Dart | 0 | 0 | 1 | 1 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\user\user_event.dart | Dart | 0 | 0 | 1 | 1 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\blocs\user\user_state.dart | Dart | 0 | 0 | 1 | 1 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\components\count\count_content.dart | Dart | 25 | 0 | 3 | 28 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\components\group\group_content.dart | Dart | 115 | 2 | 12 | 129 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\components\home\create_trip_content.dart | Dart | 481 | 21 | 63 | 565 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\components\home\home_content.dart | Dart | 366 | 12 | 30 | 408 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\components\home\show_trip_details_content.dart | Dart | 106 | 2 | 4 | 112 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\components\map\map_content.dart | Dart | 100 | 4 | 11 | 115 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\components\profile\profile_content.dart | Dart | 328 | 6 | 29 | 363 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\components\settings\settings_content.dart | Dart | 60 | 2 | 10 | 72 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\components\settings\settings_theme_content.dart | Dart | 123 | 4 | 10 | 137 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\data\data_sources\firestore_data_source.dart | Dart | 0 | 0 | 1 | 1 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\data\data_sources\local_data_source.dart | Dart | 0 | 0 | 1 | 1 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\data\models\group.dart | Dart | 23 | 0 | 3 | 26 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\data\models\message.dart | Dart | 14 | 0 | 1 | 15 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\data\models\trip.dart | Dart | 176 | 16 | 24 | 216 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\data\models\user.dart | Dart | 61 | 6 | 13 | 80 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\firebase_options.dart | Dart | 60 | 12 | 5 | 77 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\main.dart | Dart | 89 | 0 | 5 | 94 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\pages\home.dart | Dart | 147 | 6 | 13 | 166 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\pages\login.dart | Dart | 285 | 9 | 28 | 322 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\pages\resetpswd.dart | Dart | 92 | 2 | 13 | 107 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\pages\signup.dart | Dart | 256 | 7 | 20 | 283 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\providers\theme_provider.dart | Dart | 41 | 1 | 9 | 51 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\providers\user_provider.dart | Dart | 94 | 9 | 18 | 121 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\repositories\auth_repository.dart | Dart | 115 | 11 | 22 | 148 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\repositories\trip_repository.dart | Dart | 92 | 9 | 12 | 113 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\repositories\user_repository.dart | Dart | 77 | 7 | 11 | 95 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\services\auth_service.dart | Dart | 84 | 6 | 18 | 108 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\services\group_service.dart | Dart | 53 | 1 | 6 | 60 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\services\message_service.dart | Dart | 0 | 0 | 1 | 1 |
| c:\Users\dayro\Documents\coding\travel_mate\lib\services\trip_service.dart | Dart | 209 | 21 | 39 | 269 |
| c:\Users\dayro\Documents\coding\travel_mate\pubspec.yaml | YAML | 31 | 58 | 14 | 103 |
| c:\Users\dayro\Documents\coding\travel_mate\test\widget_test.dart | Dart | 14 | 10 | 7 | 31 |
| Total | | 5,159 | 328 | 739 | 6,226 |
+-----------------------------------------------------------------------------------------------------------+------------+------------+------------+------------+------------+

5
.firebaserc Normal file
View File

@@ -0,0 +1,5 @@
{
"projects": {
"default": "travelmate-a47f5"
}
}

View File

@@ -0,0 +1,226 @@
name: Deploy TravelMate (Full Mobile)
on:
push:
branches:
- release
jobs:
# --- JOB 1 : ANDROID (Génération APK) ---
deploy-android:
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Configuration Flutter & Secrets
run: |
flutter pub get
echo "${{ secrets.ENV_FILE }}" > .env
printf '%s' '${{ secrets.FIREBASE_CREDENTIALS }}' > ./android/firebase_credentials.json
- name: Build & Deploy Android
working-directory: ./android
env:
ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
RAW_PROPERTIES: ${{ secrets.ANDROID_KEY_PROPERTIES }}
FIREBASE_ANDROID_APP_ID: ${{ secrets.FIREBASE_ANDROID_APP_ID }}
run: |
# 1. Keystore
echo "$ANDROID_KEYSTORE_BASE64" | base64 -D > keystore.jks
echo "$RAW_PROPERTIES" > temp_props.txt
echo "storePassword=$(grep 'storePassword' temp_props.txt | cut -d'=' -f2 | tr -d '\r')" > key.properties
echo "keyPassword=$(grep 'keyPassword' temp_props.txt | cut -d'=' -f2 | tr -d '\r')" >> key.properties
echo "keyAlias=$(grep 'keyAlias' temp_props.txt | cut -d'=' -f2 | tr -d '\r')" >> key.properties
echo "storeFile=$(pwd)/keystore.jks" >> key.properties
# 2. Gemfile (Correctifs Ruby 3.4 inclus)
echo "source 'https://rubygems.org'" > Gemfile
echo "gem 'fastlane', '>= 2.230.0'" >> Gemfile
echo "gem 'fastlane-plugin-firebase_app_distribution'" >> Gemfile
for g in abbrev ostruct mutex_m base64 csv bigdecimal drb nkf reline logger; do echo "gem '$g'" >> Gemfile; done
gem install bundler -v 2.7.2 --no-document
bundle _2.7.2_ update
# 3. Build & Envoi
cd .. && flutter build apk --release && cd android
bundle _2.7.2_ exec fastlane run firebase_app_distribution \
app:"$FIREBASE_ANDROID_APP_ID" \
android_artifact_path:"../build/app/outputs/flutter-apk/app-release.apk" \
service_credentials_file:"firebase_credentials.json"
# --- JOB 2 : IOS (Génération IPA) ---
deploy-ios:
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Dépendances iOS & Secrets
run: |
flutter pub get
echo "${{ secrets.ENV_FILE }}" > .env
printf '%s' '${{ secrets.FIREBASE_CREDENTIALS }}' > ./ios/firebase_credentials.json
cd ios && (pod install --repo-update || pod update)
- name: Préparer le Code Signing
env:
P12_BASE: ${{ secrets.IOS_P12_BASE64 }}
P12_PASS: ${{ secrets.IOS_P12_PASSWORD }}
PROV_BASE: ${{ secrets.IOS_PROVISION_BASE64 }}
TEAM_ID: ${{ secrets.IOS_TEAM_ID }}
run: |
# Créer et configurer le keychain
security delete-keychain build.keychain || true
security create-keychain -p "" build.keychain
security unlock-keychain -p "" build.keychain
security list-keychains -d user -s build.keychain $(security list-keychains -d user | xargs)
security set-keychain-settings -lut 21600 build.keychain
# Importer le certificat
echo "$P12_BASE" | base64 -D -o cert.p12
security import cert.p12 -k build.keychain -P "$P12_PASS" -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple: -s -k "" build.keychain
# Installer le profil de provisioning
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
PROFILE_PATH=~/Library/MobileDevice/Provisioning\ Profiles/distribution.mobileprovision
echo "$PROV_BASE" | base64 -D -o "$PROFILE_PATH"
# Extraire l'UUID du profil
PROFILE_UUID=$(/usr/libexec/PlistBuddy -c "Print UUID" /dev/stdin <<< $(/usr/bin/security cms -D -i "$PROFILE_PATH"))
echo "Profile UUID: $PROFILE_UUID"
# Copier avec l'UUID correct
cp "$PROFILE_PATH" ~/Library/MobileDevice/Provisioning\ Profiles/$PROFILE_UUID.mobileprovision
- name: Configurer le projet Xcode
env:
TEAM_ID: ${{ secrets.IOS_TEAM_ID }}
BUNDLE_ID: ${{ secrets.IOS_BUNDLE_ID }}
run: |
cd ios
# Extraire le nom du profil de provisioning
PROV_NAME=$(/usr/libexec/PlistBuddy -c "Print Name" /dev/stdin <<< $(/usr/bin/security cms -D -i ~/Library/MobileDevice/Provisioning\ Profiles/distribution.mobileprovision))
echo "📝 Provisioning Profile Name: $PROV_NAME"
# Obtenir l'UUID du profil
PROFILE_UUID=$(/usr/libexec/PlistBuddy -c "Print UUID" /dev/stdin <<< $(/usr/bin/security cms -D -i ~/Library/MobileDevice/Provisioning\ Profiles/distribution.mobileprovision))
echo "🔑 Profile UUID: $PROFILE_UUID"
# Sauvegarder les variables pour la prochaine étape
echo "$PROV_NAME" > /tmp/prov_name.txt
echo "$TEAM_ID" > /tmp/team_id.txt
echo "$BUNDLE_ID" > /tmp/bundle_id.txt
echo "✅ Configuration des paramètres de signing prête"
- name: Créer exportOptions.plist
env:
TEAM_ID: ${{ secrets.IOS_TEAM_ID }}
BUNDLE_ID: ${{ secrets.IOS_BUNDLE_ID }}
run: |
# Extraire le nom du profil
PROV_NAME=$(/usr/libexec/PlistBuddy -c "Print Name" /dev/stdin <<< $(/usr/bin/security cms -D -i ~/Library/MobileDevice/Provisioning\ Profiles/distribution.mobileprovision))
cat > ios/exportOptions.plist <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>ad-hoc</string>
<key>teamID</key>
<string>$TEAM_ID</string>
<key>signingStyle</key>
<string>manual</string>
<key>provisioningProfiles</key>
<dict>
<key>$BUNDLE_ID</key>
<string>$PROV_NAME</string>
</dict>
</dict>
</plist>
EOF
- name: Build IPA avec Flutter
run: |
# Récupérer les variables sauvegardées
PROV_NAME=$(cat /tmp/prov_name.txt)
TEAM_ID=$(cat /tmp/team_id.txt)
BUNDLE_ID=$(cat /tmp/bundle_id.txt)
echo "📝 Provisioning Profile: $PROV_NAME"
echo "🔑 Team ID: $TEAM_ID"
echo "📦 Bundle ID: $BUNDLE_ID"
# Clean
flutter clean
flutter pub get
echo "🔨 Build de l'IPA avec Flutter..."
# Flutter build ipa gère automatiquement le signing des Pods
# On utilise SEULEMENT --export-options-plist (pas --export-method)
flutter build ipa \
--release \
--export-options-plist=ios/exportOptions.plist
echo "✅ Build terminé"
echo "📂 Recherche de l'IPA..."
# L'IPA devrait être dans build/ios/ipa/
find build/ios -name "*.ipa" -type f
IPA_FILE=$(find build/ios/ipa -name "*.ipa" | head -n 1)
if [ -z "$IPA_FILE" ]; then
echo "❌ ERREUR: Aucun fichier IPA trouvé !"
echo "📂 Contenu de build/ios/ :"
ls -R build/ios/
exit 1
fi
echo "✅ IPA trouvée : $IPA_FILE"
echo "📊 Taille : $(du -h "$IPA_FILE" | cut -f1)"
- name: Vérification et Upload Firebase
env:
FIREBASE_IOS_APP_ID: ${{ secrets.FIREBASE_IOS_APP_ID }}
run: |
cd ios
# Configuration Fastlane
echo "source 'https://rubygems.org'" > Gemfile
echo "gem 'fastlane', '>= 2.230.0'" >> Gemfile
echo "gem 'fastlane-plugin-firebase_app_distribution'" >> Gemfile
for g in abbrev ostruct mutex_m base64 csv bigdecimal drb nkf reline logger; do echo "gem '$g'" >> Gemfile; done
gem install bundler -v 2.7.2 --no-document
bundle _2.7.2_ update
# Recherche de l'IPA
IPA_FILE=$(find ../build/ios/ipa -name "*.ipa" | head -n 1)
if [ -z "$IPA_FILE" ]; then
echo "❌ ERREUR : Aucun fichier IPA trouvé !"
echo "📂 Structure complète du dossier build :"
ls -R ../build/
exit 1
fi
echo "✅ IPA trouvée : $IPA_FILE"
echo "📊 Taille : $(du -h "$IPA_FILE" | cut -f1)"
# Upload vers Firebase
bundle _2.7.2_ exec fastlane run firebase_app_distribution \
app:"$FIREBASE_IOS_APP_ID" \
ipa_path:"$IPA_FILE" \
service_credentials_file:"firebase_credentials.json"
- name: Nettoyage Final
if: always()
run: |
security list-keychains -d user -s login.keychain
security delete-keychain build.keychain || true

10
.gitignore vendored
View File

@@ -44,7 +44,15 @@ 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
/functions/node_modules
.idea
.vscode
.VSCodeCounter

View File

@@ -56,3 +56,7 @@ Travel Mate est une application mobile conçue pour simplifier l'organisation de
- **Google Places API** - Recherche de lieux et points d'intérêt - **Google Places API** - Recherche de lieux et points d'intérêt
- **Google Maps API** - Cartes et navigation - **Google Maps API** - Cartes et navigation
- **Google Directions API** - Calcul d'itinéraires - **Google Directions API** - Calcul d'itinéraires
## 🚀 CI/CD & Déploiement
Les versions de test interne Android et IOS sont automatiquement distribuées via **Firebase App Distribution**.

6
android/Gemfile Normal file
View File

@@ -0,0 +1,6 @@
source "https://rubygems.org"
gem "fastlane"
plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
eval_gemfile(plugins_path) if File.exist?(plugins_path)

View File

@@ -1,21 +1,28 @@
import java.util.Properties
import java.io.FileInputStream
plugins { plugins {
id("com.android.application") id("com.android.application")
// START: FlutterFire Configuration
id("com.google.gms.google-services") id("com.google.gms.google-services")
// END: FlutterFire Configuration
id("kotlin-android") id("kotlin-android")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin") id("dev.flutter.flutter-gradle-plugin")
} }
val keystoreProperties = Properties()
val keystorePropertiesFile = rootProject.file("key.properties")
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}
android { android {
namespace = "com.example.travel_mate" namespace = "be.devdayronvl.travel_mate"
compileSdk = flutter.compileSdkVersion compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion ndkVersion = flutter.ndkVersion
compileOptions { compileOptions {
sourceCompatibility = JavaVersion.VERSION_17 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17
isCoreLibraryDesugaringEnabled = true
} }
kotlinOptions { kotlinOptions {
@@ -23,23 +30,37 @@ android {
} }
defaultConfig { defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId = "be.devdayronvl.travel_mate"
applicationId = "com.example.travel_mate"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode versionCode = flutter.versionCode
versionName = flutter.versionName versionName = flutter.versionName
} }
buildTypes { signingConfigs {
release { create("release") {
// TODO: Add your own signing config for the release build. keyAlias = keystoreProperties["keyAlias"] as String?
// Signing with the debug keys for now, so `flutter run --release` works. keyPassword = keystoreProperties["keyPassword"] as String?
signingConfig = signingConfigs.getByName("debug") storeFile = if (keystoreProperties["storeFile"] != null) {
rootProject.file(keystoreProperties["storeFile"] as String)
} else {
null
}
storePassword = keystoreProperties["storePassword"] as String?
} }
} }
buildTypes {
release {
// Applique la configuration de signature définie au-dessus
signingConfig = signingConfigs.getByName("release")
}
}
}
dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4")
} }
flutter { flutter {

View File

@@ -5,6 +5,42 @@
"storage_bucket": "travelmate-a47f5.firebasestorage.app" "storage_bucket": "travelmate-a47f5.firebasestorage.app"
}, },
"client": [ "client": [
{
"client_info": {
"mobilesdk_app_id": "1:521527250907:android:56c632e98c7826347da1fe",
"android_client_info": {
"package_name": "be.devdayronvl.travel_mate"
}
},
"oauth_client": [
{
"client_id": "521527250907-j0kt1hc8hc7qc2kedp4akehau754cn5d.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAON_ol0Jr34tKbETvdDK9JCQdKNawxBeQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "521527250907-j0kt1hc8hc7qc2kedp4akehau754cn5d.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "521527250907-196i04qgm4talrosgi0ne0q8en90hkkh.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "be.devdayronvl.TravelMate"
}
}
]
}
}
},
{ {
"client_info": { "client_info": {
"mobilesdk_app_id": "1:521527250907:android:be3db7fc84f053ec7da1fe", "mobilesdk_app_id": "1:521527250907:android:be3db7fc84f053ec7da1fe",
@@ -13,6 +49,22 @@
} }
}, },
"oauth_client": [ "oauth_client": [
{
"client_id": "521527250907-19lrclc10eb0p8li1qutepctfqdohn0b.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.example.travel_mate",
"certificate_hash": "2374761dc92a30812608c072638510002041eca8"
}
},
{
"client_id": "521527250907-5v8l011nod30a6c52nkmk69d00h0ma0q.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.example.travel_mate",
"certificate_hash": "c98141ab89d42b16c273e611054e7c87aa773d83"
}
},
{ {
"client_id": "521527250907-lqgj1lmfcsjusm2be9r6kpuanq3jvjcd.apps.googleusercontent.com", "client_id": "521527250907-lqgj1lmfcsjusm2be9r6kpuanq3jvjcd.apps.googleusercontent.com",
"client_type": 1, "client_type": 1,
@@ -39,10 +91,10 @@
"client_type": 3 "client_type": 3
}, },
{ {
"client_id": "521527250907-3i1qe2656eojs8k9hjdi573j09i9p41m.apps.googleusercontent.com", "client_id": "521527250907-196i04qgm4talrosgi0ne0q8en90hkkh.apps.googleusercontent.com",
"client_type": 2, "client_type": 2,
"ios_info": { "ios_info": {
"bundle_id": "com.example.travelMate" "bundle_id": "be.devdayronvl.TravelMate"
} }
} }
] ]

View File

@@ -13,13 +13,15 @@
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" /> <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<!-- Permissions pour écrire dans le stockage --> <!-- Permissions pour écrire dans le stockage -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<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
android:name=".MainActivity" android:name=".MainActivity"
android:screenOrientation="portrait"
android:exported="true" android:exported="true"
android:launchMode="singleTop" android:launchMode="singleTop"
android:taskAffinity="" android:taskAffinity=""
@@ -40,6 +42,20 @@
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
<!-- Apple Sign In Callback Activity -->
<activity
android:name="com.aboutyou.dart_packages.sign_in_with_apple.SignInWithAppleCallback"
android:exported="true"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="signinwithapple" />
<data android:path="/" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below. <!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data <meta-data
@@ -47,7 +63,10 @@
android:value="2" /> android:value="2" />
<meta-data <meta-data
android:name="com.google.android.geo.API_KEY" android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCAtz1_d5K0ANwxAA_T84iq7Ac_gsUs_oM"/> android:value="AIzaSyAON_ol0Jr34tKbETvdDK9JCQdKNawxBeQ"/>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="high_importance_channel" />
</application> </application>
<!-- Required to query activities that can process text, see: <!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and https://developer.android.com/training/package-visibility and
@@ -59,5 +78,23 @@
<action android:name="android.intent.action.PROCESS_TEXT"/> <action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/> <data android:mimeType="text/plain"/>
</intent> </intent>
<!-- Waze -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="waze" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" android:host="www.waze.com" />
</intent>
<!-- Google Maps -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="google.navigation" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" android:host="www.google.com" />
</intent>
</queries> </queries>
</manifest> </manifest>

View File

@@ -1,4 +1,4 @@
package com.example.travel_mate package be.devdayronvl.travel_mate
import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.android.FlutterActivity

File diff suppressed because one or more lines are too long

2
android/fastlane/Appfile Normal file
View File

@@ -0,0 +1,2 @@
json_key_file("'/Users/dayronvanleemput/Documents/Coding/clé/travelmate-a47f5-1e4759031f2d.json'") # Path to the json secret file - Follow https://docs.fastlane.tools/actions/supply/#setup to get one
package_name("be.devdayronvl.travel_mate") # e.g. com.krausefx.app

28
android/fastlane/Fastfile Normal file
View File

@@ -0,0 +1,28 @@
default_platform(:android)
platform :android do
desc "Deploy to Firebase from Mac"
lane :deploy_firebase do
# 1. Création du Keystore depuis le secret Gitea
if ENV['ANDROID_KEYSTORE_BASE64']
File.open("upload-keystore.jks", "wb") do |f|
f.write(Base64.decode64(ENV['ANDROID_KEYSTORE_BASE64']))
end
else
UI.error("Secret Keystore manquant !")
end
# 2. Build de l'App Bundle (AAB)
sh("flutter build appbundle --release")
# 3. Envoi vers Firebase App Distribution
firebase_app_distribution(
app: ENV["FIREBASE_ANDROID_APP_ID"],
service_credentials_file: "firebase_credentials.json",
groups: "testers",
android_artifact_path: "../build/app/outputs/bundle/release/app-release.aab",
release_notes: "Build depuis Mac M1/M2. Commit: #{ENV['GITHUB_SHA']}"
)
end
end

View File

@@ -0,0 +1,5 @@
# Autogenerated by fastlane
#
# Ensure this file is checked in to source control!
gem 'fastlane-plugin-firebase_app_distribution'

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

View File

@@ -1 +1,37 @@
{"flutter":{"platforms":{"android":{"default":{"projectId":"travelmate-a47f5","appId":"1:521527250907:android:be3db7fc84f053ec7da1fe","fileOutput":"android/app/google-services.json"}},"dart":{"lib/firebase_options.dart":{"projectId":"travelmate-a47f5","configurations":{"android":"1:521527250907:android:be3db7fc84f053ec7da1fe","ios":"1:521527250907:ios:64b41be39c54db1c7da1fe","windows":"1:521527250907:web:53ff98bcdb8c218f7da1fe"}}}}}} {
"flutter": {
"platforms": {
"android": {
"default": {
"projectId": "travelmate-a47f5",
"appId": "1:521527250907:android:be3db7fc84f053ec7da1fe",
"fileOutput": "android/app/google-services.json"
}
},
"dart": {
"lib/firebase_options.dart": {
"projectId": "travelmate-a47f5",
"configurations": {
"android": "1:521527250907:android:be3db7fc84f053ec7da1fe",
"ios": "1:521527250907:ios:64b41be39c54db1c7da1fe",
"windows": "1:521527250907:web:53ff98bcdb8c218f7da1fe"
}
}
}
}
},
"functions": [
{
"source": "functions",
"codebase": "default",
"disallowLegacyRuntimeConfig": true,
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log",
"*.local"
]
}
]
}

2
functions/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules/
*.local

196
functions/index.js Normal file
View File

@@ -0,0 +1,196 @@
const functions = require("firebase-functions/v1");
const admin = require("firebase-admin");
admin.initializeApp();
// Helper function to send notifications to a list of users
async function sendNotificationToUsers(userIds, title, body, excludeUserId, data = {}) {
console.log(`Starting sendNotificationToUsers. Total users: ${userIds.length}, Exclude: ${excludeUserId}`);
try {
const tokens = [];
for (const userId of userIds) {
if (userId === excludeUserId) {
console.log(`Skipping user ${userId} (sender)`);
continue;
}
const userDoc = await admin.firestore().collection("users").doc(userId).get();
if (userDoc.exists) {
const userData = userDoc.data();
if (userData.fcmToken) {
console.log(`Found token for user ${userId}`);
tokens.push(userData.fcmToken);
} else {
console.log(`No FCM token found for user ${userId}`);
}
} else {
console.log(`User document not found for ${userId}`);
}
}
// De-duplicate tokens
const uniqueTokens = [...new Set(tokens)];
console.log(`Total unique tokens to send: ${uniqueTokens.length} (from ${tokens.length} found)`);
if (uniqueTokens.length > 0) {
const message = {
notification: {
title: title,
body: body,
},
tokens: uniqueTokens,
data: {
click_action: "FLUTTER_NOTIFICATION_CLICK",
...data
},
android: {
priority: "high",
notification: {
channelId: "high_importance_channel",
}
}
};
const response = await admin.messaging().sendEachForMulticast(message);
console.log(`${response.successCount} messages were sent successfully`);
if (response.failureCount > 0) {
console.log('Failed notifications:', response.responses.filter(r => !r.success));
}
} else {
console.log("No tokens found, skipping notification send.");
}
} catch (error) {
console.error("Error sending notification:", error);
}
}
exports.onActivityCreated = functions.firestore
.document("activities/{activityId}")
.onCreate(async (snapshot, context) => {
console.log(`onActivityCreated triggered for ${context.params.activityId}`);
const activity = snapshot.data();
const tripId = activity.tripId;
const createdBy = activity.createdBy || "Unknown";
if (!tripId) {
console.log("No tripId found in activity");
return;
}
// Fetch trip to get participants
const tripDoc = await admin.firestore().collection("trips").doc(tripId).get();
if (!tripDoc.exists) {
console.log(`Trip ${tripId} not found`);
return;
}
const trip = tripDoc.data();
const participants = trip.participants || [];
if (trip.createdBy && !participants.includes(trip.createdBy)) {
participants.push(trip.createdBy);
}
console.log(`Found trip participants: ${JSON.stringify(participants)}`);
// Fetch creator name
let creatorName = "Quelqu'un";
if (createdBy !== "Unknown") {
const userDoc = await admin.firestore().collection("users").doc(createdBy).get();
if (userDoc.exists) {
creatorName = userDoc.data().prenom || "Quelqu'un";
}
}
await sendNotificationToUsers(
participants,
"Nouvelle activité !",
`${creatorName} a ajouté une nouvelle activité : ${activity.name || activity.title}`,
createdBy,
{ tripId: tripId }
);
});
exports.onMessageCreated = functions.firestore
.document("groups/{groupId}/messages/{messageId}")
.onCreate(async (snapshot, context) => {
console.log(`onMessageCreated triggered for ${context.params.messageId} in group ${context.params.groupId}`);
const message = snapshot.data();
const groupId = context.params.groupId;
const senderId = message.senderId;
// Fetch group to get members
const groupDoc = await admin.firestore().collection("groups").doc(groupId).get();
if (!groupDoc.exists) {
console.log(`Group ${groupId} not found`);
return;
}
const group = groupDoc.data();
const memberIds = group.memberIds || [];
console.log(`Found group members: ${JSON.stringify(memberIds)}`);
let senderName = message.senderName || "Quelqu'un";
await sendNotificationToUsers(
memberIds,
"Nouveau message",
`${senderName} : ${message.text}`,
senderId,
{ groupId: groupId }
);
});
exports.onExpenseCreated = functions.firestore
.document("expenses/{expenseId}")
.onCreate(async (snapshot, context) => {
console.log(`onExpenseCreated triggered for ${context.params.expenseId}`);
const expense = snapshot.data();
const groupId = expense.groupId;
const paidBy = expense.paidById || expense.paidBy;
if (!groupId) {
console.log("No groupId found in expense");
return;
}
// Fetch group to get members
const groupDoc = await admin.firestore().collection("groups").doc(groupId).get();
if (!groupDoc.exists) {
console.log(`Group ${groupId} not found`);
return;
}
const group = groupDoc.data();
const memberIds = group.memberIds || [];
console.log(`Found group members: ${JSON.stringify(memberIds)}`);
let payerName = expense.paidByName || "Quelqu'un";
await sendNotificationToUsers(
memberIds,
"Nouvelle dépense",
`${payerName} a ajouté une dépense : ${expense.amount} ${expense.currency || '€'}`,
paidBy,
{ groupId: groupId }
);
});
exports.callbacks_signInWithApple = functions.https.onRequest((req, res) => {
const code = req.body.code;
const state = req.body.state;
const id_token = req.body.id_token;
const user = req.body.user;
const params = new URLSearchParams();
if (code) params.append('code', code);
if (state) params.append('state', state);
if (id_token) params.append('id_token', id_token);
if (user) params.append('user', user);
const qs = params.toString();
const packageName = 'be.devdayronvl.travel_mate';
const redirectUrl = `intent://callback?${qs}#Intent;package=${packageName};scheme=signinwithapple;end`;
res.redirect(302, redirectUrl);
});

6823
functions/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

23
functions/package.json Normal file
View File

@@ -0,0 +1,23 @@
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "20"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^13.6.0",
"firebase-functions": "^7.0.0"
},
"devDependencies": {
"firebase-functions-test": "^3.4.1"
},
"private": true
}

View File

@@ -1205,56 +1205,85 @@ PODS:
- BoringSSL-GRPC/Interface (= 0.0.37) - BoringSSL-GRPC/Interface (= 0.0.37)
- BoringSSL-GRPC/Interface (0.0.37) - BoringSSL-GRPC/Interface (0.0.37)
- cloud_firestore (6.0.3): - cloud_firestore (6.0.3):
- Firebase/Firestore (= 12.4.0) - Firebase/Firestore (= 12.6.0)
- firebase_core - firebase_core
- Flutter - Flutter
- Firebase/Auth (12.4.0): - Firebase/Auth (12.6.0):
- Firebase/CoreOnly - Firebase/CoreOnly
- FirebaseAuth (~> 12.4.0) - FirebaseAuth (~> 12.6.0)
- Firebase/CoreOnly (12.4.0): - Firebase/CoreOnly (12.6.0):
- FirebaseCore (~> 12.4.0) - FirebaseCore (~> 12.6.0)
- Firebase/Firestore (12.4.0): - Firebase/Firestore (12.6.0):
- Firebase/CoreOnly - Firebase/CoreOnly
- FirebaseFirestore (~> 12.4.0) - FirebaseFirestore (~> 12.6.0)
- Firebase/Storage (12.4.0): - Firebase/Messaging (12.6.0):
- Firebase/CoreOnly - Firebase/CoreOnly
- FirebaseStorage (~> 12.4.0) - FirebaseMessaging (~> 12.6.0)
- Firebase/Storage (12.6.0):
- Firebase/CoreOnly
- FirebaseStorage (~> 12.6.0)
- firebase_analytics (12.1.0):
- firebase_core
- FirebaseAnalytics (= 12.6.0)
- Flutter
- firebase_auth (6.1.1): - firebase_auth (6.1.1):
- Firebase/Auth (= 12.4.0) - Firebase/Auth (= 12.6.0)
- firebase_core - firebase_core
- Flutter - Flutter
- firebase_core (4.2.0): - firebase_core (4.3.0):
- Firebase/CoreOnly (= 12.4.0) - Firebase/CoreOnly (= 12.6.0)
- Flutter
- firebase_messaging (16.0.4):
- Firebase/Messaging (= 12.6.0)
- firebase_core
- Flutter - Flutter
- firebase_storage (13.0.3): - firebase_storage (13.0.3):
- Firebase/Storage (= 12.4.0) - Firebase/Storage (= 12.6.0)
- firebase_core - firebase_core
- Flutter - Flutter
- FirebaseAppCheckInterop (12.4.0) - FirebaseAnalytics (12.6.0):
- FirebaseAuth (12.4.0): - FirebaseAnalytics/Default (= 12.6.0)
- FirebaseAppCheckInterop (~> 12.4.0) - FirebaseCore (~> 12.6.0)
- FirebaseAuthInterop (~> 12.4.0) - FirebaseInstallations (~> 12.6.0)
- FirebaseCore (~> 12.4.0) - GoogleUtilities/AppDelegateSwizzler (~> 8.1)
- FirebaseCoreExtension (~> 12.4.0) - GoogleUtilities/MethodSwizzler (~> 8.1)
- GoogleUtilities/Network (~> 8.1)
- "GoogleUtilities/NSData+zlib (~> 8.1)"
- nanopb (~> 3.30910.0)
- FirebaseAnalytics/Default (12.6.0):
- FirebaseCore (~> 12.6.0)
- FirebaseInstallations (~> 12.6.0)
- GoogleAppMeasurement/Default (= 12.6.0)
- GoogleUtilities/AppDelegateSwizzler (~> 8.1)
- GoogleUtilities/MethodSwizzler (~> 8.1)
- GoogleUtilities/Network (~> 8.1)
- "GoogleUtilities/NSData+zlib (~> 8.1)"
- nanopb (~> 3.30910.0)
- FirebaseAppCheckInterop (12.6.0)
- FirebaseAuth (12.6.0):
- FirebaseAppCheckInterop (~> 12.6.0)
- FirebaseAuthInterop (~> 12.6.0)
- FirebaseCore (~> 12.6.0)
- FirebaseCoreExtension (~> 12.6.0)
- GoogleUtilities/AppDelegateSwizzler (~> 8.1) - GoogleUtilities/AppDelegateSwizzler (~> 8.1)
- GoogleUtilities/Environment (~> 8.1) - GoogleUtilities/Environment (~> 8.1)
- GTMSessionFetcher/Core (< 6.0, >= 3.4) - GTMSessionFetcher/Core (< 6.0, >= 3.4)
- RecaptchaInterop (~> 101.0) - RecaptchaInterop (~> 101.0)
- FirebaseAuthInterop (12.4.0) - FirebaseAuthInterop (12.6.0)
- FirebaseCore (12.4.0): - FirebaseCore (12.6.0):
- FirebaseCoreInternal (~> 12.4.0) - FirebaseCoreInternal (~> 12.6.0)
- GoogleUtilities/Environment (~> 8.1) - GoogleUtilities/Environment (~> 8.1)
- GoogleUtilities/Logger (~> 8.1) - GoogleUtilities/Logger (~> 8.1)
- FirebaseCoreExtension (12.4.0): - FirebaseCoreExtension (12.6.0):
- FirebaseCore (~> 12.4.0) - FirebaseCore (~> 12.6.0)
- FirebaseCoreInternal (12.4.0): - FirebaseCoreInternal (12.6.0):
- "GoogleUtilities/NSData+zlib (~> 8.1)" - "GoogleUtilities/NSData+zlib (~> 8.1)"
- FirebaseFirestore (12.4.0): - FirebaseFirestore (12.6.0):
- FirebaseCore (~> 12.4.0) - FirebaseCore (~> 12.6.0)
- FirebaseCoreExtension (~> 12.4.0) - FirebaseCoreExtension (~> 12.6.0)
- FirebaseFirestoreInternal (~> 12.4.0) - FirebaseFirestoreInternal (~> 12.6.0)
- FirebaseSharedSwift (~> 12.4.0) - FirebaseSharedSwift (~> 12.6.0)
- FirebaseFirestoreInternal (12.4.0): - FirebaseFirestoreInternal (12.6.0):
- abseil/algorithm (~> 1.20240722.0) - abseil/algorithm (~> 1.20240722.0)
- abseil/base (~> 1.20240722.0) - abseil/base (~> 1.20240722.0)
- abseil/container/flat_hash_map (~> 1.20240722.0) - abseil/container/flat_hash_map (~> 1.20240722.0)
@@ -1263,21 +1292,37 @@ PODS:
- abseil/strings/strings (~> 1.20240722.0) - abseil/strings/strings (~> 1.20240722.0)
- abseil/time (~> 1.20240722.0) - abseil/time (~> 1.20240722.0)
- abseil/types (~> 1.20240722.0) - abseil/types (~> 1.20240722.0)
- FirebaseAppCheckInterop (~> 12.4.0) - FirebaseAppCheckInterop (~> 12.6.0)
- FirebaseCore (~> 12.4.0) - FirebaseCore (~> 12.6.0)
- "gRPC-C++ (~> 1.69.0)" - "gRPC-C++ (~> 1.69.0)"
- gRPC-Core (~> 1.69.0) - gRPC-Core (~> 1.69.0)
- leveldb-library (~> 1.22) - leveldb-library (~> 1.22)
- nanopb (~> 3.30910.0) - nanopb (~> 3.30910.0)
- FirebaseSharedSwift (12.4.0) - FirebaseInstallations (12.6.0):
- FirebaseStorage (12.4.0): - FirebaseCore (~> 12.6.0)
- FirebaseAppCheckInterop (~> 12.4.0) - GoogleUtilities/Environment (~> 8.1)
- FirebaseAuthInterop (~> 12.4.0) - GoogleUtilities/UserDefaults (~> 8.1)
- FirebaseCore (~> 12.4.0) - PromisesObjC (~> 2.4)
- FirebaseCoreExtension (~> 12.4.0) - FirebaseMessaging (12.6.0):
- FirebaseCore (~> 12.6.0)
- FirebaseInstallations (~> 12.6.0)
- GoogleDataTransport (~> 10.1)
- GoogleUtilities/AppDelegateSwizzler (~> 8.1)
- GoogleUtilities/Environment (~> 8.1)
- GoogleUtilities/Reachability (~> 8.1)
- GoogleUtilities/UserDefaults (~> 8.1)
- nanopb (~> 3.30910.0)
- FirebaseSharedSwift (12.6.0)
- FirebaseStorage (12.6.0):
- FirebaseAppCheckInterop (~> 12.6.0)
- FirebaseAuthInterop (~> 12.6.0)
- FirebaseCore (~> 12.6.0)
- FirebaseCoreExtension (~> 12.6.0)
- GoogleUtilities/Environment (~> 8.1) - GoogleUtilities/Environment (~> 8.1)
- GTMSessionFetcher/Core (< 6.0, >= 3.4) - GTMSessionFetcher/Core (< 6.0, >= 3.4)
- Flutter (1.0.0) - Flutter (1.0.0)
- flutter_local_notifications (0.0.1):
- Flutter
- geolocator_apple (1.2.0): - geolocator_apple (1.2.0):
- Flutter - Flutter
- FlutterMacOS - FlutterMacOS
@@ -1292,10 +1337,40 @@ PODS:
- FlutterMacOS - FlutterMacOS
- GoogleSignIn (~> 9.0) - GoogleSignIn (~> 9.0)
- GTMSessionFetcher (>= 3.4.0) - GTMSessionFetcher (>= 3.4.0)
- GoogleAdsOnDeviceConversion (3.2.0):
- GoogleUtilities/Environment (~> 8.1)
- GoogleUtilities/Logger (~> 8.1)
- GoogleUtilities/Network (~> 8.1)
- nanopb (~> 3.30910.0)
- GoogleAppMeasurement/Core (12.6.0):
- GoogleUtilities/AppDelegateSwizzler (~> 8.1)
- GoogleUtilities/MethodSwizzler (~> 8.1)
- GoogleUtilities/Network (~> 8.1)
- "GoogleUtilities/NSData+zlib (~> 8.1)"
- nanopb (~> 3.30910.0)
- GoogleAppMeasurement/Default (12.6.0):
- GoogleAdsOnDeviceConversion (~> 3.2.0)
- GoogleAppMeasurement/Core (= 12.6.0)
- GoogleAppMeasurement/IdentitySupport (= 12.6.0)
- GoogleUtilities/AppDelegateSwizzler (~> 8.1)
- GoogleUtilities/MethodSwizzler (~> 8.1)
- GoogleUtilities/Network (~> 8.1)
- "GoogleUtilities/NSData+zlib (~> 8.1)"
- nanopb (~> 3.30910.0)
- GoogleAppMeasurement/IdentitySupport (12.6.0):
- GoogleAppMeasurement/Core (= 12.6.0)
- GoogleUtilities/AppDelegateSwizzler (~> 8.1)
- GoogleUtilities/MethodSwizzler (~> 8.1)
- GoogleUtilities/Network (~> 8.1)
- "GoogleUtilities/NSData+zlib (~> 8.1)"
- nanopb (~> 3.30910.0)
- GoogleDataTransport (10.1.0):
- nanopb (~> 3.30910.0)
- PromisesObjC (~> 2.4)
- GoogleMaps (9.4.0): - GoogleMaps (9.4.0):
- GoogleMaps/Maps (= 9.4.0) - GoogleMaps/Maps (= 9.4.0)
- GoogleMaps/Maps (9.4.0) - GoogleMaps/Maps (9.4.0)
- GoogleSignIn (9.0.0): - GoogleSignIn (9.1.0):
- AppAuth (~> 2.0) - AppAuth (~> 2.0)
- AppCheckCore (~> 11.0) - AppCheckCore (~> 11.0)
- GTMAppAuth (~> 5.0) - GTMAppAuth (~> 5.0)
@@ -1310,6 +1385,9 @@ PODS:
- GoogleUtilities/Logger (8.1.0): - GoogleUtilities/Logger (8.1.0):
- GoogleUtilities/Environment - GoogleUtilities/Environment
- GoogleUtilities/Privacy - GoogleUtilities/Privacy
- GoogleUtilities/MethodSwizzler (8.1.0):
- GoogleUtilities/Logger
- GoogleUtilities/Privacy
- GoogleUtilities/Network (8.1.0): - GoogleUtilities/Network (8.1.0):
- GoogleUtilities/Logger - GoogleUtilities/Logger
- "GoogleUtilities/NSData+zlib" - "GoogleUtilities/NSData+zlib"
@@ -1454,10 +1532,13 @@ PODS:
DEPENDENCIES: DEPENDENCIES:
- cloud_firestore (from `.symlinks/plugins/cloud_firestore/ios`) - cloud_firestore (from `.symlinks/plugins/cloud_firestore/ios`)
- firebase_analytics (from `.symlinks/plugins/firebase_analytics/ios`)
- firebase_auth (from `.symlinks/plugins/firebase_auth/ios`) - firebase_auth (from `.symlinks/plugins/firebase_auth/ios`)
- firebase_core (from `.symlinks/plugins/firebase_core/ios`) - firebase_core (from `.symlinks/plugins/firebase_core/ios`)
- firebase_messaging (from `.symlinks/plugins/firebase_messaging/ios`)
- firebase_storage (from `.symlinks/plugins/firebase_storage/ios`) - firebase_storage (from `.symlinks/plugins/firebase_storage/ios`)
- Flutter (from `Flutter`) - Flutter (from `Flutter`)
- flutter_local_notifications (from `.symlinks/plugins/flutter_local_notifications/ios`)
- geolocator_apple (from `.symlinks/plugins/geolocator_apple/darwin`) - geolocator_apple (from `.symlinks/plugins/geolocator_apple/darwin`)
- google_maps_flutter_ios (from `.symlinks/plugins/google_maps_flutter_ios/ios`) - google_maps_flutter_ios (from `.symlinks/plugins/google_maps_flutter_ios/ios`)
- google_sign_in_ios (from `.symlinks/plugins/google_sign_in_ios/darwin`) - google_sign_in_ios (from `.symlinks/plugins/google_sign_in_ios/darwin`)
@@ -1477,6 +1558,7 @@ SPEC REPOS:
- AppCheckCore - AppCheckCore
- BoringSSL-GRPC - BoringSSL-GRPC
- Firebase - Firebase
- FirebaseAnalytics
- FirebaseAppCheckInterop - FirebaseAppCheckInterop
- FirebaseAuth - FirebaseAuth
- FirebaseAuthInterop - FirebaseAuthInterop
@@ -1485,9 +1567,14 @@ SPEC REPOS:
- FirebaseCoreInternal - FirebaseCoreInternal
- FirebaseFirestore - FirebaseFirestore
- FirebaseFirestoreInternal - FirebaseFirestoreInternal
- FirebaseInstallations
- FirebaseMessaging
- FirebaseSharedSwift - FirebaseSharedSwift
- FirebaseStorage - FirebaseStorage
- Google-Maps-iOS-Utils - Google-Maps-iOS-Utils
- GoogleAdsOnDeviceConversion
- GoogleAppMeasurement
- GoogleDataTransport
- GoogleMaps - GoogleMaps
- GoogleSignIn - GoogleSignIn
- GoogleUtilities - GoogleUtilities
@@ -1503,14 +1590,20 @@ SPEC REPOS:
EXTERNAL SOURCES: EXTERNAL SOURCES:
cloud_firestore: cloud_firestore:
:path: ".symlinks/plugins/cloud_firestore/ios" :path: ".symlinks/plugins/cloud_firestore/ios"
firebase_analytics:
:path: ".symlinks/plugins/firebase_analytics/ios"
firebase_auth: firebase_auth:
:path: ".symlinks/plugins/firebase_auth/ios" :path: ".symlinks/plugins/firebase_auth/ios"
firebase_core: firebase_core:
:path: ".symlinks/plugins/firebase_core/ios" :path: ".symlinks/plugins/firebase_core/ios"
firebase_messaging:
:path: ".symlinks/plugins/firebase_messaging/ios"
firebase_storage: firebase_storage:
:path: ".symlinks/plugins/firebase_storage/ios" :path: ".symlinks/plugins/firebase_storage/ios"
Flutter: Flutter:
:path: Flutter :path: Flutter
flutter_local_notifications:
:path: ".symlinks/plugins/flutter_local_notifications/ios"
geolocator_apple: geolocator_apple:
:path: ".symlinks/plugins/geolocator_apple/darwin" :path: ".symlinks/plugins/geolocator_apple/darwin"
google_maps_flutter_ios: google_maps_flutter_ios:
@@ -1539,28 +1632,37 @@ SPEC CHECKSUMS:
AppAuth: 1c1a8afa7e12f2ec3a294d9882dfa5ab7d3cb063 AppAuth: 1c1a8afa7e12f2ec3a294d9882dfa5ab7d3cb063
AppCheckCore: cc8fd0a3a230ddd401f326489c99990b013f0c4f AppCheckCore: cc8fd0a3a230ddd401f326489c99990b013f0c4f
BoringSSL-GRPC: dded2a44897e45f28f08ae87a55ee4bcd19bc508 BoringSSL-GRPC: dded2a44897e45f28f08ae87a55ee4bcd19bc508
cloud_firestore: 79014bb3b303d451717ed5fe69fded8a2b2e8dc2 cloud_firestore: d7598ff2b1b2064e810f839dbdde2765c0f2052a
Firebase: f07b15ae5a6ec0f93713e30b923d9970d144af3e Firebase: a451a7b61536298fd5cbfe3a746fd40443a50679
firebase_auth: c2b8be95d602d4e8a9148fae72333ef78e69cc20 firebase_analytics: 4f9cca09e65f6c2944a862c6dc86f6bed9fb769c
firebase_core: 744984dbbed8b3036abf34f0b98d80f130a7e464 firebase_auth: cfb7237c0d01e87360cb3bf61e02a417c36e19e8
firebase_storage: 0ba617a05b24aec050395e4d5d3773c0d7518a15 firebase_core: ba00a168e719694f38960502ceb560285603d073
FirebaseAppCheckInterop: f734c802f21fe1da0837708f0f9a27218c8a4ed0 firebase_messaging: 752f1df5294ead9d72091d4974362d00d4aec201
FirebaseAuth: 4a2aed737c84114a9d9b33d11ae1b147d6b94889 firebase_storage: 5716627614e95c75e243134f65c1b0d6f66a4315
FirebaseAuthInterop: 858e6b754966e70740a4370dd1503dfffe6dbb49 FirebaseAnalytics: d0a97a0db6425e5a5d966340b87f92ca7b13a557
FirebaseCore: bb595f3114953664e3c1dc032f008a244147cfd3 FirebaseAppCheckInterop: e2178171b4145013c7c1a3cc464d1d446d3a1896
FirebaseCoreExtension: 7e1f7118ee970e001a8013719fb90950ee5e0018 FirebaseAuth: 613c463cb43545a7fd2cd99ade09b78ac472c544
FirebaseCoreInternal: d7f5a043c2cd01a08103ab586587c1468047bca6 FirebaseAuthInterop: db06756ef028006d034b6004dc0c37c24f7828d4
FirebaseFirestore: 2a6183381cf7679b1bb000eb76a8e3178e25dee2 FirebaseCore: 0e38ad5d62d980a47a64b8e9301ffa311457be04
FirebaseFirestoreInternal: 6577a27cd5dc3722b900042527f86d4ea1626134 FirebaseCoreExtension: 032fd6f8509e591fda8cb76f6651f20d926b121f
FirebaseSharedSwift: 93426a1de92f19e1199fac5295a4f8df16458daa FirebaseCoreInternal: 69bf1306a05b8ac43004f6cc1f804bb7b05b229e
FirebaseStorage: 20d6b56fb8a40ebaa03d6a2889fe33dac64adb73 FirebaseFirestore: 51ce079b9ddcaa481644164eda649d362c2a6396
FirebaseFirestoreInternal: 8b1d2b0a1b859b2ddbd63f448c416c5be7367405
FirebaseInstallations: 631b38da2e11a83daa4bfb482f79d286a5dfa7ad
FirebaseMessaging: a61bc42dcab3f7a346d94bbb54dab2c9435b18b2
FirebaseSharedSwift: 79f27fff0addd15c3de19b87fba426f3cc2c964f
FirebaseStorage: 550349b1e8f7315834ea08308696e9469d77135d
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467 Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467
flutter_local_notifications: a5a732f069baa862e728d839dd2ebb904737effb
geolocator_apple: ab36aa0e8b7d7a2d7639b3b4e48308394e8cef5e geolocator_apple: ab36aa0e8b7d7a2d7639b3b4e48308394e8cef5e
Google-Maps-iOS-Utils: 0a484b05ed21d88c9f9ebbacb007956edd508a96 Google-Maps-iOS-Utils: 0a484b05ed21d88c9f9ebbacb007956edd508a96
google_maps_flutter_ios: 0291eb2aa252298a769b04d075e4a9d747ff7264 google_maps_flutter_ios: 0291eb2aa252298a769b04d075e4a9d747ff7264
google_sign_in_ios: 205742c688aea0e64db9da03c33121694a365109 google_sign_in_ios: 205742c688aea0e64db9da03c33121694a365109
GoogleAdsOnDeviceConversion: d68c69dd9581a0f5da02617b6f377e5be483970f
GoogleAppMeasurement: 3bf40aff49a601af5da1c3345702fcb4991d35ee
GoogleDataTransport: aae35b7ea0c09004c3797d53c8c41f66f219d6a7
GoogleMaps: 0608099d4870cac8754bdba9b6953db543432438 GoogleMaps: 0608099d4870cac8754bdba9b6953db543432438
GoogleSignIn: c7f09cfbc85a1abf69187be091997c317cc33b77 GoogleSignIn: fcee2257188d5eda57a5e2b6a715550ffff9206d
GoogleUtilities: 00c88b9a86066ef77f0da2fab05f65d7768ed8e1 GoogleUtilities: 00c88b9a86066ef77f0da2fab05f65d7768ed8e1
"gRPC-C++": cc207623316fb041a7a3e774c252cf68a058b9e8 "gRPC-C++": cc207623316fb041a7a3e774c252cf68a058b9e8
gRPC-Core: 860978b7db482de8b4f5e10677216309b5ff6330 gRPC-Core: 860978b7db482de8b4f5e10677216309b5ff6330

View File

@@ -490,7 +490,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 456VVYXDFN;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
@@ -499,6 +503,8 @@
); );
PRODUCT_BUNDLE_IDENTIFIER = be.devdayronvl.TravelMate; PRODUCT_BUNDLE_IDENTIFIER = be.devdayronvl.TravelMate;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = myiphone;
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
@@ -673,7 +679,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 456VVYXDFN;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
@@ -682,6 +692,8 @@
); );
PRODUCT_BUNDLE_IDENTIFIER = be.devdayronvl.TravelMate; PRODUCT_BUNDLE_IDENTIFIER = be.devdayronvl.TravelMate;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = myiphone;
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
@@ -696,7 +708,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 456VVYXDFN;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
@@ -705,6 +721,8 @@
); );
PRODUCT_BUNDLE_IDENTIFIER = be.devdayronvl.TravelMate; PRODUCT_BUNDLE_IDENTIFIER = be.devdayronvl.TravelMate;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = myiphone;
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";

View File

@@ -32,6 +32,14 @@
<string>com.googleusercontent.apps.521527250907-3i1qe2656eojs8k9hjdi573j09i9p41m</string> <string>com.googleusercontent.apps.521527250907-3i1qe2656eojs8k9hjdi573j09i9p41m</string>
</array> </array>
</dict> </dict>
<dict>
<key>CFBundleURLName</key>
<string>Apple Sign-In</string>
<key>CFBundleURLSchemes</key>
<array>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
</dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string> <string>$(FLUTTER_BUILD_NUMBER)</string>
@@ -39,6 +47,11 @@
<string>521527250907-3i1qe2656eojs8k9hjdi573j09i9p41m.apps.googleusercontent.com</string> <string>521527250907-3i1qe2656eojs8k9hjdi573j09i9p41m.apps.googleusercontent.com</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>remote-notification</string>
</array>
<key>NSLocationAlwaysUsageDescription</key> <key>NSLocationAlwaysUsageDescription</key>
<string>Cette application a besoin de votre position pour afficher votre localisation sur la carte</string> <string>Cette application a besoin de votre position pour afficher votre localisation sur la carte</string>
<key>NSLocationWhenInUseUsageDescription</key> <key>NSLocationWhenInUseUsageDescription</key>
@@ -52,27 +65,18 @@
<key>UISupportedInterfaceOrientations</key> <key>UISupportedInterfaceOrientations</key>
<array> <array>
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array> </array>
<key>UISupportedInterfaceOrientations~ipad</key> <key>UISupportedInterfaceOrientations~ipad</key>
<array> <array>
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string> <string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Apple Sign-In</string>
<key>CFBundleURLSchemes</key>
<array>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
</dict>
</array> </array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>comgooglemaps</string>
<string>waze</string>
</array>
<!-- Permission Caméra --> <!-- Permission Caméra -->
<key>NSCameraUsageDescription</key> <key>NSCameraUsageDescription</key>
<string>L'application a besoin d'accéder à votre caméra pour prendre des photos de profil.</string> <string>L'application a besoin d'accéder à votre caméra pour prendre des photos de profil.</string>

View File

@@ -6,5 +6,7 @@
<array> <array>
<string>Default</string> <string>Default</string>
</array> </array>
<key>aps-environment</key>
<string>development</string>
</dict> </dict>
</plist> </plist>

View File

@@ -22,6 +22,7 @@
/// accountBloc.close(); /// accountBloc.close();
/// ``` /// ```
library; library;
import 'dart:async'; import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:travel_mate/services/error_service.dart'; import 'package:travel_mate/services/error_service.dart';
@@ -40,6 +41,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(
@@ -49,17 +52,23 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
try { try {
emit(AccountLoading()); emit(AccountLoading());
await _accountsSubscription?.cancel(); await _accountsSubscription?.cancel();
_accountsSubscription = _repository.getAccountByUserId(event.userId).listen( _accountsSubscription = _repository
(accounts) { .getAccountByUserId(event.userId)
add(_AccountsUpdated(accounts)); .listen(
}, (accounts) {
onError: (error) { add(_AccountsUpdated(accounts));
add(_AccountsUpdated([], error: error.toString())); },
}, onError: (error) {
); add(_AccountsUpdated([], error: error.toString()));
},
);
} catch (e, stackTrace) { } catch (e, stackTrace) {
_errorService.logError(e.toString(), stackTrace); _errorService.logError(
emit(AccountError(e.toString())); 'AccountBloc',
'Error loading accounts: $e',
stackTrace,
);
emit(const AccountError('Impossible de charger les comptes'));
} }
} }
@@ -87,8 +96,12 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
); );
emit(AccountOperationSuccess('Compte créé avec succès. ID: $accountId')); emit(AccountOperationSuccess('Compte créé avec succès. ID: $accountId'));
} catch (e, stackTrace) { } catch (e, stackTrace) {
_errorService.logError(e.toString(), stackTrace); _errorService.logError(
emit(AccountError('Erreur lors de la création du compte: ${e.toString()}')); 'AccountBloc',
'Error creating account: $e',
stackTrace,
);
emit(const AccountError('Impossible de créer le compte'));
} }
} }
@@ -96,7 +109,7 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
CreateAccountWithMembers event, CreateAccountWithMembers event,
Emitter<AccountState> emit, Emitter<AccountState> emit,
) async { ) async {
try{ try {
emit(AccountLoading()); emit(AccountLoading());
final accountId = await _repository.createAccountWithMembers( final accountId = await _repository.createAccountWithMembers(
account: event.account, account: event.account,
@@ -104,8 +117,51 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
); );
emit(AccountOperationSuccess('Compte créé avec succès. ID: $accountId')); emit(AccountOperationSuccess('Compte créé avec succès. ID: $accountId'));
} catch (e, stackTrace) { } catch (e, stackTrace) {
_errorService.logError(e.toString(), stackTrace); _errorService.logError(
emit(AccountError('Erreur lors de la création du compte: ${e.toString()}')); 'AccountBloc',
'Error creating account with members: $e',
stackTrace,
);
emit(const AccountError('Impossible de créer le compte'));
}
}
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(
'AccountBloc',
'Error adding member: $e',
stackTrace,
);
emit(const AccountError('Impossible d\'ajouter le membre'));
}
}
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(
'AccountBloc',
'Error removing member: $e',
stackTrace,
);
emit(const AccountError('Impossible de supprimer le membre'));
} }
} }

View File

@@ -86,3 +86,31 @@ 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];
}

View File

@@ -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
@@ -51,12 +53,15 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
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, stackTrace) {
} catch (e) { _errorService.logError(
_errorService.logError('activity_bloc', 'Erreur chargement activités: $e'); 'activity_bloc',
'Erreur chargement activités: $e',
stackTrace,
);
emit(const ActivityError('Impossible de charger les activités')); emit(const ActivityError('Impossible de charger les activités'));
} }
} }
@@ -76,16 +81,49 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
} }
// Sinon, on charge normalement // Sinon, on charge normalement
emit(ActivityLoaded( emit(
activities: activities, ActivityLoaded(activities: activities, filteredActivities: activities),
filteredActivities: activities, );
)); } catch (e, stackTrace) {
} catch (e) { _errorService.logError(
_errorService.logError('activity_bloc', 'Erreur chargement activités: $e'); 'activity_bloc',
'Erreur chargement activités: $e',
stackTrace,
);
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, stackTrace) {
_errorService.logError(
'activity_bloc',
'Erreur mise à jour date: $e',
stackTrace,
);
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,
@@ -104,7 +142,9 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
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
); );
@@ -121,14 +161,24 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
// 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) { ),
_errorService.logError('activity_bloc', 'Erreur recherche activités: $e'); );
emit(const ActivityError('Impossible de rechercher les activités')); } catch (e, stackTrace) {
_errorService.logError(
'activity_bloc',
'Erreur recherche activités: $e',
stackTrace,
);
// Extraire le message d'erreur si disponible
final errorMessage = e.toString().replaceAll('Exception: ', '');
emit(
ActivityError('Impossible de rechercher les activités: $errorMessage'),
);
} }
} }
@@ -168,13 +218,19 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
// 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) { ),
_errorService.logError('activity_bloc', 'Erreur recherche activités avec coordonnées: $e'); );
} catch (e, stackTrace) {
_errorService.logError(
'activity_bloc',
'Erreur recherche activités avec coordonnées: $e',
stackTrace,
);
emit(const ActivityError('Impossible de rechercher les activités')); emit(const ActivityError('Impossible de rechercher les activités'));
} }
} }
@@ -196,12 +252,15 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
// 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, stackTrace) {
} catch (e) { _errorService.logError(
_errorService.logError('activity_bloc', 'Erreur recherche textuelle: $e'); 'activity_bloc',
'Erreur recherche textuelle: $e',
stackTrace,
);
emit(const ActivityError('Impossible de rechercher les activités')); emit(const ActivityError('Impossible de rechercher les activités'));
} }
} }
@@ -230,23 +289,34 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
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 {
emit(const ActivityError('Impossible d\'ajouter l\'activité')); emit(const ActivityError('Impossible d\'ajouter l\'activité'));
} }
} catch (e) { } catch (e, stackTrace) {
_errorService.logError('activity_bloc', 'Erreur ajout activité: $e'); _errorService.logError(
'activity_bloc',
'Erreur ajout activité: $e',
stackTrace,
);
emit(const ActivityError('Impossible d\'ajouter l\'activité')); emit(const ActivityError('Impossible d\'ajouter l\'activité'));
} }
} }
@@ -281,26 +351,34 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
.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 {
emit(const ActivityError('Impossible d\'ajouter l\'activité')); emit(const ActivityError('Impossible d\'ajouter l\'activité'));
} }
} catch (e) { } catch (e, stackTrace) {
_errorService.logError('activity_bloc', 'Erreur ajout activité: $e'); _errorService.logError(
'activity_bloc',
'Erreur ajout activité: $e',
stackTrace,
);
emit(const ActivityError('Impossible d\'ajouter l\'activité')); emit(const ActivityError('Impossible d\'ajouter l\'activité'));
} }
} }
@@ -314,11 +392,13 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
// 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];
@@ -337,11 +417,13 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
} }
// 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) {
@@ -352,17 +434,23 @@ 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 {
emit(const ActivityError('Impossible d\'ajouter les activités')); emit(const ActivityError('Impossible d\'ajouter les activités'));
} }
} catch (e) { } catch (e, stackTrace) {
_errorService.logError('activity_bloc', 'Erreur ajout en lot: $e'); _errorService.logError(
'activity_bloc',
'Erreur ajout en lot: $e',
stackTrace,
);
emit(const ActivityError('Impossible d\'ajouter les activités')); emit(const ActivityError('Impossible d\'ajouter les activités'));
} }
} }
@@ -376,10 +464,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(
@@ -389,11 +479,13 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
); );
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) {
@@ -402,22 +494,24 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
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'));
} }
} catch (e) { } catch (e, stackTrace) {
_errorService.logError('activity_bloc', 'Erreur vote: $e'); _errorService.logError('activity_bloc', 'Erreur vote: $e', stackTrace);
emit(const ActivityError('Impossible d\'enregistrer le vote')); emit(const ActivityError('Impossible d\'enregistrer le vote'));
} }
} }
@@ -431,10 +525,12 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
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) {
@@ -446,8 +542,12 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
} else { } else {
emit(const ActivityError('Impossible de supprimer l\'activité')); emit(const ActivityError('Impossible de supprimer l\'activité'));
} }
} catch (e) { } catch (e, stackTrace) {
_errorService.logError('activity_bloc', 'Erreur suppression: $e'); _errorService.logError(
'activity_bloc',
'Erreur suppression: $e',
stackTrace,
);
emit(const ActivityError('Impossible de supprimer l\'activité')); emit(const ActivityError('Impossible de supprimer l\'activité'));
} }
} }
@@ -468,12 +568,14 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
'', // 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,27 +605,35 @@ 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 {
emit(const ActivityError('Impossible de mettre à jour l\'activité')); emit(const ActivityError('Impossible de mettre à jour l\'activité'));
} }
} catch (e) { } catch (e, stackTrace) {
_errorService.logError('activity_bloc', 'Erreur mise à jour: $e'); _errorService.logError(
'activity_bloc',
'Erreur mise à jour: $e',
stackTrace,
);
emit(const ActivityError('Impossible de mettre à jour l\'activité')); emit(const ActivityError('Impossible de mettre à jour l\'activité'));
} }
} }
@@ -536,13 +646,15 @@ 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) { ),
_errorService.logError('activity_bloc', 'Erreur favori: $e'); );
} catch (e, stackTrace) {
_errorService.logError('activity_bloc', 'Erreur favori: $e', stackTrace);
emit(const ActivityError('Impossible de modifier les favoris')); emit(const ActivityError('Impossible de modifier les favoris'));
} }
} }
@@ -558,7 +670,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) {
@@ -587,11 +717,13 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
.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 +732,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,
),
);
} }
} }

View File

@@ -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];

View File

@@ -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
@@ -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];

View File

@@ -25,19 +25,28 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import '../../repositories/auth_repository.dart'; import '../../repositories/auth_repository.dart';
import 'auth_event.dart'; import 'auth_event.dart';
import 'auth_state.dart'; import 'auth_state.dart';
import '../../services/notification_service.dart';
import '../../services/analytics_service.dart';
/// BLoC for managing authentication state and operations. /// BLoC for managing authentication state and operations.
class AuthBloc extends Bloc<AuthEvent, AuthState> { class AuthBloc extends Bloc<AuthEvent, AuthState> {
/// Repository for authentication operations. /// Repository for authentication operations.
final AuthRepository _authRepository; final AuthRepository _authRepository;
final NotificationService _notificationService;
final AnalyticsService _analyticsService;
/// Creates an [AuthBloc] with the provided [authRepository]. /// Creates an [AuthBloc] with the provided [authRepository].
/// ///
/// The bloc starts in the [AuthInitial] state and registers event handlers /// The bloc starts in the [AuthInitial] state and registers event handlers
/// for all supported authentication events. /// for all supported authentication events.
AuthBloc({required AuthRepository authRepository}) AuthBloc({
: _authRepository = authRepository, required AuthRepository authRepository,
super(AuthInitial()) { NotificationService? notificationService,
AnalyticsService? analyticsService,
}) : _authRepository = authRepository,
_notificationService = notificationService ?? NotificationService(),
_analyticsService = analyticsService ?? AnalyticsService(),
super(AuthInitial()) {
on<AuthCheckRequested>(_onAuthCheckRequested); on<AuthCheckRequested>(_onAuthCheckRequested);
on<AuthSignInRequested>(_onSignInRequested); on<AuthSignInRequested>(_onSignInRequested);
on<AuthSignUpRequested>(_onSignUpRequested); on<AuthSignUpRequested>(_onSignUpRequested);
@@ -69,6 +78,9 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
); );
if (user != null) { if (user != null) {
// Save FCM Token on auto-login
await _notificationService.saveTokenToFirestore(user.id!);
await _analyticsService.setUserId(user.id);
emit(AuthAuthenticated(user: user)); emit(AuthAuthenticated(user: user));
} else { } else {
emit(AuthUnauthenticated()); emit(AuthUnauthenticated());
@@ -77,7 +89,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
emit(AuthUnauthenticated()); emit(AuthUnauthenticated());
} }
} catch (e) { } catch (e) {
emit(AuthError(message: e.toString())); emit(AuthError(message: e.toString().replaceAll('Exception: ', '')));
} }
} }
@@ -98,12 +110,19 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
); );
if (user != null) { if (user != null) {
// Save FCM Token
await NotificationService().saveTokenToFirestore(user.id!);
await _analyticsService.setUserId(user.id);
await _analyticsService.logEvent(
name: 'login',
parameters: {'method': 'email'},
);
emit(AuthAuthenticated(user: user)); emit(AuthAuthenticated(user: user));
} else { } else {
emit(const AuthError(message: 'Invalid email or password')); emit(const AuthError(message: 'Invalid email or password'));
} }
} catch (e) { } catch (e) {
emit(AuthError(message: e.toString())); emit(AuthError(message: e.toString().replaceAll('Exception: ', '')));
} }
} }
@@ -127,12 +146,19 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
); );
if (user != null) { if (user != null) {
// Save FCM Token
await NotificationService().saveTokenToFirestore(user.id!);
await _analyticsService.setUserId(user.id);
await _analyticsService.logEvent(
name: 'sign_up',
parameters: {'method': 'email'},
);
emit(AuthAuthenticated(user: user)); emit(AuthAuthenticated(user: user));
} else { } else {
emit(const AuthError(message: 'Failed to create account')); emit(const AuthError(message: 'Failed to create account'));
} }
} catch (e) { } catch (e) {
emit(AuthError(message: e.toString())); emit(AuthError(message: e.toString().replaceAll('Exception: ', '')));
} }
} }
@@ -150,6 +176,13 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
final user = await _authRepository.signInWithGoogle(); final user = await _authRepository.signInWithGoogle();
if (user != null) { if (user != null) {
// Save FCM Token
await NotificationService().saveTokenToFirestore(user.id!);
await _analyticsService.setUserId(user.id);
await _analyticsService.logEvent(
name: 'login',
parameters: {'method': 'google'},
);
emit(AuthAuthenticated(user: user)); emit(AuthAuthenticated(user: user));
} else { } else {
emit( emit(
@@ -160,7 +193,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
); );
} }
} catch (e) { } catch (e) {
emit(AuthError(message: e.toString())); emit(AuthError(message: e.toString().replaceAll('Exception: ', '')));
} }
} }
@@ -178,12 +211,17 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
); );
if (user != null) { if (user != null) {
await _analyticsService.setUserId(user.id);
await _analyticsService.logEvent(
name: 'sign_up',
parameters: {'method': 'google'},
);
emit(AuthAuthenticated(user: user)); emit(AuthAuthenticated(user: user));
} else { } else {
emit(const AuthError(message: 'Failed to create account with Google')); emit(const AuthError(message: 'Failed to create account with Google'));
} }
} catch (e) { } catch (e) {
emit(AuthError(message: e.toString())); emit(AuthError(message: e.toString().replaceAll('Exception: ', '')));
} }
} }
@@ -201,12 +239,17 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
); );
if (user != null) { if (user != null) {
await _analyticsService.setUserId(user.id);
await _analyticsService.logEvent(
name: 'sign_up',
parameters: {'method': 'apple'},
);
emit(AuthAuthenticated(user: user)); emit(AuthAuthenticated(user: user));
} else { } else {
emit(const AuthError(message: 'Failed to create account with Apple')); emit(const AuthError(message: 'Failed to create account with Apple'));
} }
} catch (e) { } catch (e) {
emit(AuthError(message: e.toString())); emit(AuthError(message: e.toString().replaceAll('Exception: ', '')));
} }
} }
@@ -224,6 +267,13 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
final user = await _authRepository.signInWithApple(); final user = await _authRepository.signInWithApple();
if (user != null) { if (user != null) {
// Save FCM Token
await NotificationService().saveTokenToFirestore(user.id!);
await _analyticsService.setUserId(user.id);
await _analyticsService.logEvent(
name: 'login',
parameters: {'method': 'apple'},
);
emit(AuthAuthenticated(user: user)); emit(AuthAuthenticated(user: user));
} else { } else {
emit( emit(
@@ -234,7 +284,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
); );
} }
} catch (e) { } catch (e) {
emit(AuthError(message: e.toString())); emit(AuthError(message: e.toString().replaceAll('Exception: ', '')));
} }
} }
@@ -246,6 +296,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
Emitter<AuthState> emit, Emitter<AuthState> emit,
) async { ) async {
await _authRepository.signOut(); await _authRepository.signOut();
await _analyticsService.setUserId(null); // Clear user ID
emit(AuthUnauthenticated()); emit(AuthUnauthenticated());
} }
@@ -261,7 +312,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
await _authRepository.resetPassword(event.email); await _authRepository.resetPassword(event.email);
emit(AuthPasswordResetSent(email: event.email)); emit(AuthPasswordResetSent(email: event.email));
} catch (e) { } catch (e) {
emit(AuthError(message: e.toString())); emit(AuthError(message: e.toString().replaceAll('Exception: ', '')));
} }
} }
} }

View File

@@ -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';
@@ -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);
@@ -83,21 +89,29 @@ 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( emit(
balances: userBalances, GroupBalancesLoaded(balances: userBalances, settlements: settlements),
settlements: settlements, );
)); } catch (e, stackTrace) {
} catch (e) { _errorService.logError(
_errorService.logError('BalanceBloc', 'Error loading balance: $e'); 'BalanceBloc',
emit(BalanceError(e.toString())); 'Error loading balance: $e',
stackTrace,
);
emit(const BalanceError('Impossible de charger la balance'));
} }
} }
@@ -121,18 +135,25 @@ class BalanceBloc extends Bloc<BalanceEvent, BalanceState> {
} }
// 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( emit(
balances: userBalances, GroupBalancesLoaded(balances: userBalances, settlements: settlements),
settlements: settlements, );
)); } catch (e, stackTrace) {
} catch (e) { _errorService.logError(
_errorService.logError('BalanceBloc', 'Error refreshing balance: $e'); 'BalanceBloc',
emit(BalanceError(e.toString())); 'Error refreshing balance: $e',
stackTrace,
);
emit(const BalanceError('Impossible de rafraîchir la balance'));
} }
} }
@@ -161,9 +182,15 @@ class BalanceBloc extends Bloc<BalanceEvent, BalanceState> {
// Reload balance after settlement // Reload balance after settlement
add(RefreshBalance(event.groupId)); add(RefreshBalance(event.groupId));
} catch (e) { } catch (e, stackTrace) {
_errorService.logError('BalanceBloc', 'Error marking settlement: $e'); _errorService.logError(
emit(BalanceError(e.toString())); 'BalanceBloc',
'Error marking settlement: $e',
stackTrace,
);
emit(
const BalanceError('Impossible de marquer le règlement comme terminé'),
);
} }
} }
} }

View File

@@ -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);
@@ -56,7 +57,9 @@ 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();
@@ -64,11 +67,12 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
.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');
emit(ExpenseError(e.toString())); emit(const ExpenseError('Impossible de charger les dépenses'));
} }
} }
@@ -105,11 +109,14 @@ 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');
emit(ExpenseError(e.toString())); emit(const ExpenseError('Impossible de créer la dépense'));
} }
} }
@@ -127,11 +134,14 @@ 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');
emit(ExpenseError(e.toString())); emit(const ExpenseError('Impossible de mettre à jour la dépense'));
} }
} }
@@ -152,7 +162,7 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
emit(const ExpenseOperationSuccess('Expense deleted successfully')); emit(const ExpenseOperationSuccess('Expense deleted successfully'));
} catch (e) { } catch (e) {
_errorService.logError('ExpenseBloc', 'Error deleting expense: $e'); _errorService.logError('ExpenseBloc', 'Error deleting expense: $e');
emit(ExpenseError(e.toString())); emit(const ExpenseError('Impossible de supprimer la dépense'));
} }
} }
@@ -174,7 +184,7 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
emit(const ExpenseOperationSuccess('Payment marked as completed')); emit(const ExpenseOperationSuccess('Payment marked as completed'));
} catch (e) { } catch (e) {
_errorService.logError('ExpenseBloc', 'Error marking split as paid: $e'); _errorService.logError('ExpenseBloc', 'Error marking split as paid: $e');
emit(ExpenseError(e.toString())); emit(const ExpenseError('Impossible de marquer comme payé'));
} }
} }
@@ -196,7 +206,7 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
emit(const ExpenseOperationSuccess('Expense archived successfully')); emit(const ExpenseOperationSuccess('Expense archived successfully'));
} catch (e) { } catch (e) {
_errorService.logError('ExpenseBloc', 'Error archiving expense: $e'); _errorService.logError('ExpenseBloc', 'Error archiving expense: $e');
emit(ExpenseError(e.toString())); emit(const ExpenseError('Impossible d\'archiver la dépense'));
} }
} }

View File

@@ -32,6 +32,7 @@
/// )); /// ));
/// ``` /// ```
library; library;
import 'dart:async'; import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:travel_mate/services/error_service.dart'; import 'package:travel_mate/services/error_service.dart';
@@ -85,17 +86,23 @@ class GroupBloc extends Bloc<GroupEvent, GroupState> {
try { try {
emit(GroupLoading()); emit(GroupLoading());
await _groupsSubscription?.cancel(); await _groupsSubscription?.cancel();
_groupsSubscription = _repository.getGroupsByUserId(event.userId).listen( _groupsSubscription = _repository
(groups) { .getGroupsByUserId(event.userId)
add(_GroupsUpdated(groups)); .listen(
}, (groups) {
onError: (error) { add(_GroupsUpdated(groups));
add(_GroupsUpdated([], error: error.toString())); },
}, onError: (error) {
); add(_GroupsUpdated([], error: error.toString()));
},
);
} catch (e, stackTrace) { } catch (e, stackTrace) {
_errorService.logError(e.toString(), stackTrace); _errorService.logError(
emit(GroupError(e.toString())); 'GroupBloc',
'Error loading groups: $e',
stackTrace,
);
emit(const GroupError('Impossible de charger les groupes'));
} }
} }
@@ -139,8 +146,13 @@ class GroupBloc extends Bloc<GroupEvent, GroupState> {
} else { } else {
emit(const GroupsLoaded([])); emit(const GroupsLoaded([]));
} }
} catch (e) { } catch (e, stackTrace) {
emit(GroupError(e.toString())); _errorService.logError(
'GroupBloc',
'Error loading group by trip: $e',
stackTrace,
);
emit(const GroupError('Impossible de charger le groupe du voyage'));
} }
} }
@@ -164,8 +176,13 @@ class GroupBloc extends Bloc<GroupEvent, GroupState> {
); );
emit(GroupCreated(groupId: groupId)); emit(GroupCreated(groupId: groupId));
emit(const GroupOperationSuccess('Group created successfully')); emit(const GroupOperationSuccess('Group created successfully'));
} catch (e) { } catch (e, stackTrace) {
emit(GroupError('Error during creation: $e')); _errorService.logError(
'GroupBloc',
'Error creating group: $e',
stackTrace,
);
emit(const GroupError('Impossible de créer le groupe'));
} }
} }
@@ -189,8 +206,13 @@ class GroupBloc extends Bloc<GroupEvent, GroupState> {
members: event.members, members: event.members,
); );
emit(GroupCreated(groupId: groupId)); emit(GroupCreated(groupId: groupId));
} catch (e) { } catch (e, stackTrace) {
emit(GroupError('Error during creation: $e')); _errorService.logError(
'GroupBloc',
'Error creating group with members: $e',
stackTrace,
);
emit(const GroupError('Impossible de créer le groupe'));
} }
} }
@@ -209,8 +231,13 @@ class GroupBloc extends Bloc<GroupEvent, GroupState> {
try { try {
await _repository.addMember(event.groupId, event.member); await _repository.addMember(event.groupId, event.member);
emit(const GroupOperationSuccess('Member added')); emit(const GroupOperationSuccess('Member added'));
} catch (e) { } catch (e, stackTrace) {
emit(GroupError('Error during addition: $e')); _errorService.logError(
'GroupBloc',
'Error adding member: $e',
stackTrace,
);
emit(const GroupError('Impossible d\'ajouter le membre'));
} }
} }
@@ -229,8 +256,13 @@ class GroupBloc extends Bloc<GroupEvent, GroupState> {
try { try {
await _repository.removeMember(event.groupId, event.userId); await _repository.removeMember(event.groupId, event.userId);
emit(const GroupOperationSuccess('Member removed')); emit(const GroupOperationSuccess('Member removed'));
} catch (e) { } catch (e, stackTrace) {
emit(GroupError('Error during removal: $e')); _errorService.logError(
'GroupBloc',
'Error removing member: $e',
stackTrace,
);
emit(const GroupError('Impossible de supprimer le membre'));
} }
} }
@@ -249,8 +281,13 @@ class GroupBloc extends Bloc<GroupEvent, GroupState> {
try { try {
await _repository.updateGroup(event.groupId, event.group); await _repository.updateGroup(event.groupId, event.group);
emit(const GroupOperationSuccess('Group updated')); emit(const GroupOperationSuccess('Group updated'));
} catch (e) { } catch (e, stackTrace) {
emit(GroupError('Error during update: $e')); _errorService.logError(
'GroupBloc',
'Error updating group: $e',
stackTrace,
);
emit(const GroupError('Impossible de mettre à jour le groupe'));
} }
} }
@@ -269,8 +306,13 @@ class GroupBloc extends Bloc<GroupEvent, GroupState> {
try { try {
await _repository.deleteGroup(event.tripId); await _repository.deleteGroup(event.tripId);
emit(const GroupOperationSuccess('Group deleted')); emit(const GroupOperationSuccess('Group deleted'));
} catch (e) { } catch (e, stackTrace) {
emit(GroupError('Error during deletion: $e')); _errorService.logError(
'GroupBloc',
'Error deleting group: $e',
stackTrace,
);
emit(const GroupError('Impossible de supprimer le groupe'));
} }
} }

View File

@@ -40,6 +40,7 @@
/// )); /// ));
/// ``` /// ```
library; library;
import 'dart:async'; import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import '../../models/message.dart'; import '../../models/message.dart';
@@ -65,10 +66,10 @@ class MessageBloc extends Bloc<MessageEvent, MessageState> {
/// Args: /// Args:
/// [messageService]: Optional service for message operations (auto-created if null) /// [messageService]: Optional service for message operations (auto-created if null)
MessageBloc({MessageService? messageService}) MessageBloc({MessageService? messageService})
: _messageService = messageService ?? MessageService( : _messageService =
messageRepository: MessageRepository(), messageService ??
), MessageService(messageRepository: MessageRepository()),
super(MessageInitial()) { super(MessageInitial()) {
on<LoadMessages>(_onLoadMessages); on<LoadMessages>(_onLoadMessages);
on<SendMessage>(_onSendMessage); on<SendMessage>(_onSendMessage);
on<DeleteMessage>(_onDeleteMessage); on<DeleteMessage>(_onDeleteMessage);
@@ -101,7 +102,7 @@ class MessageBloc extends Bloc<MessageEvent, MessageState> {
add(_MessagesUpdated(messages: messages, groupId: event.groupId)); add(_MessagesUpdated(messages: messages, groupId: event.groupId));
}, },
onError: (error) { onError: (error) {
add(_MessagesError('Error loading messages: $error')); add(const _MessagesError('Impossible de charger les messages'));
}, },
); );
} }
@@ -114,10 +115,7 @@ class MessageBloc extends Bloc<MessageEvent, MessageState> {
/// Args: /// Args:
/// [event]: The _MessagesUpdated event containing messages and group ID /// [event]: The _MessagesUpdated event containing messages and group ID
/// [emit]: State emitter function /// [emit]: State emitter function
void _onMessagesUpdated( void _onMessagesUpdated(_MessagesUpdated event, Emitter<MessageState> emit) {
_MessagesUpdated event,
Emitter<MessageState> emit,
) {
emit(MessagesLoaded(messages: event.messages, groupId: event.groupId)); emit(MessagesLoaded(messages: event.messages, groupId: event.groupId));
} }
@@ -142,7 +140,7 @@ class MessageBloc extends Bloc<MessageEvent, MessageState> {
senderName: event.senderName, senderName: event.senderName,
); );
} catch (e) { } catch (e) {
emit(MessageError('Error sending message: $e')); emit(const MessageError('Impossible d\'envoyer le message'));
} }
} }
@@ -166,7 +164,7 @@ class MessageBloc extends Bloc<MessageEvent, MessageState> {
messageId: event.messageId, messageId: event.messageId,
); );
} catch (e) { } catch (e) {
emit(MessageError('Error deleting message: $e')); emit(const MessageError('Impossible de supprimer le message'));
} }
} }
@@ -191,7 +189,7 @@ class MessageBloc extends Bloc<MessageEvent, MessageState> {
newText: event.newText, newText: event.newText,
); );
} catch (e) { } catch (e) {
emit(MessageError('Error updating message: $e')); emit(const MessageError('Impossible de modifier le message'));
} }
} }
@@ -217,7 +215,7 @@ class MessageBloc extends Bloc<MessageEvent, MessageState> {
reaction: event.reaction, reaction: event.reaction,
); );
} catch (e) { } catch (e) {
emit(MessageError('Error adding reaction: $e')); emit(const MessageError('Impossible d\'ajouter la réaction'));
} }
} }
@@ -242,7 +240,7 @@ class MessageBloc extends Bloc<MessageEvent, MessageState> {
userId: event.userId, userId: event.userId,
); );
} catch (e) { } catch (e) {
emit(MessageError('Error removing reaction: $e')); emit(const MessageError('Impossible de supprimer la réaction'));
} }
} }
@@ -273,10 +271,7 @@ class _MessagesUpdated extends MessageEvent {
/// Args: /// Args:
/// [messages]: List of messages from the stream update /// [messages]: List of messages from the stream update
/// [groupId]: ID of the group these messages belong to /// [groupId]: ID of the group these messages belong to
const _MessagesUpdated({ const _MessagesUpdated({required this.messages, required this.groupId});
required this.messages,
required this.groupId,
});
@override @override
List<Object?> get props => [messages, groupId]; List<Object?> get props => [messages, groupId];

View File

@@ -36,17 +36,20 @@
/// tripBloc.add(TripDeleteRequested(tripId: 'tripId456')); /// tripBloc.add(TripDeleteRequested(tripId: 'tripId456'));
/// ``` /// ```
library; library;
import 'dart:async'; import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:travel_mate/models/trip.dart'; import 'package:travel_mate/models/trip.dart';
import 'trip_event.dart'; import 'trip_event.dart';
import 'trip_state.dart'; import 'trip_state.dart';
import '../../repositories/trip_repository.dart'; import '../../repositories/trip_repository.dart';
import '../../services/error_service.dart';
/// BLoC that manages trip-related operations and state. /// BLoC that manages trip-related operations and state.
class TripBloc extends Bloc<TripEvent, TripState> { class TripBloc extends Bloc<TripEvent, TripState> {
/// Repository for trip data operations /// Repository for trip data operations
final TripRepository _repository; final TripRepository _repository;
final _errorService = ErrorService();
/// Subscription to trip stream for real-time updates /// Subscription to trip stream for real-time updates
StreamSubscription? _tripsSubscription; StreamSubscription? _tripsSubscription;
@@ -88,14 +91,26 @@ class TripBloc extends Bloc<TripEvent, TripState> {
_currentUserId = event.userId; _currentUserId = event.userId;
await _tripsSubscription?.cancel(); await _tripsSubscription?.cancel();
_tripsSubscription = _repository.getTripsByUserId(event.userId).listen( _tripsSubscription = _repository
(trips) { .getTripsByUserId(event.userId)
add(_TripsUpdated(trips)); .listen(
}, (trips) {
onError: (error) { add(_TripsUpdated(trips));
emit(TripError(error.toString())); },
}, onError: (error, stackTrace) {
); _errorService.logError(
'TripBloc',
'Error loading trips: $error',
stackTrace,
);
add(
const _TripsUpdated(
[],
error: 'Impossible de charger les voyages',
),
);
},
);
} }
/// Handles [_TripsUpdated] events. /// Handles [_TripsUpdated] events.
@@ -106,11 +121,12 @@ class TripBloc extends Bloc<TripEvent, TripState> {
/// Args: /// Args:
/// [event]: The _TripsUpdated event containing the updated trip list /// [event]: The _TripsUpdated event containing the updated trip list
/// [emit]: State emitter function /// [emit]: State emitter function
void _onTripsUpdated( void _onTripsUpdated(_TripsUpdated event, Emitter<TripState> emit) {
_TripsUpdated event, if (event.error != null) {
Emitter<TripState> emit, emit(TripError(event.error!));
) { } else {
emit(TripLoaded(event.trips)); emit(TripLoaded(event.trips));
}
} }
/// Handles [TripCreateRequested] events. /// Handles [TripCreateRequested] events.
@@ -137,9 +153,9 @@ class TripBloc extends Bloc<TripEvent, TripState> {
if (_currentUserId != null) { if (_currentUserId != null) {
add(LoadTripsByUserId(userId: _currentUserId!)); add(LoadTripsByUserId(userId: _currentUserId!));
} }
} catch (e, stackTrace) {
} catch (e) { _errorService.logError('TripBloc', 'Error creating trip: $e', stackTrace);
emit(TripError('Error during creation: $e')); emit(const TripError('Impossible de créer le voyage'));
} }
} }
@@ -163,9 +179,9 @@ class TripBloc extends Bloc<TripEvent, TripState> {
if (_currentUserId != null) { if (_currentUserId != null) {
add(LoadTripsByUserId(userId: _currentUserId!)); add(LoadTripsByUserId(userId: _currentUserId!));
} }
} catch (e, stackTrace) {
} catch (e) { _errorService.logError('TripBloc', 'Error updating trip: $e', stackTrace);
emit(TripError('Error during update: $e')); emit(const TripError('Impossible de mettre à jour le voyage'));
} }
} }
@@ -191,9 +207,9 @@ class TripBloc extends Bloc<TripEvent, TripState> {
if (_currentUserId != null) { if (_currentUserId != null) {
add(LoadTripsByUserId(userId: _currentUserId!)); add(LoadTripsByUserId(userId: _currentUserId!));
} }
} catch (e, stackTrace) {
} catch (e) { _errorService.logError('TripBloc', 'Error deleting trip: $e', stackTrace);
emit(TripError('Error during deletion: $e')); emit(const TripError('Impossible de supprimer le voyage'));
} }
} }
@@ -206,10 +222,7 @@ class TripBloc extends Bloc<TripEvent, TripState> {
/// Args: /// Args:
/// [event]: The ResetTrips event /// [event]: The ResetTrips event
/// [emit]: State emitter function /// [emit]: State emitter function
Future<void> _onResetTrips( Future<void> _onResetTrips(ResetTrips event, Emitter<TripState> emit) async {
ResetTrips event,
Emitter<TripState> emit,
) async {
await _tripsSubscription?.cancel(); await _tripsSubscription?.cancel();
_currentUserId = null; _currentUserId = null;
emit(TripInitial()); emit(TripInitial());
@@ -230,16 +243,11 @@ class TripBloc extends Bloc<TripEvent, TripState> {
/// ///
/// This internal event is used to process updates from the trip stream /// This internal event is used to process updates from the trip stream
/// subscription and emit appropriate states based on the received data. /// subscription and emit appropriate states based on the received data.
/// internal event
class _TripsUpdated extends TripEvent { class _TripsUpdated extends TripEvent {
/// List of trips received from the stream
final List<Trip> trips; final List<Trip> trips;
final String? error;
/// Creates a _TripsUpdated event. const _TripsUpdated(this.trips, {this.error});
///
/// Args:
/// [trips]: List of trips from the stream update
const _TripsUpdated(this.trips);
@override @override
List<Object?> get props => [trips]; List<Object?> get props => [trips, error];
} }

View File

@@ -1,6 +1,11 @@
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:travel_mate/repositories/group_repository.dart';
import 'package:travel_mate/services/notification_service.dart';
import 'package:travel_mate/services/logger_service.dart';
import 'package:travel_mate/services/error_service.dart';
import 'user_event.dart' as event; import 'user_event.dart' as event;
import 'user_state.dart' as state; import 'user_state.dart' as state;
@@ -16,6 +21,10 @@ class UserBloc extends Bloc<event.UserEvent, state.UserState> {
/// Firestore instance for user data operations. /// Firestore instance for user data operations.
final FirebaseFirestore _firestore = FirebaseFirestore.instance; final FirebaseFirestore _firestore = FirebaseFirestore.instance;
final GroupRepository _groupRepository = GroupRepository();
final _errorService = ErrorService();
/// Creates a new [UserBloc] with initial state. /// Creates a new [UserBloc] with initial state.
/// ///
/// Registers event handlers for all user-related events. /// Registers event handlers for all user-related events.
@@ -45,6 +54,12 @@ class UserBloc extends Bloc<event.UserEvent, state.UserState> {
return; return;
} }
// Initialize notifications and update token
final notificationService = NotificationService();
await notificationService.initialize();
final fcmToken = await notificationService.getFCMToken();
LoggerService.info('UserBloc - FCM Token retrieved: $fcmToken');
// Fetch user data from Firestore // Fetch user data from Firestore
final userDoc = await _firestore final userDoc = await _firestore
.collection('users') .collection('users')
@@ -57,6 +72,7 @@ class UserBloc extends Bloc<event.UserEvent, state.UserState> {
id: currentUser.uid, id: currentUser.uid,
email: currentUser.email ?? '', email: currentUser.email ?? '',
prenom: currentUser.displayName ?? 'Voyageur', prenom: currentUser.displayName ?? 'Voyageur',
fcmToken: fcmToken,
); );
await _firestore await _firestore
@@ -70,10 +86,25 @@ class UserBloc extends Bloc<event.UserEvent, state.UserState> {
'id': currentUser.uid, 'id': currentUser.uid,
...userDoc.data()!, ...userDoc.data()!,
}); });
// Update FCM token if it changed
if (fcmToken != null && user.fcmToken != fcmToken) {
LoggerService.info('UserBloc - Updating FCM token in Firestore');
await _firestore.collection('users').doc(currentUser.uid).set({
'fcmToken': fcmToken,
}, SetOptions(merge: true));
LoggerService.info('UserBloc - FCM token updated');
} else {
LoggerService.info(
'UserBloc - FCM token not updated. Local: $fcmToken, Firestore: ${user.fcmToken}',
);
}
emit(state.UserLoaded(user)); emit(state.UserLoaded(user));
} }
} catch (e) { } catch (e, stackTrace) {
emit(state.UserError('Error loading user: $e')); _errorService.logError('UserBloc', 'Error loading user: $e', stackTrace);
emit(state.UserError('Impossible de charger l\'utilisateur'));
} }
} }
@@ -102,8 +133,9 @@ class UserBloc extends Bloc<event.UserEvent, state.UserState> {
} else { } else {
emit(state.UserError('User not found')); emit(state.UserError('User not found'));
} }
} catch (e) { } catch (e, stackTrace) {
emit(state.UserError('Error loading user: $e')); _errorService.logError('UserBloc', 'Error loading user: $e', stackTrace);
emit(state.UserError('Impossible de charger l\'utilisateur'));
} }
} }
@@ -136,8 +168,23 @@ class UserBloc extends Bloc<event.UserEvent, state.UserState> {
}); });
emit(state.UserLoaded(updatedUser)); emit(state.UserLoaded(updatedUser));
} catch (e) {
emit(state.UserError('Error updating user: $e')); // Propager les changements aux groupes
await _groupRepository.updateMemberDetails(
userId: currentUser.id,
firstName: event
.userData['prenom'], // 'prenom' dans Firestore map map to firstName usually? Wait, UserModel has prenom/nom.
lastName: event.userData['nom'],
profilePictureUrl: event
.userData['profilePictureUrl'], // Key was 'profilePictureUrl' in ProfileContent
);
} catch (e, stackTrace) {
_errorService.logError(
'UserBloc',
'Error updating user: $e',
stackTrace,
);
emit(state.UserError('Impossible de mettre à jour l\'utilisateur'));
} }
} }
} }

View File

@@ -81,6 +81,9 @@ class UserModel {
/// User's profile picture URL (optional). /// User's profile picture URL (optional).
final String? profilePictureUrl; final String? profilePictureUrl;
/// Firebase Cloud Messaging token for push notifications.
final String? fcmToken;
/// Creates a new [UserModel] instance. /// Creates a new [UserModel] instance.
/// ///
/// [id], [email], and [prenom] are required fields. /// [id], [email], and [prenom] are required fields.
@@ -93,6 +96,7 @@ class UserModel {
this.authMethod, this.authMethod,
this.phoneNumber, this.phoneNumber,
this.profilePictureUrl, this.profilePictureUrl,
this.fcmToken,
}); });
/// Creates a [UserModel] instance from a JSON map. /// Creates a [UserModel] instance from a JSON map.
@@ -108,6 +112,7 @@ class UserModel {
authMethod: json['authMethod'] ?? json['platform'], authMethod: json['authMethod'] ?? json['platform'],
phoneNumber: json['phoneNumber'], phoneNumber: json['phoneNumber'],
profilePictureUrl: json['profilePictureUrl'], profilePictureUrl: json['profilePictureUrl'],
fcmToken: json['fcmToken'],
); );
} }
@@ -123,6 +128,7 @@ class UserModel {
'authMethod': authMethod, 'authMethod': authMethod,
'phoneNumber': phoneNumber, 'phoneNumber': phoneNumber,
'profilePictureUrl': profilePictureUrl, 'profilePictureUrl': profilePictureUrl,
'fcmToken': fcmToken,
}; };
} }
} }

View File

@@ -18,8 +18,11 @@
/// ///
/// The component automatically loads account data when initialized and /// The component automatically loads account data when initialized and
/// provides a clean interface for managing group-based expenses. /// provides a clean interface for managing group-based expenses.
///
library; library;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../services/error_service.dart';
import 'package:travel_mate/blocs/user/user_bloc.dart'; import 'package:travel_mate/blocs/user/user_bloc.dart';
import '../../models/account.dart'; import '../../models/account.dart';
import '../../blocs/account/account_bloc.dart'; import '../../blocs/account/account_bloc.dart';
@@ -28,8 +31,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 {
@@ -69,10 +73,7 @@ class _AccountContentState extends State<AccountContent> {
throw Exception('User not connected'); throw Exception('User not connected');
} }
} catch (e) { } catch (e) {
ErrorContent( ErrorContent(message: 'Error loading accounts: $e', onRetry: () {});
message: 'Error loading accounts: $e',
onRetry: () {},
);
} }
} }
@@ -93,30 +94,18 @@ class _AccountContentState extends State<AccountContent> {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => GroupExpensesPage( builder: (context) =>
account: account, GroupExpensesPage(account: account, group: group),
group: group,
),
), ),
); );
} else { } else {
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( ErrorService().showError(message: 'Group not found for this account');
const SnackBar(
content: Text('Group not found for this account'),
backgroundColor: Colors.red,
),
);
} }
} }
} catch (e) { } catch (e) {
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( ErrorService().showError(message: 'Error loading group: $e');
SnackBar(
content: Text('Error loading group: $e'),
backgroundColor: Colors.red,
),
);
} }
} }
} }
@@ -132,46 +121,36 @@ 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),
);
}, },
); );
} }
}, },
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 +175,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 +183,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 +201,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'),
), ),
], ],
), ),
@@ -250,7 +229,11 @@ class _AccountContentState extends State<AccountContent> {
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
const Icon(Icons.account_balance_wallet, size: 80, color: Colors.grey), const Icon(
Icons.account_balance_wallet,
size: 80,
color: Colors.grey,
),
const SizedBox(height: 16), const SizedBox(height: 16),
const Text( const Text(
'No accounts found', 'No accounts found',
@@ -258,7 +241,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,25 +272,14 @@ class _AccountContentState extends State<AccountContent> {
child: ListView( child: ListView(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
children: [ children: [
const Text(
'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) { ...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),
); );
}) }),
], ],
) ),
); );
} }
@@ -329,9 +301,10 @@ class _AccountContentState extends State<AccountContent> {
final colors = [Colors.blue, Colors.purple, Colors.green, Colors.orange]; final colors = [Colors.blue, Colors.purple, Colors.green, Colors.orange];
final color = colors[account.name.hashCode.abs() % colors.length]; final color = colors[account.name.hashCode.abs() % colors.length];
String memberInfo = '${account.members.length} member${account.members.length > 1 ? 's' : ''}'; String memberInfo =
'${account.members.length} member${account.members.length > 1 ? 's' : ''}';
if(account.members.isNotEmpty){ if (account.members.isNotEmpty) {
final names = account.members final names = account.members
.take(2) .take(2)
.map((m) => m.pseudo.isNotEmpty ? m.pseudo : m.firstName) .map((m) => m.pseudo.isNotEmpty ? m.pseudo : m.firstName)
@@ -344,7 +317,10 @@ class _AccountContentState extends State<AccountContent> {
child: ListTile( child: ListTile(
leading: CircleAvatar( leading: CircleAvatar(
backgroundColor: color, backgroundColor: color,
child: const Icon(Icons.account_balance_wallet, color: Colors.white), child: const Icon(
Icons.account_balance_wallet,
color: Colors.white,
),
), ),
title: Text( title: Text(
account.name, account.name,
@@ -352,7 +328,8 @@ class _AccountContentState extends State<AccountContent> {
), ),
subtitle: Text(memberInfo), subtitle: Text(memberInfo),
trailing: const Icon(Icons.chevron_right), trailing: const Icon(Icons.chevron_right),
onTap: () => _navigateToGroupExpenses(account), // Navigate to group expenses onTap: () =>
_navigateToGroupExpenses(account), // Navigate to group expenses
), ),
); );
} catch (e) { } catch (e) {
@@ -361,7 +338,7 @@ class _AccountContentState extends State<AccountContent> {
child: const ListTile( child: const ListTile(
leading: Icon(Icons.error, color: Colors.red), leading: Icon(Icons.error, color: Colors.red),
title: Text('Display error'), title: Text('Display error'),
) ),
); );
} }
} }

View File

@@ -56,12 +56,14 @@
/// - 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';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:travel_mate/models/expense_split.dart'; import 'package:travel_mate/models/expense_split.dart';
import '../../services/error_service.dart';
import '../../blocs/expense/expense_bloc.dart'; import '../../blocs/expense/expense_bloc.dart';
import '../../blocs/expense/expense_event.dart'; import '../../blocs/expense/expense_event.dart';
import '../../blocs/expense/expense_state.dart'; import '../../blocs/expense/expense_state.dart';
@@ -76,11 +78,25 @@ 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;
/// Optional initial category for a new expense.
final ExpenseCategory? initialCategory;
/// Optional initial amount for a new expense.
final double? initialAmount;
/// Optional initial splits (userId -> amount) for a new expense.
final Map<String, double>? initialSplits;
/// Optional initial description for a new expense.
final String? initialDescription;
/// Creates an AddExpenseDialog. /// Creates an AddExpenseDialog.
/// ///
/// [group] is the group for the expense. /// [group] is the group for the expense.
@@ -91,6 +107,10 @@ class AddExpenseDialog extends StatefulWidget {
required this.group, required this.group,
required this.currentUser, required this.currentUser,
this.expenseToEdit, this.expenseToEdit,
this.initialCategory,
this.initialAmount,
this.initialSplits,
this.initialDescription,
}); });
@override @override
@@ -103,33 +123,49 @@ 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();
// Initialize form fields and splits based on whether editing or creating // Initialize form fields and splits based on whether editing or creating
_selectedDate = widget.expenseToEdit?.date ?? DateTime.now(); _selectedDate = widget.expenseToEdit?.date ?? DateTime.now();
_selectedCategory = widget.expenseToEdit?.category ?? ExpenseCategory.other; _selectedCategory =
widget.expenseToEdit?.category ??
widget.initialCategory ??
ExpenseCategory.other;
_selectedCurrency = widget.expenseToEdit?.currency ?? ExpenseCurrency.eur; _selectedCurrency = widget.expenseToEdit?.currency ?? ExpenseCurrency.eur;
_paidById = widget.expenseToEdit?.paidById ?? widget.currentUser.id; _paidById = widget.expenseToEdit?.paidById ?? widget.currentUser.id;
@@ -142,9 +178,32 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
} }
_splitEqually = false; _splitEqually = false;
} else { } else {
// Creating: initialize splits for all group members // Creating: initialize splits
for (final member in widget.group.members) { if (widget.initialDescription != null) {
_splits[member.userId] = 0; _descriptionController.text = widget.initialDescription!;
}
if (widget.initialAmount != null) {
_amountController.text = widget.initialAmount.toString();
}
if (widget.initialSplits != null) {
_splits.addAll(widget.initialSplits!);
// Fill remaining members with 0 if not in initialSplits
for (final member in widget.group.members) {
if (!_splits.containsKey(member.userId)) {
_splits[member.userId] = 0;
} else {
// If we have specific splits, we probably aren't splitting equally by default logic
// unless we want to force it. For reimbursement, we likely set exact amounts.
_splitEqually = false;
}
}
} else {
// Default behavior: initialize splits for all group members
for (final member in widget.group.members) {
_splits[member.userId] = 0;
}
} }
} }
} }
@@ -175,11 +234,8 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
if (fileSize > 5 * 1024 * 1024) { if (fileSize > 5 * 1024 * 1024) {
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( ErrorService().showError(
const SnackBar( message: 'L\'image ne doit pas dépasser 5 Mo',
content: Text('L\'image ne doit pas dépasser 5 Mo'),
backgroundColor: Colors.red,
),
); );
} }
return; return;
@@ -221,24 +277,18 @@ 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( ErrorService().showError(
const SnackBar( message: 'Veuillez sélectionner au moins un participant',
content: Text('Veuillez sélectionner au moins un participant'),
backgroundColor: Colors.red,
),
); );
return; return;
} }
@@ -248,11 +298,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,41 +320,32 @@ 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( ErrorService().showSnackbar(
SnackBar( message: widget.expenseToEdit == null
content: Text(widget.expenseToEdit == null ? 'Dépense ajoutée'
? 'Dépense ajoutée' : 'Dépense modifiée',
: 'Dépense modifiée'), isError: false,
backgroundColor: Colors.green,
),
); );
} }
} catch (e) { } catch (e) {
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( ErrorService().showError(message: 'Erreur: $e');
SnackBar(
content: Text('Erreur: $e'),
backgroundColor: Colors.red,
),
);
} }
} finally { } finally {
if (mounted) { if (mounted) {
@@ -314,284 +359,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,
),
),
),
),
),
],
), ),
), ),
); );

View File

@@ -6,7 +6,13 @@
library; library;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../blocs/user/user_bloc.dart';
import '../../blocs/user/user_state.dart' as user_state;
import '../../models/expense.dart';
import '../../models/group.dart';
import '../../models/user_balance.dart'; import '../../models/user_balance.dart';
import 'add_expense_dialog.dart';
/// A stateless widget that displays a list of user balances in a group. /// A stateless widget that displays a list of user balances in a group.
/// ///
@@ -18,21 +24,19 @@ class BalancesTab extends StatelessWidget {
/// The list of user balances to display. /// The list of user balances to display.
final List<UserBalance> balances; final List<UserBalance> balances;
/// The group associated with these balances.
final Group group;
/// Creates a `BalancesTab` widget. /// Creates a `BalancesTab` widget.
/// ///
/// The [balances] parameter must not be null. /// The [balances] parameter must not be null.
const BalancesTab({ const BalancesTab({super.key, required this.balances, required this.group});
super.key,
required this.balances,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Check if the balances list is empty and display a placeholder message if true. // Check if the balances list is empty and display a placeholder message if true.
if (balances.isEmpty) { if (balances.isEmpty) {
return const Center( return const Center(child: Text('Aucune balance à afficher'));
child: Text('Aucune balance à afficher'),
);
} }
// Render the list of balances as a scrollable list. // Render the list of balances as a scrollable list.
@@ -79,81 +83,149 @@ class BalancesTab extends StatelessWidget {
margin: const EdgeInsets.only(bottom: 12), margin: const EdgeInsets.only(bottom: 12),
child: Padding( child: Padding(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: Row( child: Column(
children: [ children: [
// Display the user's initial in a circular avatar. Row(
CircleAvatar( children: [
radius: 24, // Display the user's initial in a circular avatar.
backgroundColor: isDark ? Colors.grey[800] : Colors.grey[200], CircleAvatar(
child: Text( radius: 24,
balance.userName.isNotEmpty backgroundColor: isDark ? Colors.grey[800] : Colors.grey[200],
? balance.userName[0].toUpperCase() child: Text(
: '?', balance.userName.isNotEmpty
style: const TextStyle( ? balance.userName[0].toUpperCase()
fontSize: 20, : '?',
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(width: 16),
// Display the user's name and financial details.
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// User's name.
Text(
balance.userName,
style: const TextStyle( style: const TextStyle(
fontSize: 16, fontSize: 20,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
const SizedBox(height: 4), ),
// User's total paid and owed amounts. const SizedBox(width: 16),
Text( // Display the user's name and financial details.
'Payé: ${balance.totalPaid.toStringAsFixed(2)} € • Doit: ${balance.totalOwed.toStringAsFixed(2)}', Expanded(
style: TextStyle( child: Column(
fontSize: 12, crossAxisAlignment: CrossAxisAlignment.start,
color: isDark ? Colors.grey[400] : Colors.grey[600], children: [
), // User's name.
), Text(
], balance.userName,
), style: const TextStyle(
), fontSize: 16,
// Display the user's balance status and amount. fontWeight: FontWeight.bold,
Column( ),
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Row(
children: [
// Icon indicating the balance status.
Icon(balanceIcon, size: 16, color: balanceColor),
const SizedBox(width: 4),
// User's absolute balance amount.
Text(
'${balance.absoluteBalance.toStringAsFixed(2)}',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: balanceColor,
), ),
const SizedBox(height: 4),
// User's total paid and owed amounts.
Text(
'Payé: ${balance.totalPaid.toStringAsFixed(2)} € • Doit: ${balance.totalOwed.toStringAsFixed(2)}',
style: TextStyle(
fontSize: 12,
color: isDark ? Colors.grey[400] : Colors.grey[600],
),
),
],
),
),
// Display the user's balance status and amount.
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Row(
children: [
// Icon indicating the balance status.
Icon(balanceIcon, size: 16, color: balanceColor),
const SizedBox(width: 4),
// User's absolute balance amount.
Text(
'${balance.absoluteBalance.toStringAsFixed(2)}',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: balanceColor,
),
),
],
),
// Text indicating the balance status (e.g., "À recevoir").
Text(
balanceText,
style: TextStyle(fontSize: 12, color: balanceColor),
), ),
], ],
), ),
// Text indicating the balance status (e.g., "À recevoir").
Text(
balanceText,
style: TextStyle(
fontSize: 12,
color: balanceColor,
),
),
], ],
), ),
// "Rembourser" button (Only show if this user is owed money and current user is looking at list?
// Wait, this list shows balances of everyone.
// Requirement: "Il faut un bouton dans la page qui permet de régler l'argent qu'on doit à une certaine personne"
// So if I look at "Alice", and Alice "shouldReceive" (is green), it implies the group owes Alice.
// But does it mean *I* owe Alice?
// The BalancesTab shows the *Group's* balances.
// However, usually settlement is 1-on-1. The requirement says: "régler l'argent qu'on doit à une certaine personne".
// If the user displayed here 'shouldReceive' money, it means they are owed money.
// If I click 'Rembourser', it implies *I* am paying them.
// This button should probably be available if the user on the card is POSITIVE (shouldReceive)
// AND I am not that user.
if (balance.shouldReceive) ...[
const SizedBox(height: 12),
SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
onPressed: () => _showReimbursementDialog(context, balance),
icon: const Icon(Icons.monetization_on_outlined),
label: Text('Rembourser ${balance.userName}'),
style: OutlinedButton.styleFrom(
foregroundColor: Colors.green,
side: const BorderSide(color: Colors.green),
),
),
),
],
], ],
), ),
), ),
); );
} }
void _showReimbursementDialog(
BuildContext context,
UserBalance payeeBalance,
) {
final userState = context.read<UserBloc>().state;
if (userState is! user_state.UserLoaded) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Erreur: utilisateur non connecté')),
);
return;
}
final currentUser = userState.user;
// Prevent reimbursing yourself
if (payeeBalance.userId == currentUser.id) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Vous ne pouvez pas vous rembourser vous-même'),
),
);
return;
}
showDialog(
context: context,
builder: (context) => AddExpenseDialog(
group: group,
currentUser: currentUser,
initialCategory: ExpenseCategory.reimbursement,
initialDescription: 'Remboursement',
initialAmount: payeeBalance.absoluteBalance,
initialSplits: {
payeeBalance.userId: payeeBalance
.absoluteBalance, // The payee receives the full amount (as split)
},
),
);
}
} }

View File

@@ -42,185 +42,351 @@ class ExpenseDetailDialog extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Formatters for displaying dates and times. // Formatters for displaying dates and times.
final dateFormat = DateFormat('dd MMMM yyyy'); final dateFormat = DateFormat('dd MMMM yyyy', 'fr_FR');
final timeFormat = DateFormat('HH:mm');
final theme = Theme.of(context);
return BlocBuilder<UserBloc, user_state.UserState>( return BlocBuilder<UserBloc, user_state.UserState>(
builder: (context, userState) { builder: (context, userState) {
// Determine the current user and their permissions. // Determine the current user and their permissions.
final currentUser = userState is user_state.UserLoaded ? userState.user : null; final currentUser = userState is user_state.UserLoaded
? userState.user
: null;
final canEdit = currentUser?.id == expense.paidById; final canEdit = currentUser?.id == expense.paidById;
return Dialog( return Dialog(
backgroundColor: Colors.transparent,
insetPadding: const EdgeInsets.all(16),
child: Container( child: Container(
constraints: const BoxConstraints(maxWidth: 500, maxHeight: 700), constraints: const BoxConstraints(maxWidth: 500, maxHeight: 700),
child: Scaffold( decoration: BoxDecoration(
appBar: AppBar( color: theme.colorScheme.surface,
title: const Text('Détails de la dépense'), borderRadius: BorderRadius.circular(28),
automaticallyImplyLeading: false, boxShadow: [
actions: [ BoxShadow(
if (canEdit) ...[ color: Colors.black.withValues(alpha: 0.2),
// Edit button. blurRadius: 20,
IconButton( offset: const Offset(0, 10),
icon: const Icon(Icons.edit), ),
onPressed: () { ],
Navigator.of(context).pop(); ),
_showEditDialog(context, currentUser!); child: Column(
}, children: [
), // Header with actions
// Delete button. Padding(
IconButton( padding: const EdgeInsets.fromLTRB(24, 20, 16, 0),
icon: const Icon(Icons.delete, color: Colors.red), child: Row(
onPressed: () => _confirmDelete(context), children: [
), Text(
], 'Détails',
// Close button. style: theme.textTheme.titleLarge?.copyWith(
IconButton( fontWeight: FontWeight.bold,
icon: const Icon(Icons.close), ),
onPressed: () => Navigator.of(context).pop(), ),
), const Spacer(),
], if (canEdit) ...[
), IconButton(
body: ListView( icon: const Icon(Icons.edit_outlined),
padding: const EdgeInsets.all(16), tooltip: 'Modifier',
children: [ onPressed: () {
// Header with icon and description. Navigator.of(context).pop();
Center( _showEditDialog(context, currentUser!);
child: Column( },
children: [ ),
Container( IconButton(
width: 80, icon: const Icon(
height: 80, Icons.delete_outline,
decoration: BoxDecoration( color: Colors.red,
color: Colors.blue.withValues(alpha: 0.1),
shape: BoxShape.circle,
), ),
child: Icon( tooltip: 'Supprimer',
expense.category.icon, onPressed: () => _confirmDelete(context),
size: 40, ),
color: Colors.blue, ],
IconButton(
icon: const Icon(Icons.close),
onPressed: () => Navigator.of(context).pop(),
),
],
),
),
Expanded(
child: ListView(
padding: const EdgeInsets.fromLTRB(24, 10, 24, 24),
children: [
// Icon and Category
Center(
child: Column(
children: [
Container(
width: 80,
height: 80,
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer
.withValues(alpha: 0.3),
shape: BoxShape.circle,
),
child: Icon(
expense.category.icon,
size: 36,
color: theme.colorScheme.primary,
),
),
const SizedBox(height: 16),
Text(
expense.description,
style: theme.textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 4),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 6,
),
decoration: BoxDecoration(
color:
theme.colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(20),
),
child: Text(
expense.category.displayName,
style: theme.textTheme.labelMedium?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
),
],
),
),
const SizedBox(height: 32),
// Amount Display
Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: theme.colorScheme.surfaceContainerHighest
.withValues(alpha: 0.3),
borderRadius: BorderRadius.circular(24),
border: Border.all(
color: theme.colorScheme.outline.withValues(
alpha: 0.1,
),
), ),
), ),
const SizedBox(height: 16), child: Column(
children: [
Text(
'Montant total',
style: theme.textTheme.labelLarge?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 8),
Text(
'${expense.amount.toStringAsFixed(2)} ${expense.currency.symbol}',
style: theme.textTheme.displaySmall?.copyWith(
fontWeight: FontWeight.w800,
color: theme.colorScheme.primary,
),
),
if (expense.currency != ExpenseCurrency.eur)
Padding(
padding: const EdgeInsets.only(top: 4),
child: Text(
'${expense.amountInEur.toStringAsFixed(2)}',
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
),
],
),
),
const SizedBox(height: 24),
// Info Grid
Row(
children: [
Expanded(
child: _buildInfoCard(
context,
Icons.person_outline,
'Payé par',
expense.paidByName,
),
),
const SizedBox(width: 12),
Expanded(
child: _buildInfoCard(
context,
Icons.calendar_today_outlined,
'Date',
dateFormat.format(expense.date),
),
),
],
),
const SizedBox(height: 24),
// Splits Section
Text(
'Répartition',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 12),
Container(
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: theme.colorScheme.outline.withValues(
alpha: 0.1,
),
),
),
child: Column(
children: expense.splits.asMap().entries.map((entry) {
final index = entry.key;
final split = entry.value;
final isLast = index == expense.splits.length - 1;
return Column(
children: [
_buildSplitTile(context, split),
if (!isLast)
Divider(
height: 1,
indent: 16,
endIndent: 16,
color: theme.colorScheme.outline.withValues(
alpha: 0.1,
),
),
],
);
}).toList(),
),
),
// Receipt Section
if (expense.receiptUrl != null) ...[
const SizedBox(height: 24),
Text( Text(
expense.description, 'Reçu',
style: const TextStyle( style: theme.textTheme.titleMedium?.copyWith(
fontSize: 24,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
textAlign: TextAlign.center,
), ),
const SizedBox(height: 8), const SizedBox(height: 12),
Text( ClipRRect(
expense.category.displayName, borderRadius: BorderRadius.circular(16),
style: TextStyle( child: Stack(
fontSize: 14, alignment: Alignment.center,
color: Colors.grey[600], children: [
Image.network(
expense.receiptUrl!,
width: double.infinity,
height: 200,
fit: BoxFit.cover,
loadingBuilder:
(context, child, loadingProgress) {
if (loadingProgress == null) return child;
return Container(
height: 200,
color: theme
.colorScheme
.surfaceContainerHighest,
child: const Center(
child: CircularProgressIndicator(),
),
);
},
errorBuilder: (context, error, stackTrace) {
return Container(
height: 200,
color: theme
.colorScheme
.surfaceContainerHighest,
child: const Center(
child: Icon(Icons.broken_image_outlined),
),
);
},
),
Positioned.fill(
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () {
showDialog(
context: context,
builder: (context) => Dialog(
backgroundColor: Colors.transparent,
insetPadding: EdgeInsets.zero,
child: Stack(
alignment: Alignment.center,
children: [
InteractiveViewer(
minScale: 0.5,
maxScale: 4.0,
child: Image.network(
expense.receiptUrl!,
fit: BoxFit.contain,
),
),
Positioned(
top: 40,
right: 20,
child: IconButton(
icon: const Icon(
Icons.close,
color: Colors.white,
size: 30,
),
onPressed: () => Navigator.of(
context,
).pop(),
),
),
],
),
),
);
},
),
),
),
],
), ),
), ),
], ],
),
),
const SizedBox(height: 24),
// Amount card. // Archive Button
Card( if (!expense.isArchived && canEdit) ...[
child: Padding( const SizedBox(height: 32),
padding: const EdgeInsets.all(16), SizedBox(
child: Column( width: double.infinity,
children: [ child: OutlinedButton.icon(
Text( onPressed: () => _confirmArchive(context),
'${expense.amount.toStringAsFixed(2)} ${expense.currency.symbol}', icon: const Icon(Icons.archive_outlined),
style: const TextStyle( label: const Text('Archiver cette dépense'),
fontSize: 32, style: OutlinedButton.styleFrom(
fontWeight: FontWeight.bold, padding: const EdgeInsets.symmetric(vertical: 16),
color: Colors.green, shape: RoundedRectangleBorder(
), borderRadius: BorderRadius.circular(12),
),
if (expense.currency != ExpenseCurrency.eur)
Text(
'${expense.amountInEur.toStringAsFixed(2)}',
style: TextStyle(
fontSize: 16,
color: Colors.grey[600],
), ),
), ),
], ),
), ),
), ],
],
), ),
const SizedBox(height: 16), ),
],
// Information rows.
_buildInfoRow(Icons.person, 'Payé par', expense.paidByName),
_buildInfoRow(Icons.calendar_today, 'Date', dateFormat.format(expense.date)),
_buildInfoRow(Icons.access_time, 'Heure', timeFormat.format(expense.createdAt)),
if (expense.isEdited && expense.editedAt != null)
_buildInfoRow(
Icons.edit,
'Modifié le',
dateFormat.format(expense.editedAt!),
),
const SizedBox(height: 16),
const Divider(),
const SizedBox(height: 8),
// Splits section.
const Text(
'Répartition',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 12),
...expense.splits.map((split) => _buildSplitTile(context, split)),
const SizedBox(height: 16),
// Receipt section.
if (expense.receiptUrl != null) ...[
const Divider(),
const SizedBox(height: 8),
const Text(
'Reçu',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 12),
ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Image.network(
expense.receiptUrl!,
fit: BoxFit.cover,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return const Center(child: CircularProgressIndicator());
},
errorBuilder: (context, error, stackTrace) {
return const Center(
child: Text('Erreur de chargement de l\'image'),
);
},
),
),
],
const SizedBox(height: 16),
// Archive button.
if (!expense.isArchived && canEdit)
OutlinedButton.icon(
onPressed: () => _confirmArchive(context),
icon: const Icon(Icons.archive),
label: const Text('Archiver cette dépense'),
),
],
),
), ),
), ),
); );
@@ -228,83 +394,135 @@ class ExpenseDetailDialog extends StatelessWidget {
); );
} }
/// Builds a row displaying an icon, a label, and a value. Widget _buildInfoCard(
Widget _buildInfoRow(IconData icon, String label, String value) { BuildContext context,
return Padding( IconData icon,
padding: const EdgeInsets.symmetric(vertical: 8), String label,
child: Row( String value,
) {
final theme = Theme.of(context);
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: theme.colorScheme.outline.withValues(alpha: 0.1),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Icon(icon, size: 20, color: Colors.grey[600]), Row(
const SizedBox(width: 12), children: [
Text( Icon(icon, size: 16, color: theme.colorScheme.onSurfaceVariant),
label, const SizedBox(width: 8),
style: TextStyle( Text(
fontSize: 14, label,
color: Colors.grey[600], style: theme.textTheme.labelMedium?.copyWith(
), color: theme.colorScheme.onSurfaceVariant,
),
),
],
), ),
const Spacer(), const SizedBox(height: 8),
Text( Text(
value, value,
style: const TextStyle( style: theme.textTheme.bodyLarge?.copyWith(
fontSize: 14, fontWeight: FontWeight.w600,
fontWeight: FontWeight.w500,
), ),
maxLines: 1,
overflow: TextOverflow.ellipsis,
), ),
], ],
), ),
); );
} }
/// Builds a tile displaying details about a split in the expense.
///
/// The tile shows the user's name, the split amount, and whether the split is paid. If the current user
/// is responsible for the split and it is unpaid, a button is provided to mark it as paid.
Widget _buildSplitTile(BuildContext context, ExpenseSplit split) { Widget _buildSplitTile(BuildContext context, ExpenseSplit split) {
return BlocBuilder<UserBloc, user_state.UserState>( return BlocBuilder<UserBloc, user_state.UserState>(
builder: (context, userState) { builder: (context, userState) {
final currentUser = userState is user_state.UserLoaded ? userState.user : null; final currentUser = userState is user_state.UserLoaded
? userState.user
: null;
final isCurrentUser = currentUser?.id == split.userId; final isCurrentUser = currentUser?.id == split.userId;
final theme = Theme.of(context);
return ListTile( return Padding(
leading: CircleAvatar( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
backgroundColor: split.isPaid ? Colors.green : Colors.orange, child: Row(
child: Icon(
split.isPaid ? Icons.check : Icons.pending,
color: Colors.white,
size: 20,
),
),
title: Text(
split.userName,
style: TextStyle(
fontWeight: isCurrentUser ? FontWeight.bold : FontWeight.normal,
),
),
subtitle: Text(split.isPaid ? 'Payé' : 'En attente'),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [ children: [
Text( Container(
'${split.amount.toStringAsFixed(2)}', width: 40,
style: const TextStyle( height: 40,
fontSize: 16, decoration: BoxDecoration(
fontWeight: FontWeight.bold, color: split.isPaid
? Colors.green.withValues(alpha: 0.1)
: Colors.orange.withValues(alpha: 0.1),
shape: BoxShape.circle,
),
child: Icon(
split.isPaid ? Icons.check : Icons.access_time_rounded,
color: split.isPaid ? Colors.green : Colors.orange,
size: 20,
), ),
), ),
if (!split.isPaid && isCurrentUser) ...[ const SizedBox(width: 12),
const SizedBox(width: 8), Expanded(
IconButton( child: Column(
icon: const Icon(Icons.check_circle, color: Colors.green), crossAxisAlignment: CrossAxisAlignment.start,
onPressed: () { children: [
context.read<ExpenseBloc>().add(MarkSplitAsPaid( Text(
expenseId: expense.id, isCurrentUser ? 'Moi' : split.userName,
userId: split.userId, style: theme.textTheme.bodyLarge?.copyWith(
)); fontWeight: isCurrentUser
Navigator.of(context).pop(); ? FontWeight.bold
}, : FontWeight.w500,
),
),
Text(
split.isPaid ? 'Payé' : 'En attente',
style: theme.textTheme.bodySmall?.copyWith(
color: split.isPaid ? Colors.green : Colors.orange,
fontWeight: FontWeight.w500,
),
),
],
), ),
], ),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'${split.amount.toStringAsFixed(2)}',
style: theme.textTheme.bodyLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
if (!split.isPaid && isCurrentUser)
GestureDetector(
onTap: () {
context.read<ExpenseBloc>().add(
MarkSplitAsPaid(
expenseId: expense.id,
userId: split.userId,
),
);
Navigator.of(context).pop();
},
child: Padding(
padding: const EdgeInsets.only(top: 4),
child: Text(
'Marquer payé',
style: theme.textTheme.labelSmall?.copyWith(
color: theme.colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
], ],
), ),
); );
@@ -312,7 +530,6 @@ class ExpenseDetailDialog extends StatelessWidget {
); );
} }
/// Shows a dialog for editing the expense.
void _showEditDialog(BuildContext context, user_state.UserModel currentUser) { void _showEditDialog(BuildContext context, user_state.UserModel currentUser) {
showDialog( showDialog(
context: context, context: context,
@@ -327,13 +544,14 @@ class ExpenseDetailDialog extends StatelessWidget {
); );
} }
/// Shows a confirmation dialog for deleting the expense.
void _confirmDelete(BuildContext context) { void _confirmDelete(BuildContext context) {
showDialog( showDialog(
context: context, context: context,
builder: (dialogContext) => AlertDialog( builder: (dialogContext) => AlertDialog(
title: const Text('Supprimer la dépense'), title: const Text('Supprimer la dépense'),
content: const Text('Êtes-vous sûr de vouloir supprimer cette dépense ?'), content: const Text(
'Êtes-vous sûr de vouloir supprimer cette dépense ?',
),
actions: [ actions: [
TextButton( TextButton(
onPressed: () => Navigator.of(dialogContext).pop(), onPressed: () => Navigator.of(dialogContext).pop(),
@@ -341,9 +559,7 @@ class ExpenseDetailDialog extends StatelessWidget {
), ),
TextButton( TextButton(
onPressed: () { onPressed: () {
context.read<ExpenseBloc>().add(DeleteExpense( context.read<ExpenseBloc>().add(DeleteExpense(expense.id));
expense.id,
));
Navigator.of(dialogContext).pop(); Navigator.of(dialogContext).pop();
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
@@ -355,13 +571,14 @@ class ExpenseDetailDialog extends StatelessWidget {
); );
} }
/// Shows a confirmation dialog for archiving the expense.
void _confirmArchive(BuildContext context) { void _confirmArchive(BuildContext context) {
showDialog( showDialog(
context: context, context: context,
builder: (dialogContext) => AlertDialog( builder: (dialogContext) => AlertDialog(
title: const Text('Archiver la dépense'), title: const Text('Archiver la dépense'),
content: const Text('Cette dépense sera archivée et n\'apparaîtra plus dans les calculs de balance.'), content: const Text(
'Cette dépense sera archivée et n\'apparaîtra plus dans les calculs de balance.',
),
actions: [ actions: [
TextButton( TextButton(
onPressed: () => Navigator.of(dialogContext).pop(), onPressed: () => Navigator.of(dialogContext).pop(),
@@ -369,9 +586,7 @@ class ExpenseDetailDialog extends StatelessWidget {
), ),
TextButton( TextButton(
onPressed: () { onPressed: () {
context.read<ExpenseBloc>().add(ArchiveExpense( context.read<ExpenseBloc>().add(ArchiveExpense(expense.id));
expense.id,
));
Navigator.of(dialogContext).pop(); Navigator.of(dialogContext).pop();
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },

View File

@@ -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,159 @@ 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;
case ExpenseCategory.reimbursement:
return Colors.green;
}
}
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,
),
); );
} }
} }

View File

@@ -13,7 +13,9 @@ 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';
import '../../services/error_service.dart';
class GroupExpensesPage extends StatefulWidget { class GroupExpensesPage extends StatefulWidget {
final Account account; final Account account;
@@ -31,13 +33,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();
} }
@@ -57,111 +60,254 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
@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: [],
), ),
body: MultiBlocListener( body: MultiBlocListener(
listeners: [ listeners: [
BlocListener<ExpenseBloc, ExpenseState>( BlocListener<ExpenseBloc, ExpenseState>(
listener: (context, state) { listener: (context, state) {
if (state is ExpenseOperationSuccess) { if (state is ExpenseOperationSuccess) {
ScaffoldMessenger.of(context).showSnackBar( ErrorService().showSnackbar(
SnackBar( message: state.message,
content: Text(state.message), isError: false,
backgroundColor: Colors.green,
),
); );
_loadData(); // Recharger les données après une opération _loadData(); // Recharger les données après une opération
} else if (state is ExpenseError) { } else if (state is ExpenseError) {
ScaffoldMessenger.of(context).showSnackBar( ErrorService().showError(message: state.message);
SnackBar( } else if (state is ExpensesLoaded) {
content: Text(state.message), // Rafraîchir les balances quand les dépenses changent (ex: via stream)
backgroundColor: Colors.red, 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,
group: widget.group,
);
} else if (state is BalanceError) {
return _buildErrorState('Erreur: ${state.message}');
}
return _buildEmptyState('Aucune balance disponible');
},
),
],
),
), ),
], ],
), ),
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
heroTag: 'group_expenses_fab',
onPressed: _showAddExpenseDialog, onPressed: _showAddExpenseDialog,
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 +317,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 +332,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 +352,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 +365,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,
), ),
], ],
@@ -247,18 +379,11 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
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( ErrorService().showError(message: 'Erreur: utilisateur non connecté');
const SnackBar(
content: Text('Erreur: utilisateur non connecté'),
backgroundColor: Colors.red,
),
);
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,322 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../services/map_navigation_service.dart';
import '../../models/activity.dart';
class ActivityDetailDialog extends StatelessWidget {
final Activity activity;
const ActivityDetailDialog({super.key, required this.activity});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
// final isDarkMode = theme.brightness == Brightness.dark;
// Traduction de la catégorie
String categoryDisplay = activity.category;
final categoryEnum = ActivityCategory.values.firstWhere(
(e) => e.name == activity.category,
orElse: () => ActivityCategory.attraction, // Fallback
);
categoryDisplay = categoryEnum.displayName;
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
backgroundColor: theme.scaffoldBackgroundColor,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Image header
if (activity.imageUrl != null && activity.imageUrl!.isNotEmpty)
ClipRRect(
borderRadius: const BorderRadius.vertical(
top: Radius.circular(16),
),
child: Image.network(
activity.imageUrl!,
height: 200,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) => Container(
height: 100,
color: Colors.grey[300],
child: const Icon(Icons.image_not_supported, size: 50),
),
),
),
Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Titre et Catégorie
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
activity.name,
style: theme.textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 5,
),
decoration: BoxDecoration(
color: theme.colorScheme.primary.withValues(
alpha: 0.1,
),
borderRadius: BorderRadius.circular(20),
),
child: Text(
categoryDisplay,
style: TextStyle(
color: theme.colorScheme.primary,
fontWeight: FontWeight.bold,
fontSize: 12,
),
),
),
],
),
const SizedBox(height: 16),
// Date
if (activity.date != null) ...[
Row(
children: [
Icon(
Icons.calendar_today,
size: 20,
color: Colors.grey[600],
),
const SizedBox(width: 8),
Text(
DateFormat(
'EEEE d MMMM yyyy',
'fr_FR',
).format(activity.date!),
style: theme.textTheme.bodyMedium,
),
],
),
const SizedBox(height: 16),
],
// Heures d'ouverture
if (activity.openingHours.isNotEmpty) ...[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
Icons.access_time,
size: 20,
color: Colors.grey[600],
),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: activity.openingHours
.map(
(hour) => Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Text(
hour,
style: theme.textTheme.bodyMedium,
),
),
)
.toList(),
),
),
],
),
const SizedBox(height: 16),
],
// Adresse
if (activity.address != null) ...[
Row(
children: [
Icon(
Icons.location_on,
size: 20,
color: Colors.grey[600],
),
const SizedBox(width: 8),
Expanded(
child: Text(
activity.address!,
style: theme.textTheme.bodyMedium,
),
),
],
),
const SizedBox(height: 16),
],
// Description
if (activity.description.isNotEmpty) ...[
Text(
'Description',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Text(
activity.description,
style: theme.textTheme.bodyMedium,
),
const SizedBox(height: 16),
],
// Votes
if (activity.votes.isNotEmpty) ...[
const Divider(),
const SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_buildVoteStat(
Icons.thumb_up,
Colors.green,
activity.positiveVotes,
'Pour',
),
_buildVoteStat(
Icons.thumb_down,
Colors.red,
activity.negativeVotes,
'Contre',
),
],
),
],
],
),
),
// Boutons
Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
if (activity.latitude != null && activity.longitude != null)
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ElevatedButton.icon(
onPressed: () {
// Déclencher la navigation
context
.read<MapNavigationService>()
.navigateToLocation(
activity.latitude!,
activity.longitude!,
name: activity.name,
);
// Revenir à la page d'accueil (fermer le dialog et les pages empilées comme ActivitiesPage)
Navigator.of(
context,
).popUntil((route) => route.isFirst);
},
icon: const Icon(Icons.map_outlined),
label: const Text('Voir sur la carte de l\'app'),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
vertical: 12,
horizontal: 24,
),
backgroundColor:
theme.colorScheme.secondaryContainer,
foregroundColor:
theme.colorScheme.onSecondaryContainer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
const SizedBox(height: 8),
ElevatedButton.icon(
onPressed: () async {
final url = Uri.parse(
'https://www.google.com/maps/search/?api=1&query=${activity.latitude},${activity.longitude}',
);
if (await canLaunchUrl(url)) {
await launchUrl(
url,
mode: LaunchMode.externalApplication,
);
}
},
icon: const Icon(Icons.map),
label: const Text('Voir sur Google Maps'),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
vertical: 12,
horizontal: 24,
),
backgroundColor:
theme.colorScheme.primaryContainer,
foregroundColor:
theme.colorScheme.onPrimaryContainer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
],
),
),
ElevatedButton(
onPressed: () => Navigator.pop(context),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
minimumSize: const Size(double.infinity, 45),
),
child: const Text('Fermer'),
),
],
),
),
],
),
),
);
}
Widget _buildVoteStat(IconData icon, Color color, int count, String label) {
return Column(
children: [
Icon(icon, color: color),
const SizedBox(height: 4),
Text(
'$count',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: color,
),
),
Text(label, style: const TextStyle(fontSize: 12, color: Colors.grey)),
],
);
}
}

View File

@@ -1,5 +1,6 @@
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 'package:firebase_auth/firebase_auth.dart';
import 'dart:math' as math; import 'dart:math' as math;
import '../../blocs/activity/activity_bloc.dart'; import '../../blocs/activity/activity_bloc.dart';
import '../../blocs/activity/activity_event.dart'; import '../../blocs/activity/activity_event.dart';
@@ -25,6 +26,7 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
final ErrorService _errorService = ErrorService(); final ErrorService _errorService = ErrorService();
ActivityCategory _selectedCategory = ActivityCategory.attraction; ActivityCategory _selectedCategory = ActivityCategory.attraction;
DateTime? _selectedDate;
bool _isLoading = false; bool _isLoading = false;
@override @override
@@ -57,7 +59,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),
), ),
), ),
@@ -149,6 +151,13 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
icon: Icons.location_on, icon: Icons.location_on,
), ),
const SizedBox(height: 20),
// Date et heure (optionnel)
_buildSectionTitle('Date et heure (optionnel)'),
const SizedBox(height: 8),
_buildDateTimePicker(),
const SizedBox(height: 40), const SizedBox(height: 40),
// Boutons d'action // Boutons d'action
@@ -368,6 +377,8 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
votes: {}, votes: {},
createdAt: DateTime.now(), createdAt: DateTime.now(),
updatedAt: DateTime.now(), updatedAt: DateTime.now(),
date: _selectedDate,
createdBy: FirebaseAuth.instance.currentUser?.uid,
); );
context.read<ActivityBloc>().add(AddActivity(activity)); context.read<ActivityBloc>().add(AddActivity(activity));
@@ -412,4 +423,92 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
return Icons.spa; return Icons.spa;
} }
} }
Widget _buildDateTimePicker() {
final theme = Theme.of(context);
final isDarkMode = theme.brightness == Brightness.dark;
return InkWell(
onTap: _pickDateTime,
borderRadius: BorderRadius.circular(12),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: isDarkMode
? Colors.white.withValues(alpha: 0.2)
: Colors.black.withValues(alpha: 0.2),
),
),
child: Row(
children: [
Icon(
Icons.calendar_today,
color: theme.colorScheme.onSurface.withValues(alpha: 0.6),
),
const SizedBox(width: 12),
Text(
_selectedDate != null
? '${_selectedDate!.day}/${_selectedDate!.month}/${_selectedDate!.year} à ${_selectedDate!.hour}:${_selectedDate!.minute.toString().padLeft(2, '0')}'
: 'Choisir une date et une heure',
style: theme.textTheme.bodyMedium?.copyWith(
color: _selectedDate != null
? theme.colorScheme.onSurface
: theme.colorScheme.onSurface.withValues(alpha: 0.6),
),
),
const Spacer(),
if (_selectedDate != null)
IconButton(
icon: const Icon(Icons.clear, size: 20),
onPressed: () {
setState(() {
_selectedDate = null;
});
},
padding: EdgeInsets.zero,
constraints: const BoxConstraints(),
),
],
),
),
);
}
Future<void> _pickDateTime() async {
final now = DateTime.now();
final initialDate = widget.trip.startDate.isAfter(now)
? widget.trip.startDate
: now;
final date = await showDatePicker(
context: context,
initialDate: _selectedDate ?? initialDate,
firstDate: now.subtract(const Duration(days: 365)),
lastDate: now.add(const Duration(days: 365 * 2)),
);
if (date == null) return;
if (!mounted) return;
final time = await showTimePicker(
context: context,
initialTime: TimeOfDay.fromDateTime(_selectedDate ?? now),
);
if (time == null) return;
setState(() {
_selectedDate = DateTime(
date.year,
date.month,
date.day,
time.hour,
time.minute,
);
});
}
} }

View File

@@ -79,11 +79,7 @@ class ErrorContent extends StatelessWidget {
color: defaultIconColor?.withValues(alpha: 0.1), color: defaultIconColor?.withValues(alpha: 0.1),
shape: BoxShape.circle, shape: BoxShape.circle,
), ),
child: Icon( child: Icon(icon, size: 48, color: defaultIconColor),
icon,
size: 48,
color: defaultIconColor,
),
), ),
const SizedBox(height: 24), const SizedBox(height: 24),
@@ -167,9 +163,7 @@ void showErrorDialog(
barrierDismissible: barrierDismissible, barrierDismissible: barrierDismissible,
builder: (BuildContext dialogContext) { builder: (BuildContext dialogContext) {
return Dialog( return Dialog(
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
borderRadius: BorderRadius.circular(16),
),
child: ErrorContent( child: ErrorContent(
title: title, title: title,
message: message, message: message,
@@ -187,70 +181,3 @@ void showErrorDialog(
}, },
); );
} }
// Fonction helper pour afficher l'erreur en bottom sheet
void showErrorBottomSheet(
BuildContext context, {
String title = 'Une erreur est survenue',
required String message,
VoidCallback? onRetry,
IconData icon = Icons.error_outline,
Color? iconColor,
bool isDismissible = true,
}) {
showModalBottomSheet(
context: context,
isDismissible: isDismissible,
enableDrag: isDismissible,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
builder: (BuildContext sheetContext) {
return SafeArea(
child: Padding(
padding: const EdgeInsets.all(16),
child: ErrorContent(
title: title,
message: message,
icon: icon,
iconColor: iconColor,
onRetry: onRetry != null
? () {
Navigator.of(sheetContext).pop();
onRetry();
}
: null,
onClose: () => Navigator.of(sheetContext).pop(),
),
),
);
},
);
}
// Fonction helper pour afficher en SnackBar (pour erreurs mineures)
void showErrorSnackBar(
BuildContext context, {
required String message,
VoidCallback? onRetry,
Duration duration = const Duration(seconds: 4),
}) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: Colors.red[400],
duration: duration,
action: onRetry != null
? SnackBarAction(
label: 'Réessayer',
textColor: Colors.white,
onPressed: onRetry,
)
: null,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
);
}

View File

@@ -1,12 +1,16 @@
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';
import '../../services/error_service.dart';
/// Chat group content widget for group messaging functionality. /// Chat group content widget for group messaging functionality.
/// ///
@@ -28,10 +32,7 @@ class ChatGroupContent extends StatefulWidget {
/// ///
/// 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();
@@ -47,17 +48,36 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
/// 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();
} }
@@ -76,23 +96,23 @@ 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();
@@ -132,32 +152,29 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
/// [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
@@ -183,7 +200,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,
),
), ),
], ],
), ),
@@ -201,12 +221,7 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
child: BlocConsumer<MessageBloc, MessageState>( child: BlocConsumer<MessageBloc, MessageState>(
listener: (context, state) { listener: (context, state) {
if (state is MessageError) { if (state is MessageError) {
ScaffoldMessenger.of(context).showSnackBar( ErrorService().showError(message: state.message);
SnackBar(
content: Text(state.message),
backgroundColor: Colors.red,
),
);
} }
}, },
builder: (context, state) { builder: (context, state) {
@@ -235,7 +250,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 +259,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 +282,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,
@@ -299,7 +322,9 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
? '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,
@@ -309,16 +334,21 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
vertical: 12, vertical: 12,
), ),
), ),
maxLines: null, maxLines: 5,
minLines: 1,
textCapitalization: TextCapitalization.sentences, textCapitalization: TextCapitalization.sentences,
), ),
), ),
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 +371,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,7 +389,12 @@ 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;
@@ -381,76 +406,139 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
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.cast<GroupMember?>().firstWhere(
(m) => m?.userId == message.senderId,
orElse: () => null,
);
// 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),
),
), ),
),
], ],
), ),
), ),
@@ -497,7 +585,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 +597,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 +637,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 +741,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 +803,80 @@ 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
ErrorService().showSnackbar(
message: 'Pseudo modifié en "$newPseudo"',
isError: false,
);
}
} catch (e) {
if (mounted) {
ErrorService().showError(
message: 'Erreur lors de la modification du pseudo: $e',
);
}
}
}
} }

View File

@@ -1,6 +1,6 @@
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 'package:travel_mate/components/error/error_content.dart'; import '../../services/error_service.dart';
import 'package:travel_mate/components/group/chat_group_content.dart'; import 'package:travel_mate/components/group/chat_group_content.dart';
import 'package:travel_mate/components/widgets/user_state_widget.dart'; import 'package:travel_mate/components/widgets/user_state_widget.dart';
import '../../blocs/user/user_bloc.dart'; import '../../blocs/user/user_bloc.dart';
@@ -50,19 +50,12 @@ class _GroupContentState extends State<GroupContent> {
return BlocConsumer<GroupBloc, GroupState>( return BlocConsumer<GroupBloc, GroupState>(
listener: (context, groupState) { listener: (context, groupState) {
if (groupState is GroupOperationSuccess) { if (groupState is GroupOperationSuccess) {
ScaffoldMessenger.of(context).showSnackBar( ErrorService().showSnackbar(
SnackBar( message: groupState.message,
content: Text(groupState.message), isError: false,
backgroundColor: Colors.green,
),
); );
} else if (groupState is GroupError) { } else if (groupState is GroupError) {
ScaffoldMessenger.of(context).showSnackBar( ErrorService().showError(message: groupState.message);
SnackBar(
content: Text(groupState.message),
backgroundColor: Colors.red,
),
);
} }
}, },
builder: (context, groupState) { builder: (context, groupState) {
@@ -127,17 +120,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 +137,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';
} }
@@ -223,8 +202,7 @@ class _GroupContentState extends State<GroupContent> {
if (mounted) { if (mounted) {
if (retry) { if (retry) {
if (userId == '') { if (userId == '') {
showErrorDialog( ErrorService().showError(
context,
title: 'Erreur utilisateur', title: 'Erreur utilisateur',
message: 'Utilisateur non connecté. Veuillez vous reconnecter.', message: 'Utilisateur non connecté. Veuillez vous reconnecter.',
icon: Icons.error, icon: Icons.error,
@@ -234,8 +212,7 @@ class _GroupContentState extends State<GroupContent> {
}, },
); );
} else { } else {
showErrorDialog( ErrorService().showError(
context,
title: 'Erreur de chargement', title: 'Erreur de chargement',
message: error, message: error,
icon: Icons.cloud_off, icon: Icons.cloud_off,
@@ -246,8 +223,7 @@ class _GroupContentState extends State<GroupContent> {
); );
} }
} else { } else {
showErrorDialog( ErrorService().showError(
context,
title: 'Erreur', title: 'Erreur',
message: error, message: error,
icon: Icons.error, icon: Icons.error,

View File

@@ -0,0 +1,487 @@
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';
import '../../../repositories/user_repository.dart';
import '../../../models/user.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;
final CalendarFormat _calendarFormat = CalendarFormat.week;
@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);
final isDarkMode = theme.brightness == Brightness.dark;
return Scaffold(
backgroundColor: isDarkMode
? theme.scaffoldBackgroundColor
: Colors.white,
appBar: AppBar(
title: Text(
widget.trip.title,
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
centerTitle: true,
backgroundColor: Colors.transparent,
elevation: 0,
leading: IconButton(
icon: Icon(Icons.arrow_back_ios, color: theme.colorScheme.onSurface),
onPressed: () => Navigator.pop(context),
),
actions: [
IconButton(
icon: Icon(Icons.people, color: theme.colorScheme.onSurface),
onPressed: () => _showParticipantsDialog(context),
),
],
),
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
}
// 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,
);
// Sort by time
selectedActivities.sort((a, b) => a.date!.compareTo(b.date!));
return Column(
children: [
// Calendar Strip
Container(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: isDarkMode ? theme.cardColor : Colors.grey[100],
borderRadius: BorderRadius.circular(12),
),
child: TableCalendar(
firstDay: DateTime.now().subtract(const Duration(days: 365)),
lastDay: DateTime.now().add(const Duration(days: 365)),
focusedDay: _focusedDay,
calendarFormat: _calendarFormat,
headerStyle: HeaderStyle(
formatButtonVisible: false,
titleCentered: true,
titleTextStyle: theme.textTheme.titleLarge!.copyWith(
fontWeight: FontWeight.bold,
),
leftChevronIcon: const Icon(Icons.chevron_left),
rightChevronIcon: const Icon(Icons.chevron_right),
),
calendarStyle: CalendarStyle(
todayDecoration: BoxDecoration(
color: Colors.blue.withValues(alpha: 0.3),
shape: BoxShape.circle,
),
selectedDecoration: const BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle,
),
markerDecoration: const BoxDecoration(
color: Colors.purple,
shape: BoxShape.circle,
),
),
selectedDayPredicate: (day) {
return isSameDay(_selectedDay, day);
},
onDaySelected: (selectedDay, focusedDay) {
setState(() {
_selectedDay = selectedDay;
_focusedDay = focusedDay;
});
},
onPageChanged: (focusedDay) {
_focusedDay = focusedDay;
},
eventLoader: (day) {
return _getActivitiesForDay(day, scheduledActivities);
},
),
),
const SizedBox(height: 16),
// Timeline View
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Timeline
if (selectedActivities.isEmpty)
Padding(
padding: const EdgeInsets.symmetric(vertical: 32),
child: Center(
child: Text(
'Aucune activité prévue ce jour',
style: theme.textTheme.bodyLarge?.copyWith(
color: theme.colorScheme.onSurface.withValues(
alpha: 0.5,
),
),
),
),
)
else
...selectedActivities.map((activity) {
return _buildTimelineItem(activity, theme);
}),
const SizedBox(height: 32),
// Unscheduled Activities Section
Text(
'Activités à ajouter',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
if (unscheduledActivities.isEmpty)
Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: Text(
'Toutes les activités sont planifiées !',
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withValues(
alpha: 0.5,
),
),
),
)
else
...unscheduledActivities.map((activity) {
return _buildUnscheduledActivityCard(activity, theme);
}),
const SizedBox(height: 32),
],
),
),
),
],
);
},
),
);
}
Widget _buildTimelineItem(Activity activity, ThemeData theme) {
final timeFormat = DateFormat('HH:mm'); // 10:00
final endTimeFormat = DateFormat('HH:mm'); // 11:30 (simulated duration)
// Simulate duration (1h30)
final endTime = activity.date!.add(const Duration(hours: 1, minutes: 30));
return IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Time Column
SizedBox(
width: 50,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${activity.date!.hour}h',
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withValues(alpha: 0.5),
),
),
],
),
),
// Timeline Line
// Expanded(child: Container()), // Placeholder for line if needed
// Activity Card
Expanded(
child: Container(
margin: const EdgeInsets.only(bottom: 24),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: _getCategoryColor(
activity.category,
).withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
border: Border(
left: BorderSide(
color: _getCategoryColor(activity.category),
width: 4,
),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
activity.name,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.onSurface,
),
),
const SizedBox(height: 4),
Text(
'${timeFormat.format(activity.date!)} - ${endTimeFormat.format(endTime)}',
style: theme.textTheme.bodyMedium?.copyWith(
color: _getCategoryColor(activity.category),
fontWeight: FontWeight.w500,
),
),
],
),
),
),
],
),
);
}
Widget _buildUnscheduledActivityCard(Activity activity, ThemeData theme) {
return Container(
margin: const EdgeInsets.only(bottom: 12),
decoration: BoxDecoration(
color: theme.cardColor,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: ListTile(
contentPadding: const EdgeInsets.all(16),
leading: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: _getCategoryColor(activity.category).withValues(alpha: 0.1),
shape: BoxShape.circle,
),
child: Icon(
_getCategoryIcon(activity.category),
color: _getCategoryColor(activity.category),
),
),
title: Text(
activity.name,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
subtitle: Text(
activity.category,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withValues(alpha: 0.6),
),
),
trailing: IconButton(
icon: const Icon(Icons.grid_view), // Drag handle icon
onPressed: () {
if (_selectedDay != null) {
_selectTimeAndSchedule(activity, _selectedDay!);
}
},
),
),
);
}
Color _getCategoryColor(String category) {
// Simple mapping based on category name
// You might want to use the enum if possible, but category is String in Activity model
if (category.toLowerCase().contains('musée') ||
category.toLowerCase().contains('museum')) {
return Colors.blue;
}
if (category.toLowerCase().contains('restaurant') ||
category.toLowerCase().contains('food')) {
return Colors.orange;
}
if (category.toLowerCase().contains('nature') ||
category.toLowerCase().contains('park')) {
return Colors.green;
}
if (category.toLowerCase().contains('photo') ||
category.toLowerCase().contains('attraction')) {
return Colors.purple;
}
if (category.toLowerCase().contains('détente') ||
category.toLowerCase().contains('relax')) {
return Colors.pink;
}
return Colors.teal;
}
IconData _getCategoryIcon(String category) {
if (category.toLowerCase().contains('musée')) return Icons.museum;
if (category.toLowerCase().contains('restaurant')) return Icons.restaurant;
if (category.toLowerCase().contains('nature')) return Icons.nature;
if (category.toLowerCase().contains('photo')) return Icons.camera_alt;
if (category.toLowerCase().contains('détente')) {
return Icons.icecream; // Gelato icon :)
}
return Icons.place;
}
void _showParticipantsDialog(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Participants'),
content: SizedBox(
width: double.maxFinite,
child: FutureBuilder<List<User>>(
future: UserRepository().getUsersByIds([
...widget.trip.participants,
widget.trip.createdBy,
]),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
return const Center(child: Text('Erreur de chargement'));
}
final users = snapshot.data ?? [];
if (users.isEmpty) {
return const Center(child: Text('Aucun participant trouvé'));
}
return ListView.builder(
shrinkWrap: true,
itemCount: users.length,
itemBuilder: (context, index) {
final user = users[index];
final isCreator = user.id == widget.trip.createdBy;
return ListTile(
leading: CircleAvatar(
backgroundImage: user.profilePictureUrl != null
? NetworkImage(user.profilePictureUrl!)
: null,
child: user.profilePictureUrl == null
? Text(
'${user.prenom.isNotEmpty ? user.prenom[0] : ''}${user.nom.isNotEmpty ? user.nom[0] : ''}'
.toUpperCase(),
)
: null,
),
title: Text(user.fullName),
subtitle: isCreator ? const Text('Organisateur') : null,
);
},
);
},
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Fermer'),
),
],
),
);
}
}

View File

@@ -0,0 +1,59 @@
void _showParticipantsDialog(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Participants'),
content: SizedBox(
width: double.maxFinite,
child: FutureBuilder<List<User>>(
future: UserRepository().getUsersByIds([
...widget.trip.participants,
widget.trip.createdBy,
]),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
return const Center(child: Text('Erreur de chargement'));
}
final users = snapshot.data ?? [];
if (users.isEmpty) {
return const Center(child: Text('Aucun participant trouvé'));
}
return ListView.builder(
shrinkWrap: true,
itemCount: users.length,
itemBuilder: (context, index) {
final user = users[index];
final isCreator = user.id == widget.trip.createdBy;
return ListTile(
leading: CircleAvatar(
backgroundImage: user.photoUrl != null
? NetworkImage(user.photoUrl!)
: null,
child: user.photoUrl == null
? Text(user.initials)
: null,
),
title: Text(user.fullName),
subtitle: isCreator ? const Text('Organisateur') : null,
);
},
);
},
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Fermer'),
),
],
),
);
}

View File

@@ -1,3 +1,4 @@
import 'dart:io';
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
@@ -17,10 +18,13 @@ 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';
import '../../firebase_options.dart';
/// Create trip content widget for trip creation and editing functionality. /// Create trip content widget for trip creation and editing functionality.
/// ///
@@ -45,10 +49,7 @@ class CreateTripContent extends StatefulWidget {
/// 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();
@@ -71,6 +72,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
/// 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();
@@ -84,7 +86,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
String? _selectedImageUrl; String? _selectedImageUrl;
/// Google Maps API key for location services /// Google Maps API key for location services
static final String _apiKey = dotenv.env['GOOGLE_MAPS_API_KEY'] ?? ''; static String get _apiKey {
return DefaultFirebaseOptions.currentPlatform.apiKey;
}
/// Participant management /// Participant management
final List<String> _participants = []; final List<String> _participants = [];
@@ -123,7 +127,11 @@ class _CreateTripContentState extends State<CreateTripContent> {
} }
} }
bool _isProgrammaticUpdate = false;
void _onLocationChanged() { void _onLocationChanged() {
if (_isProgrammaticUpdate) return;
final query = _locationController.text.trim(); final query = _locationController.text.trim();
if (query.length < 2) { if (query.length < 2) {
@@ -149,7 +157,7 @@ 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);
@@ -203,13 +211,18 @@ class _CreateTripContentState extends State<CreateTripContent> {
if (_placeSuggestions.isEmpty) return; if (_placeSuggestions.isEmpty) return;
final overlay = Overlay.of(context);
// Calculer la largeur correcte en fonction du padding parent (16 margin + 24 padding = 40 de chaque côté)
final width = MediaQuery.of(context).size.width - 80;
_suggestionsOverlay = OverlayEntry( _suggestionsOverlay = OverlayEntry(
builder: (context) => Positioned( builder: (context) => Positioned(
width: MediaQuery.of(context).size.width - 32, // Largeur du champ avec padding width: width,
child: CompositedTransformFollower( child: CompositedTransformFollower(
link: _layerLink, link: _layerLink,
showWhenUnlinked: false, showWhenUnlinked: false,
offset: const Offset(0, 60), // Position sous le champ targetAnchor: Alignment.bottomLeft,
child: Material( child: Material(
elevation: 4, elevation: 4,
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
@@ -222,6 +235,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
), ),
child: ListView.builder( child: ListView.builder(
shrinkWrap: true, shrinkWrap: true,
padding: EdgeInsets.zero,
itemCount: _placeSuggestions.length, itemCount: _placeSuggestions.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final suggestion = _placeSuggestions[index]; final suggestion = _placeSuggestions[index];
@@ -242,7 +256,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
), ),
); );
Overlay.of(context).insert(_suggestionsOverlay!); overlay.insert(_suggestionsOverlay!);
} }
void _hideSuggestions() { void _hideSuggestions() {
@@ -251,7 +265,10 @@ class _CreateTripContentState extends State<CreateTripContent> {
} }
void _selectSuggestion(PlaceSuggestion suggestion) { void _selectSuggestion(PlaceSuggestion suggestion) {
_isProgrammaticUpdate = true;
_locationController.text = suggestion.description; _locationController.text = suggestion.description;
_isProgrammaticUpdate = false;
_hideSuggestions(); _hideSuggestions();
setState(() { setState(() {
_placeSuggestions = []; _placeSuggestions = [];
@@ -263,19 +280,25 @@ class _CreateTripContentState extends State<CreateTripContent> {
/// 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',
@@ -347,42 +370,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,
@@ -412,26 +429,26 @@ class _CreateTripContentState extends State<CreateTripContent> {
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,7 +457,7 @@ 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;
@@ -452,7 +469,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 +483,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 +499,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 +529,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 +545,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 +572,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 +618,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 +645,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 +699,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 +796,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 +813,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 +891,17 @@ 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'))); _errorService.showError(message: 'Email invalide');
} }
return; return;
} }
if (_participants.contains(email)) { if (_participants.contains(email)) {
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context) _errorService.showSnackbar(
.showSnackBar(SnackBar(content: Text('Ce participant est déjà ajouté'))); message: 'Ce participant est déjà ajouté',
isError: true,
);
} }
return; return;
} }
@@ -871,13 +918,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 +938,56 @@ 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) {
_errorService.showSnackbar(
message: 'Groupe et compte mis à jour avec succès !',
isError: false,
);
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 +1003,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;
} }
@@ -951,7 +1027,6 @@ class _CreateTripContentState extends State<CreateTripContent> {
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,34 +1046,29 @@ 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( _errorService.showSnackbar(
SnackBar( message: 'Voyage, groupe et compte créés avec succès !',
content: Text('Voyage, groupe et compte créés avec succès !'), isError: false,
backgroundColor: Colors.green,
),
); );
setState(() { setState(() {
_isLoading = false; _isLoading = false;
}); });
Navigator.pop(context); Navigator.pop(context);
} }
} catch (e) { } catch (e) {
_errorService.logError( _errorService.logError(
'create_trip_content.dart', 'create_trip_content.dart',
@@ -1006,12 +1076,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
); );
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( _errorService.showError(message: 'Erreur: $e');
SnackBar(
content: Text('Erreur: $e'),
backgroundColor: Colors.red,
),
);
setState(() { setState(() {
_isLoading = false; _isLoading = false;
}); });
@@ -1019,8 +1084,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;
@@ -1028,8 +1091,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
if (_startDate == null || _endDate == null) { if (_startDate == null || _endDate == null) {
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( _errorService.showSnackbar(
SnackBar(content: Text('Veuillez sélectionner les dates')), message: 'Veuillez sélectionner les dates',
isError: true,
); );
} }
return; return;
@@ -1043,7 +1107,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,20 +1133,15 @@ 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( _errorService.showSnackbar(
SnackBar( message:
content: Text('Voyage créé sans géolocalisation (pas d\'impact sur les fonctionnalités)'), 'Voyage créé sans géolocalisation (pas d\'impact sur les fonctionnalités)',
backgroundColor: Colors.orange, isError: true, // Warning displayed as error for now
duration: Duration(seconds: 2),
),
); );
} }
} }
@@ -1089,27 +1150,29 @@ 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));
} }
} catch (e) { } catch (e) {
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( _errorService.showError(message: 'Erreur: $e');
SnackBar(
content: Text('Erreur: $e'),
backgroundColor: Colors.red,
),
);
setState(() { setState(() {
_isLoading = false; _isLoading = false;
@@ -1118,7 +1181,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,20 +1192,20 @@ 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 {
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( _errorService.showSnackbar(
SnackBar( message: 'Utilisateur non trouvé: $email',
content: Text('Utilisateur non trouvé: $email'), isError: true,
backgroundColor: Colors.orange,
),
); );
} }
} }
@@ -1160,8 +1225,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,
});
} }

View File

@@ -11,6 +11,7 @@ import '../../blocs/trip/trip_bloc.dart';
import '../../blocs/trip/trip_state.dart'; import '../../blocs/trip/trip_state.dart';
import '../../blocs/trip/trip_event.dart'; import '../../blocs/trip/trip_event.dart';
import '../../models/trip.dart'; import '../../models/trip.dart';
import '../../services/error_service.dart';
/// Home content widget for the main application dashboard. /// Home content widget for the main application dashboard.
/// ///
@@ -79,26 +80,16 @@ class _HomeContentState extends State<HomeContent>
return BlocConsumer<TripBloc, TripState>( return BlocConsumer<TripBloc, TripState>(
listener: (context, tripState) { listener: (context, tripState) {
if (tripState is TripOperationSuccess) { if (tripState is TripOperationSuccess) {
ScaffoldMessenger.of(context).showSnackBar( ErrorService().showSnackbar(
SnackBar( message: tripState.message,
content: Text(tripState.message), isError: false,
backgroundColor: Colors.green,
),
); );
} else if (tripState is TripError) { } else if (tripState is TripError) {
ScaffoldMessenger.of(context).showSnackBar( ErrorService().showError(message: tripState.message);
SnackBar(
content: Text(tripState.message),
backgroundColor: Colors.red,
),
);
} else if (tripState is TripCreated) { } else if (tripState is TripCreated) {
ScaffoldMessenger.of(context).showSnackBar( ErrorService().showSnackbar(
SnackBar( message: 'Voyage en cours de création...',
content: Text('Voyage en cours de création...'), isError: false,
backgroundColor: Colors.blue,
duration: Duration(seconds: 1),
),
); );
} }
}, },
@@ -134,17 +125,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()
@@ -165,6 +146,7 @@ class _HomeContentState extends State<HomeContent>
), ),
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
heroTag: 'home_fab',
onPressed: () async { onPressed: () async {
final tripBloc = context.read<TripBloc>(); final tripBloc = context.read<TripBloc>();

File diff suppressed because it is too large Load Diff

View File

@@ -41,12 +41,9 @@ class _TripCardState extends State<TripCard> {
}); });
try { try {
// D'abord vérifier si une image existe déjà dans le Storage
String? imageUrl = await _placeImageService.getExistingImageUrl( String? imageUrl = await _placeImageService.getExistingImageUrl(
widget.trip.location, widget.trip.location,
); );
// Si aucune image n'existe, en télécharger une nouvelle
imageUrl ??= await _placeImageService.getPlaceImageUrl( imageUrl ??= await _placeImageService.getPlaceImageUrl(
widget.trip.location, widget.trip.location,
); );
@@ -57,7 +54,6 @@ class _TripCardState extends State<TripCard> {
_isLoadingImage = false; _isLoadingImage = false;
}); });
// Mettre à jour le voyage dans la base de données avec l'imageUrl
_updateTripWithImage(imageUrl); _updateTripWithImage(imageUrl);
} else { } else {
setState(() { setState(() {
@@ -76,18 +72,13 @@ class _TripCardState extends State<TripCard> {
Future<void> _updateTripWithImage(String imageUrl) async { Future<void> _updateTripWithImage(String imageUrl) async {
try { try {
if (widget.trip.id != null) { if (widget.trip.id != null) {
// Créer une copie du voyage avec la nouvelle imageUrl
final updatedTrip = widget.trip.copyWith( final updatedTrip = widget.trip.copyWith(
imageUrl: imageUrl, imageUrl: imageUrl,
updatedAt: DateTime.now(), updatedAt: DateTime.now(),
); );
// Mettre à jour dans la base de données
await _tripRepository.updateTrip(widget.trip.id!, updatedTrip); await _tripRepository.updateTrip(widget.trip.id!, updatedTrip);
} }
} catch (e) { } catch (e) {}
// En cas d'erreur, on continue sans échec - l'image reste affichée localement
}
} }
Widget _buildImageWidget() { Widget _buildImageWidget() {

View File

@@ -57,7 +57,10 @@ 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');
if (mounted) {
Navigator.pop(context);
}
} }
} }
} }

View File

@@ -1,3 +1,4 @@
import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:geolocator/geolocator.dart'; import 'package:geolocator/geolocator.dart';
@@ -5,6 +6,11 @@ import 'dart:convert';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart';
import '../../firebase_options.dart';
import '../../services/error_service.dart';
import '../../services/map_navigation_service.dart';
import '../../services/logger_service.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class MapContent extends StatefulWidget { class MapContent extends StatefulWidget {
final String? initialSearchQuery; final String? initialSearchQuery;
@@ -17,6 +23,7 @@ class MapContent extends StatefulWidget {
class _MapContentState extends State<MapContent> { class _MapContentState extends State<MapContent> {
GoogleMapController? _mapController; GoogleMapController? _mapController;
LatLng _initialPosition = const LatLng(48.8566, 2.3522); LatLng _initialPosition = const LatLng(48.8566, 2.3522);
LatLng? _currentMapCenter;
final TextEditingController _searchController = TextEditingController(); final TextEditingController _searchController = TextEditingController();
bool _isLoadingLocation = false; bool _isLoadingLocation = false;
bool _isSearching = false; bool _isSearching = false;
@@ -27,13 +34,45 @@ class _MapContentState extends State<MapContent> {
List<PlaceSuggestion> _suggestions = []; List<PlaceSuggestion> _suggestions = [];
static final String _apiKey = dotenv.env['GOOGLE_MAPS_API_KEY'] ?? ''; static String get _apiKey {
return DefaultFirebaseOptions.currentPlatform.apiKey;
}
@override @override
void initState() { void initState() {
super.initState(); super.initState();
// Si une recherche initiale est fournie, la pré-remplir et lancer la recherche
if (widget.initialSearchQuery != null && widget.initialSearchQuery!.isNotEmpty) { final mapService = context.read<MapNavigationService>();
// Écouter les nouvelles demandes
mapService.requestStream.listen((request) {
LoggerService.info(
'MapContent: Received navigation request: ${request.name}',
);
_handleNavigationRequest(request);
});
// Vérifier s'il y a une demande de navigation en attente
if (mapService.lastRequest != null) {
LoggerService.info(
'MapContent: Found pending navigation request: ${mapService.lastRequest!.name}',
);
// Handle synchronously for initial build
final request = mapService.lastRequest!;
final position = LatLng(request.latitude, request.longitude);
_initialPosition = position;
_markers.add(
Marker(
markerId: MarkerId(
'nav_request_${request.timestamp.millisecondsSinceEpoch}',
),
position: position,
infoWindow: InfoWindow(title: request.name ?? 'Lieu sélectionné'),
),
);
// Ne pas lancer _getCurrentLocation() ici pour ne pas écraser la position
} else 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), () {
@@ -45,6 +84,54 @@ class _MapContentState extends State<MapContent> {
} }
} }
void _handleNavigationRequest(MapLocationRequest request) {
if (!mounted) return;
LoggerService.info(
'MapContent: Handling navigation request to ${request.latitude}, ${request.longitude}',
);
final position = LatLng(request.latitude, request.longitude);
setState(() {
// Garder le marqueur de position utilisateur
_markers.removeWhere((m) => m.markerId.value != 'user_location');
// Ajouter le marqueur pour le lieu demandé
_markers.add(
Marker(
markerId: MarkerId(
'nav_request_${request.timestamp.millisecondsSinceEpoch}',
),
position: position,
infoWindow: InfoWindow(title: request.name ?? 'Lieu sélectionné'),
),
);
_isSearching = false;
});
// Animer la caméra si le contrôleur est prêt
if (_mapController != null) {
LoggerService.info(
'MapContent: Waiting for map to be visible before animating',
);
// Attendre un peu que l'onglet change et que la carte soit visible
Future.delayed(const Duration(milliseconds: 500), () {
if (mounted && _mapController != null) {
LoggerService.info('MapContent: Animating camera to position');
_mapController!.animateCamera(
CameraUpdate.newLatLngZoom(position, 15),
);
}
});
} else {
LoggerService.info(
'MapContent: MapController not ready, setting initial position',
);
// Si le contrôleur n'est pas encore prêt, définir la position initiale
_initialPosition = position;
}
}
@override @override
void dispose() { void dispose() {
_searchController.dispose(); _searchController.dispose();
@@ -65,11 +152,13 @@ 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);
@@ -117,6 +206,8 @@ 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);
@@ -223,38 +314,40 @@ class _MapContentState extends State<MapContent> {
} }
} }
// Créer une icône personnalisée à partir de l'icône Material // Créer une icône personnalisée
Future<BitmapDescriptor> _createCustomMarkerIcon() async { Future<BitmapDescriptor> _createMarkerIcon(
IconData iconData,
Color color, {
double size = 60.0,
}) async {
final pictureRecorder = ui.PictureRecorder(); final pictureRecorder = ui.PictureRecorder();
final canvas = Canvas(pictureRecorder); final canvas = Canvas(pictureRecorder);
const size = 120.0;
// Dessiner l'icône person_pin_circle en bleu final iconPainter = TextPainter(textDirection: TextDirection.ltr);
final iconPainter = TextPainter(
textDirection: TextDirection.ltr,
);
iconPainter.text = TextSpan( iconPainter.text = TextSpan(
text: String.fromCharCode(Icons.person_pin_circle.codePoint), text: String.fromCharCode(iconData.codePoint),
style: TextStyle( style: TextStyle(
fontSize: 100, fontSize: size,
fontFamily: Icons.person_pin_circle.fontFamily, fontFamily: iconData.fontFamily,
color: Colors.blue[700], package: iconData.fontPackage,
color: color,
shadows: [
Shadow(
offset: const Offset(1, 1),
blurRadius: 2,
color: Colors.black.withValues(alpha: 0.3),
),
],
), ),
); );
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
@@ -274,8 +367,12 @@ class _MapContentState extends State<MapContent> {
), ),
); );
// Créer l'icône personnalisée // Créer l'icône personnalisée (plus petite: 60 au lieu de 80)
final icon = await _createCustomMarkerIcon(); final icon = await _createMarkerIcon(
Icons.person_pin_circle,
Colors.blue[700]!,
size: 60.0,
);
// Ajouter le marqueur avec l'icône // Ajouter le marqueur avec l'icône
setState(() { setState(() {
@@ -284,10 +381,11 @@ 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
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)}',
), ),
), ),
); );
@@ -307,38 +405,69 @@ class _MapContentState extends State<MapContent> {
}); });
try { try {
final apiKey = _apiKey;
LoggerService.info('MapContent: Searching places with query "$query"');
if (apiKey.isEmpty) {
LoggerService.error('MapContent: API Key is empty!');
} else {
// Log first few chars to verify correct key is loaded without leaking full key
LoggerService.info(
'MapContent: Using API Key starting with ${apiKey.substring(0, 5)}...',
);
}
final url = Uri.parse( final url = Uri.parse(
'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;
LoggerService.info(
'MapContent: Response status code: ${response.statusCode}',
);
if (response.statusCode == 200) { if (response.statusCode == 200) {
final data = json.decode(response.body); final data = json.decode(response.body);
final status = data['status'];
if (data['status'] == 'OK') { LoggerService.info('MapContent: API Status: $status');
if (status == 'OK') {
final predictions = data['predictions'] as List; final predictions = data['predictions'] as List;
LoggerService.info(
'MapContent: Found ${predictions.length} predictions',
);
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;
}); });
} else { } else {
LoggerService.error(
'MapContent: API Error: $status - ${data['error_message'] ?? "No error message"}',
);
setState(() { setState(() {
_suggestions = []; _suggestions = [];
_isSearching = false; _isSearching = false;
}); });
} }
} else {
LoggerService.error('MapContent: HTTP Error ${response.statusCode}');
} }
} catch (e) { } catch (e) {
LoggerService.error('MapContent: Exception during search: $e');
_showError('Erreur lors de la recherche de lieux: $e'); _showError('Erreur lors de la recherche de lieux: $e');
setState(() { setState(() {
_isSearching = false; _isSearching = false;
@@ -346,6 +475,128 @@ class _MapContentState extends State<MapContent> {
} }
} }
Future<void> _performTextSearch(String query) async {
if (query.isEmpty) return;
setState(() {
_isSearching = true;
_suggestions = []; // Hide suggestions
});
try {
final apiKey = _apiKey;
// Utiliser le centre actuel de la carte ou la position initiale
final center = _currentMapCenter ?? _initialPosition;
final url = Uri.parse(
'https://maps.googleapis.com/maps/api/place/textsearch/json'
'?query=${Uri.encodeComponent(query)}'
'&location=${center.latitude},${center.longitude}'
'&radius=5000' // Rechercher dans un rayon de 5km autour du centre
'&key=$apiKey'
'&language=fr',
);
final response = await http.get(url);
if (!mounted) return;
if (response.statusCode == 200) {
final data = json.decode(response.body);
if (data['status'] == 'OK') {
final results = data['results'] as List;
final List<Marker> newMarkers = [];
// Garder le marqueur de position utilisateur
final userMarker = _markers
.where((m) => m.markerId.value == 'user_location')
.toList();
double minLat = center.latitude;
double maxLat = center.latitude;
double minLng = center.longitude;
double maxLng = center.longitude;
// Créer le marqueur rouge standard personnalisé
final markerIcon = await _createMarkerIcon(
Icons.location_on,
Colors.red,
size: 50.0,
);
for (final place in results) {
final geometry = place['geometry']['location'];
final lat = geometry['lat'];
final lng = geometry['lng'];
final name = place['name'];
final placeId = place['place_id'];
final position = LatLng(lat, lng);
// Mettre à jour les bornes
if (lat < minLat) minLat = lat;
if (lat > maxLat) maxLat = lat;
if (lng < minLng) minLng = lng;
if (lng > maxLng) maxLng = lng;
newMarkers.add(
Marker(
markerId: MarkerId(placeId),
position: position,
icon: markerIcon,
anchor: const Offset(0.5, 0.85), // Standard anchor for pins
infoWindow: InfoWindow(
title: name,
snippet: place['formatted_address'] ?? 'Lieu trouvé',
),
),
);
}
setState(() {
_markers.clear();
if (userMarker.isNotEmpty) {
_markers.add(userMarker.first);
}
_markers.addAll(newMarkers);
_isSearching = false;
});
// Ajuster la caméra pour montrer tous les résultats
if (newMarkers.isNotEmpty) {
_mapController?.animateCamera(
CameraUpdate.newLatLngBounds(
LatLngBounds(
southwest: LatLng(minLat, minLng),
northeast: LatLng(maxLat, maxLng),
),
50.0, // padding
),
);
}
FocusScope.of(context).unfocus();
} else {
_showError('Aucun résultat trouvé pour "$query"');
setState(() {
_isSearching = false;
});
}
} else {
_showError('Erreur lors de la recherche: ${response.statusCode}');
setState(() {
_isSearching = false;
});
}
} catch (e) {
_showError('Erreur lors de la recherche: $e');
setState(() {
_isSearching = false;
});
}
}
Future<void> _selectPlace(PlaceSuggestion suggestion) async { Future<void> _selectPlace(PlaceSuggestion suggestion) async {
setState(() { setState(() {
_isSearching = true; _isSearching = true;
@@ -363,17 +614,27 @@ 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 result = data['result'];
final location = result['geometry']['location'];
final lat = location['lat']; final lat = location['lat'];
final lng = location['lng']; final lng = location['lng'];
final name = data['result']['name']; final name = result['name'];
final newPosition = LatLng(lat, lng); final newPosition = LatLng(lat, lng);
// Utiliser le marqueur rouge standard personnalisé
final markerIcon = await _createMarkerIcon(
Icons.location_on,
Colors.red,
size: 50.0,
);
// Ajouter un marqueur pour le lieu recherché (ne pas supprimer le marqueur de position) // Ajouter un marqueur pour le lieu recherché (ne pas supprimer le marqueur de position)
setState(() { setState(() {
// Garder le marqueur de position utilisateur // Garder le marqueur de position utilisateur
@@ -384,6 +645,8 @@ class _MapContentState extends State<MapContent> {
Marker( Marker(
markerId: MarkerId(suggestion.placeId), markerId: MarkerId(suggestion.placeId),
position: newPosition, position: newPosition,
icon: markerIcon,
anchor: const Offset(0.5, 0.85),
infoWindow: InfoWindow(title: name), infoWindow: InfoWindow(title: name),
), ),
); );
@@ -394,7 +657,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) {
@@ -407,13 +672,7 @@ class _MapContentState extends State<MapContent> {
void _showError(String message) { void _showError(String message) {
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( ErrorService().showError(message: message);
SnackBar(
content: Text(message),
backgroundColor: Colors.red,
behavior: SnackBarBehavior.floating,
),
);
} }
} }
@@ -437,6 +696,9 @@ class _MapContentState extends State<MapContent> {
onMapCreated: (GoogleMapController controller) { onMapCreated: (GoogleMapController controller) {
_mapController = controller; _mapController = controller;
}, },
onCameraMove: (CameraPosition position) {
_currentMapCenter = position.target;
},
markers: _markers, markers: _markers,
circles: _circles, circles: _circles,
myLocationEnabled: false, myLocationEnabled: false,
@@ -545,7 +807,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(() {
@@ -565,9 +830,14 @@ class _MapContentState extends State<MapContent> {
vertical: 14, vertical: 14,
), ),
), ),
textInputAction: TextInputAction.search,
onSubmitted: (value) {
_performTextSearch(value);
},
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 +871,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(
@@ -652,6 +920,7 @@ class _MapContentState extends State<MapContent> {
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
heroTag: 'map_fab',
onPressed: _getCurrentLocation, onPressed: _getCurrentLocation,
tooltip: 'Ma position', tooltip: 'Ma position',
child: const Icon(Icons.my_location), child: const Icon(Icons.my_location),
@@ -664,8 +933,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,
});
} }

View File

@@ -11,6 +11,13 @@ class PoliciesContent extends StatelessWidget {
} }
} }
Future<void> _launchCustomPrivacyPolicy() async {
final Uri url = Uri.parse('https://xeewy.be/travelmate/policies');
if (!await launchUrl(url)) {
throw Exception('Could not launch $url');
}
}
Future<void> _onBackPressed(BuildContext context) async { Future<void> _onBackPressed(BuildContext context) async {
if (Navigator.canPop(context)) { if (Navigator.canPop(context)) {
Navigator.pop(context); Navigator.pop(context);
@@ -44,108 +51,8 @@ class PoliciesContent extends StatelessWidget {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Section Collecte d'informations // Keep only the buttons
Text(
'Collecte d\'informations',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w600,
color: isDark ? Colors.white : Colors.black,
),
),
const SizedBox(height: 10),
Text(
'Nous collectons des informations que vous nous fournissez directement, comme votre nom, adresse e-mail et préférences de voyage.',
style: theme.textTheme.bodyLarge?.copyWith(
color: isDark ? Colors.grey[300] : Colors.grey[800],
),
),
const SizedBox(height: 20), const SizedBox(height: 20),
// Section Utilisation des données
Text(
'Utilisation des données',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w600,
color: isDark ? Colors.white : Colors.black,
),
),
const SizedBox(height: 10),
Text(
'Vos données sont utilisées pour améliorer votre expérience utilisateur et vous proposer des recommandations personnalisées.',
style: theme.textTheme.bodyLarge?.copyWith(
color: isDark ? Colors.grey[300] : Colors.grey[800],
),
),
const SizedBox(height: 20),
// Section Protection des données
Text(
'Protection des données',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w600,
color: isDark ? Colors.white : Colors.black,
),
),
const SizedBox(height: 10),
Text(
'Nous mettons en place des mesures de sécurité appropriées pour protéger vos informations personnelles.',
style: theme.textTheme.bodyLarge?.copyWith(
color: isDark ? Colors.grey[300] : Colors.grey[800],
),
),
const SizedBox(height: 20),
// Section Partage des données
Text(
'Partage des données',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w600,
color: isDark ? Colors.white : Colors.black,
),
),
const SizedBox(height: 10),
Text(
'Nous ne partageons pas vos informations personnelles avec des tiers sans votre consentement explicite.',
style: theme.textTheme.bodyLarge?.copyWith(
color: isDark ? Colors.grey[300] : Colors.grey[800],
),
),
const SizedBox(height: 20),
// Section Droits de l'utilisateur
Text(
'Vos droits',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w600,
color: isDark ? Colors.white : Colors.black,
),
),
const SizedBox(height: 10),
Text(
'Vous avez le droit d\'accéder, de corriger ou de supprimer vos données personnelles à tout moment. Veuillez nous contacter pour toute demande.',
style: theme.textTheme.bodyLarge?.copyWith(
color: isDark ? Colors.grey[300] : Colors.grey[800],
),
),
const SizedBox(height: 20),
// Section Contact
Text(
'Nous contacter',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w600,
color: isDark ? Colors.white : Colors.black,
),
),
const SizedBox(height: 10),
Text(
'Pour toute question concernant cette politique de confidentialité, veuillez nous contacter à support@travelmate.com',
style: theme.textTheme.bodyLarge?.copyWith(
color: isDark ? Colors.grey[300] : Colors.grey[800],
),
),
const SizedBox(height: 20),
// Bouton Google Privacy Policy // Bouton Google Privacy Policy
SizedBox( SizedBox(
width: double.infinity, width: double.infinity,
@@ -163,6 +70,24 @@ class PoliciesContent extends StatelessWidget {
), ),
), ),
), ),
const SizedBox(height: 12),
// Bouton Nos politiques de confidentialité
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: _launchCustomPrivacyPolicy,
icon: const Icon(Icons.policy),
label: const Text('Nos politiques de confidentialités'),
style: ElevatedButton.styleFrom(
backgroundColor: theme.primaryColor,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
),
const SizedBox(height: 32), const SizedBox(height: 32),
], ],
), ),

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:travel_mate/components/widgets/user_state_widget.dart'; import 'package:travel_mate/components/widgets/user_state_widget.dart';
import 'package:travel_mate/services/error_service.dart'; import 'package:travel_mate/services/error_service.dart';
@@ -9,6 +10,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 +21,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 +43,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 +62,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 +95,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 +103,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 +127,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,
),
), ),
), ),
], ],
@@ -140,7 +150,9 @@ class ProfileContent extends StatelessWidget {
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: Colors.black87, color: Theme.of(context).brightness == Brightness.dark
? Colors.white
: Colors.black87,
), ),
), ),
], ],
@@ -320,11 +332,7 @@ class ProfileContent extends StatelessWidget {
), ),
), ),
), ),
Icon( Icon(Icons.arrow_forward_ios, size: 16, color: Colors.grey[400]),
Icons.arrow_forward_ios,
size: 16,
color: Colors.grey[400],
),
], ],
), ),
), ),
@@ -401,7 +409,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 +432,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);
}, },
@@ -490,11 +504,9 @@ class ProfileContent extends StatelessWidget {
); );
Navigator.of(dialogContext).pop(); Navigator.of(dialogContext).pop();
ScaffoldMessenger.of(context).showSnackBar( _errorService.showSnackbar(
SnackBar( message: 'Profil mis à jour !',
content: Text('Profil mis à jour !'), isError: false,
backgroundColor: Colors.green,
),
); );
} }
}, },
@@ -515,56 +527,62 @@ class ProfileContent extends StatelessWidget {
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,7 +590,11 @@ 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);
@@ -582,7 +604,9 @@ class ProfileContent extends StatelessWidget {
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) {
@@ -593,14 +617,15 @@ 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 {
@@ -608,13 +633,17 @@ class ProfileContent extends StatelessWidget {
// É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,36 +652,30 @@ 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( _errorService.showSnackbar(
SnackBar( message: 'Photo de profil mise à jour !',
content: Text('Photo de profil mise à jour !'), isError: false,
backgroundColor: Colors.green,
),
); );
} }
} 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',
@@ -711,22 +734,16 @@ class ProfileContent extends StatelessWidget {
if (currentPasswordController.text.isEmpty || if (currentPasswordController.text.isEmpty ||
newPasswordController.text.isEmpty || newPasswordController.text.isEmpty ||
confirmPasswordController.text.isEmpty) { confirmPasswordController.text.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar( _errorService.showError(
SnackBar( message: 'Tous les champs sont requis',
content: Text('Tous les champs sont requis'),
backgroundColor: Colors.red,
),
); );
return; return;
} }
if (newPasswordController.text != if (newPasswordController.text !=
confirmPasswordController.text) { confirmPasswordController.text) {
ScaffoldMessenger.of(context).showSnackBar( _errorService.showError(
SnackBar( message: 'Les mots de passe ne correspondent pas',
content: Text('Les mots de passe ne correspondent pas'),
backgroundColor: Colors.red,
),
); );
return; return;
} }
@@ -738,13 +755,13 @@ 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( _errorService.showSnackbar(
content: Text('Mot de passe changé !'), message: 'Mot de passe changé !',
backgroundColor: Colors.green, isError: false,
), );
); }
} catch (e) { } catch (e) {
_errorService.showError( _errorService.showError(
message: 'Erreur: Mot de passe actuel incorrect', message: 'Erreur: Mot de passe actuel incorrect',
@@ -763,7 +780,7 @@ class ProfileContent extends StatelessWidget {
BuildContext context, BuildContext context,
user_state.UserModel user, user_state.UserModel user,
) { ) {
final passwordController = TextEditingController(); final confirmationController = TextEditingController();
final authService = AuthService(); final authService = AuthService();
showDialog( showDialog(
@@ -775,15 +792,15 @@ class ProfileContent extends StatelessWidget {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Text( Text(
'Êtes-vous sûr de vouloir supprimer votre compte ? Cette action est irréversible.', 'Êtes-vous sûr de vouloir supprimer votre compte ? Cette action est irréversible.\n\nPour confirmer, veuillez écrire "CONFIRMER" ci-dessous.',
), ),
SizedBox(height: 16), SizedBox(height: 16),
TextField( TextField(
controller: passwordController, controller: confirmationController,
obscureText: true,
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Confirmez votre mot de passe', labelText: 'Écrivez CONFIRMER',
border: OutlineInputBorder(), border: OutlineInputBorder(),
hintText: 'CONFIRMER',
), ),
), ),
], ],
@@ -795,23 +812,48 @@ class ProfileContent extends StatelessWidget {
), ),
TextButton( TextButton(
onPressed: () async { onPressed: () async {
try { if (confirmationController.text != 'CONFIRMER') {
await authService.deleteAccount(
password: passwordController.text,
email: user.email,
);
Navigator.of(dialogContext).pop();
context.read<UserBloc>().add(user_event.UserLoggedOut());
Navigator.pushNamedAndRemoveUntil(
context,
'/login',
(route) => false,
);
} catch (e) {
_errorService.showError( _errorService.showError(
message: 'Erreur: Mot de passe incorrect', message: 'Veuillez écrire CONFIRMER pour valider',
); );
return;
}
try {
await authService.deleteAccount();
if (context.mounted) {
Navigator.of(dialogContext).pop();
context.read<UserBloc>().add(user_event.UserLoggedOut());
Navigator.pushNamedAndRemoveUntil(
context,
'/login',
(route) => false,
);
}
} on FirebaseAuthException catch (e) {
if (e.code == 'requires-recent-login') {
if (context.mounted) {
Navigator.of(dialogContext).pop();
_errorService.showSnackbar(
message:
'Par sécurité, veuillez vous reconnecter avant de supprimer votre compte',
isError: true, // It's a warning/error
);
}
} else {
if (context.mounted) {
_errorService.showError(
message: 'Erreur lors de la suppression: ${e.message}',
);
}
}
} catch (e) {
if (context.mounted) {
_errorService.showError(
message: 'Erreur inattendue: ${e.toString()}',
);
}
} }
}, },
style: TextButton.styleFrom(foregroundColor: Colors.red), style: TextButton.styleFrom(foregroundColor: Colors.red),

View File

@@ -3,9 +3,33 @@ import 'package:travel_mate/components/settings/policies/policies_content.dart';
import 'theme/settings_theme_content.dart'; import 'theme/settings_theme_content.dart';
import 'profile/profile_content.dart'; import 'profile/profile_content.dart';
class SettingsContent extends StatelessWidget { import 'package:package_info_plus/package_info_plus.dart';
class SettingsContent extends StatefulWidget {
const SettingsContent({super.key}); const SettingsContent({super.key});
@override
State<SettingsContent> createState() => _SettingsContentState();
}
class _SettingsContentState extends State<SettingsContent> {
String _version = '...';
@override
void initState() {
super.initState();
_loadVersion();
}
Future<void> _loadVersion() async {
final packageInfo = await PackageInfo.fromPlatform();
if (mounted) {
setState(() {
_version = packageInfo.version;
});
}
}
Future<void> changePage(BuildContext context, Widget page) async { Future<void> changePage(BuildContext context, Widget page) async {
Navigator.push(context, MaterialPageRoute(builder: (context) => page)); Navigator.push(context, MaterialPageRoute(builder: (context) => page));
} }
@@ -46,20 +70,6 @@ class SettingsContent extends StatelessWidget {
}, },
), ),
ListTile(
leading: const Icon(Icons.notifications),
title: const Text('Notifications'),
trailing: const Icon(Icons.arrow_forward_ios),
onTap: () {},
),
ListTile(
leading: const Icon(Icons.language),
title: const Text('Langue'),
trailing: const Icon(Icons.arrow_forward_ios),
onTap: () {},
),
ListTile( ListTile(
leading: const Icon(Icons.privacy_tip), leading: const Icon(Icons.privacy_tip),
title: const Text('Confidentialité'), title: const Text('Confidentialité'),
@@ -84,7 +94,7 @@ class SettingsContent extends StatelessWidget {
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
Text( Text(
'1.0.0', _version,
style: TextStyle(fontSize: 14, color: Colors.grey[500]), style: TextStyle(fontSize: 14, color: Colors.grey[500]),
), ),
], ],

View File

@@ -0,0 +1,57 @@
import 'package:flutter/material.dart';
class PasswordRequirements extends StatelessWidget {
final String password;
const PasswordRequirements({super.key, required this.password});
bool get _hasMinLength => password.length >= 8;
bool get _hasUppercase => password.contains(RegExp(r'[A-Z]'));
bool get _hasLowercase => password.contains(RegExp(r'[a-z]'));
bool get _hasDigit => password.contains(RegExp(r'[0-9]'));
bool get _hasSpecialChar =>
password.contains(RegExp(r'[!@#\$%^&*(),.?":{}|<>]'));
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 10),
const Text(
'Votre mot de passe doit contenir :',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
_buildRequirement(_hasMinLength, 'Au moins 8 caractères'),
_buildRequirement(_hasUppercase, 'Une majuscule'),
_buildRequirement(_hasLowercase, 'Une minuscule'),
_buildRequirement(_hasDigit, 'Un chiffre'),
_buildRequirement(_hasSpecialChar, 'Un caractère spécial'),
],
);
}
Widget _buildRequirement(bool isMet, String text) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 2.0),
child: Row(
children: [
Icon(
isMet ? Icons.check_circle : Icons.circle_outlined,
color: isMet ? Colors.green : Colors.grey,
size: 16,
),
const SizedBox(width: 8),
Text(
text,
style: TextStyle(
color: isMet ? Colors.green : Colors.grey,
fontSize: 12,
),
),
],
),
);
}
}

View File

@@ -0,0 +1,140 @@
import 'package:flutter/material.dart';
import '../../services/whats_new_service.dart';
class WhatsNewDialog extends StatelessWidget {
final VoidCallback onDismiss;
final List<WhatsNewItem> features;
const WhatsNewDialog({
super.key,
required this.onDismiss,
required this.features,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
backgroundColor: theme.colorScheme.surface,
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header
Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer,
shape: BoxShape.circle,
),
child: Icon(
Icons.auto_awesome,
color: theme.colorScheme.primary,
size: 24,
),
),
const SizedBox(width: 16),
Expanded(
child: Text(
'Quoi de neuf ?',
style: theme.textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
],
),
const SizedBox(height: 24),
// Features List
Flexible(
child: ListView.separated(
shrinkWrap: true,
itemCount: features.length,
separatorBuilder: (_, __) => const SizedBox(height: 16),
itemBuilder: (context, index) {
final feature = features[index];
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
feature.icon,
color: theme.colorScheme.primary,
size: 20,
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
feature.title,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 4),
Text(
feature.description,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
],
),
),
],
);
},
),
),
const SizedBox(height: 32),
// Button
SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton(
onPressed: () {
// Marquer comme vu via le service
WhatsNewService().markCurrentVersionAsSeen();
onDismiss();
},
style: ElevatedButton.styleFrom(
backgroundColor: theme.colorScheme.primary,
foregroundColor: theme.colorScheme.onPrimary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text(
'C\'est parti !',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
),
),
],
),
),
);
}
}
class WhatsNewItem {
final IconData icon;
final String title;
final String description;
const WhatsNewItem({
required this.icon,
required this.title,
required this.description,
});
}

View File

@@ -27,18 +27,6 @@ class DefaultFirebaseOptions {
return android; return android;
case TargetPlatform.iOS: case TargetPlatform.iOS:
return ios; return ios;
case TargetPlatform.macOS:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for macos - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.windows:
return windows;
case TargetPlatform.linux:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for linux - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
default: default:
throw UnsupportedError( throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.', 'DefaultFirebaseOptions are not supported for this platform.',
@@ -63,15 +51,4 @@ class DefaultFirebaseOptions {
iosClientId: '521527250907-3i1qe2656eojs8k9hjdi573j09i9p41m.apps.googleusercontent.com', iosClientId: '521527250907-3i1qe2656eojs8k9hjdi573j09i9p41m.apps.googleusercontent.com',
iosBundleId: 'com.example.travelMate', iosBundleId: 'com.example.travelMate',
); );
static const FirebaseOptions windows = FirebaseOptions(
apiKey: 'AIzaSyC4t-WOvp22zns9b9t58urznsNAhSHRAag',
appId: '1:521527250907:web:53ff98bcdb8c218f7da1fe',
messagingSenderId: '521527250907',
projectId: 'travelmate-a47f5',
authDomain: 'travelmate-a47f5.firebaseapp.com',
storageBucket: 'travelmate-a47f5.firebasestorage.app',
measurementId: 'G-J246Y7J61M',
);
} }

View File

@@ -1,8 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_core/firebase_core.dart';
import 'package:travel_mate/blocs/balance/balance_bloc.dart'; import 'package:travel_mate/blocs/balance/balance_bloc.dart';
import 'package:travel_mate/blocs/expense/expense_bloc.dart'; import 'package:travel_mate/blocs/expense/expense_bloc.dart';
import 'package:google_maps_flutter_android/google_maps_flutter_android.dart';
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:travel_mate/blocs/message/message_bloc.dart'; import 'package:travel_mate/blocs/message/message_bloc.dart';
import 'package:travel_mate/blocs/activity/activity_bloc.dart'; import 'package:travel_mate/blocs/activity/activity_bloc.dart';
import 'package:travel_mate/firebase_options.dart'; import 'package:travel_mate/firebase_options.dart';
@@ -11,6 +14,10 @@ import 'package:travel_mate/services/error_service.dart';
import 'package:travel_mate/services/activity_places_service.dart'; import 'package:travel_mate/services/activity_places_service.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:travel_mate/services/expense_service.dart'; import 'package:travel_mate/services/expense_service.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:travel_mate/services/notification_service.dart';
import 'package:travel_mate/services/map_navigation_service.dart';
import 'package:travel_mate/services/analytics_service.dart';
import 'blocs/auth/auth_bloc.dart'; import 'blocs/auth/auth_bloc.dart';
import 'blocs/auth/auth_event.dart'; import 'blocs/auth/auth_event.dart';
import 'blocs/theme/theme_bloc.dart'; import 'blocs/theme/theme_bloc.dart';
@@ -34,14 +41,33 @@ import 'pages/home.dart';
import 'pages/signup.dart'; import 'pages/signup.dart';
import 'pages/resetpswd.dart'; import 'pages/resetpswd.dart';
import 'package:intl/date_symbol_data_local.dart';
/// Entry point of the Travel Mate application. /// Entry point of the Travel Mate application.
/// ///
/// This function initializes Flutter widgets, loads environment variables, /// This function initializes Flutter widgets, loads environment variables,
/// initializes Firebase, and starts the application. /// initializes Firebase, and starts the application.
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
await dotenv.load(fileName: ".env"); await dotenv.load(fileName: ".env");
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
await initializeDateFormatting('fr_FR', null);
// Set the background messaging handler early on, as a named top-level function
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
await NotificationService().initialize();
// Requirements for Google Maps on Android (Hybrid Composition)
final GoogleMapsFlutterPlatform mapsImplementation =
GoogleMapsFlutterPlatform.instance;
if (mapsImplementation is GoogleMapsFlutterAndroid) {
mapsImplementation.useAndroidViewSurface = true;
}
runApp(const MyApp()); runApp(const MyApp());
} }
@@ -117,6 +143,14 @@ class MyApp extends StatelessWidget {
expenseRepository: context.read<ExpenseRepository>(), expenseRepository: context.read<ExpenseRepository>(),
), ),
), ),
// Map navigation service
RepositoryProvider<MapNavigationService>(
create: (context) => MapNavigationService(),
),
// Analysis service
RepositoryProvider<AnalyticsService>(
create: (context) => AnalyticsService(),
),
], ],
child: MultiBlocProvider( child: MultiBlocProvider(
providers: [ providers: [
@@ -177,6 +211,9 @@ class MyApp extends StatelessWidget {
title: 'Travel Mate', title: 'Travel Mate',
navigatorKey: ErrorService.navigatorKey, navigatorKey: ErrorService.navigatorKey,
themeMode: themeState.themeMode, themeMode: themeState.themeMode,
navigatorObservers: [
context.read<AnalyticsService>().getAnalyticsObserver(),
],
// Light theme configuration // Light theme configuration
theme: ThemeData( theme: ThemeData(
colorScheme: ColorScheme.fromSeed( colorScheme: ColorScheme.fromSeed(

View File

@@ -20,6 +20,8 @@ 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é
final String? createdBy; // ID de l'utilisateur qui a créé l'activité
Activity({ Activity({
required this.id, required this.id,
@@ -40,11 +42,13 @@ class Activity {
this.votes = const {}, this.votes = const {},
required this.createdAt, required this.createdAt,
required this.updatedAt, required this.updatedAt,
this.date,
this.createdBy,
}); });
/// 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 +108,9 @@ class Activity {
Map<String, int>? votes, Map<String, int>? votes,
DateTime? createdAt, DateTime? createdAt,
DateTime? updatedAt, DateTime? updatedAt,
DateTime? date,
bool clearDate = false,
String? createdBy,
}) { }) {
return Activity( return Activity(
id: id ?? this.id, id: id ?? this.id,
@@ -124,6 +131,8 @@ 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),
createdBy: createdBy ?? this.createdBy,
); );
} }
@@ -148,6 +157,8 @@ 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,
'createdBy': createdBy,
}; };
} }
@@ -172,6 +183,8 @@ 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,
createdBy: map['createdBy'],
); );
} }

View File

@@ -9,8 +9,10 @@ import 'expense_split.dart';
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');
@@ -29,16 +31,24 @@ enum ExpenseCurrency {
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),
/// Reimbursement for settling debts
reimbursement('Remboursement', Icons.monetization_on);
const ExpenseCategory(this.displayName, this.icon); const ExpenseCategory(this.displayName, this.icon);
@@ -144,13 +154,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 +257,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,
];
} }

View File

@@ -27,6 +27,9 @@ class Group {
/// 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.
@@ -40,9 +43,11 @@ class Group {
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.
/// ///
@@ -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,
); );
} }
} }

View File

@@ -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,15 +85,19 @@ 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 =>
userBalances.where((b) => b.shouldReceive).toList();
List<UserBalance> get debtors => userBalances.where((b) => b.shouldPay).toList(); List<UserBalance> get debtors =>
userBalances.where((b) => b.shouldPay).toList();
int get participantCount => userBalances.length; int get participantCount => userBalances.length;

View File

@@ -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,

View File

@@ -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,
); );
} }
} }

View File

@@ -11,6 +11,11 @@ import '../blocs/user/user_bloc.dart';
import '../blocs/user/user_event.dart'; import '../blocs/user/user_event.dart';
import '../blocs/auth/auth_bloc.dart'; import '../blocs/auth/auth_bloc.dart';
import '../blocs/auth/auth_event.dart'; import '../blocs/auth/auth_event.dart';
import '../services/error_service.dart';
import '../services/notification_service.dart';
import '../services/map_navigation_service.dart';
import '../services/whats_new_service.dart';
import '../components/whats_new_dialog.dart';
class HomePage extends StatefulWidget { class HomePage extends StatefulWidget {
const HomePage({super.key}); const HomePage({super.key});
@@ -36,6 +41,63 @@ class _HomePageState extends State<HomePage> {
super.initState(); super.initState();
// Initialiser les données utilisateur // Initialiser les données utilisateur
context.read<UserBloc>().add(UserInitialized()); context.read<UserBloc>().add(UserInitialized());
// Setup notifications listener and check for initial message
final notificationService = NotificationService();
notificationService.startListening();
// Check for initial message after a slight delay to ensure the widget tree is fully built
WidgetsBinding.instance.addPostFrameCallback((_) {
notificationService.handleInitialMessage();
});
// Écouter les demandes de navigation vers la carte
context.read<MapNavigationService>().requestStream.listen((request) {
if (_currentIndex != 2) {
setState(() {
_currentIndex = 2;
});
}
});
// Vérifier les nouveautés
WidgetsBinding.instance.addPostFrameCallback((_) async {
await _checkAndShowWhatsNew();
});
}
Future<void> _checkAndShowWhatsNew() async {
final service = WhatsNewService();
if (await service.shouldShowWhatsNew()) {
if (!mounted) return;
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => WhatsNewDialog(
onDismiss: () => Navigator.pop(context),
features: const [
WhatsNewItem(
icon: Icons.map_outlined,
title: 'Recherche globale',
description:
'Recherchez des restaurants, musées et plus encore directement depuis la carte.',
),
WhatsNewItem(
icon: Icons.search,
title: 'Autocomplétion améliorée',
description:
'Découvrez des suggestions intelligentes lors de la recherche de lieux et d\'activités.',
),
WhatsNewItem(
icon: Icons.warning_amber_rounded,
title: 'Alertes de distance',
description:
'Soyez averti si une activité est trop éloignée de votre lieu de séjour.',
),
],
),
);
}
} }
Widget _buildPage(int index) { Widget _buildPage(int index) {
@@ -119,12 +181,7 @@ class _HomePageState extends State<HomePage> {
); );
} catch (e) { } catch (e) {
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( ErrorService().showError(message: 'Erreur lors de la déconnexion: $e');
SnackBar(
content: Text('Erreur lors de la déconnexion: $e'),
backgroundColor: Colors.red,
),
);
} }
} }
} }
@@ -132,9 +189,7 @@ class _HomePageState extends State<HomePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(title: Text(titles[_currentIndex])),
title: Text(titles[_currentIndex]),
),
drawer: Drawer( drawer: Drawer(
child: ListView( child: ListView(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
@@ -142,28 +197,43 @@ class _HomePageState extends State<HomePage> {
DrawerHeader( DrawerHeader(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).brightness == Brightness.dark color: Theme.of(context).brightness == Brightness.dark
? Colors.black ? Colors.black
: Colors.white, : Colors.white,
), ),
child: Text( child: Text(
"Travel Mate", "Travel Mate",
style: TextStyle( style: TextStyle(
color: Theme.of(context).brightness == Brightness.dark color: Theme.of(context).brightness == Brightness.dark
? Colors.white ? Colors.white
: Colors.black, : Colors.black,
fontSize: 24, fontSize: 24,
), ),
), ),
), ),
_buildDrawerItem(icon: Icons.home, title: "Mes voyages", index: 0), _buildDrawerItem(icon: Icons.home, title: "Mes voyages", index: 0),
_buildDrawerItem(icon: Icons.settings, title: "Paramètres", index: 1), _buildDrawerItem(
icon: Icons.settings,
title: "Paramètres",
index: 1,
),
_buildDrawerItem(icon: Icons.map, title: "Carte", index: 2), _buildDrawerItem(icon: Icons.map, title: "Carte", index: 2),
_buildDrawerItem(icon: Icons.group, title: "Chat de groupe", index: 3), _buildDrawerItem(
_buildDrawerItem(icon: Icons.account_balance_wallet, title: "Comptes", index: 4), icon: Icons.group,
title: "Chat de groupe",
index: 3,
),
_buildDrawerItem(
icon: Icons.account_balance_wallet,
title: "Comptes",
index: 4,
),
const Divider(), const Divider(),
ListTile( ListTile(
leading: const Icon(Icons.logout, color: Colors.red), leading: const Icon(Icons.logout, color: Colors.red),
title: const Text("Déconnexion", style: TextStyle(color: Colors.red)), title: const Text(
"Déconnexion",
style: TextStyle(color: Colors.red),
),
onTap: _handleLogout, // Utiliser la nouvelle méthode onTap: _handleLogout, // Utiliser la nouvelle méthode
), ),
], ],
@@ -191,7 +261,9 @@ class _HomePageState extends State<HomePage> {
leading: Icon(icon), leading: Icon(icon),
title: Text(title), title: Text(title),
selected: _currentIndex == index, selected: _currentIndex == index,
selectedTileColor: Theme.of(context).colorScheme.primary.withValues(alpha: 0.1), selectedTileColor: Theme.of(
context,
).colorScheme.primary.withValues(alpha: 0.1),
onTap: () => _onNavigationTap(index), onTap: () => _onNavigationTap(index),
); );
} }

View File

@@ -4,6 +4,7 @@ import '../blocs/auth/auth_bloc.dart';
import '../blocs/auth/auth_event.dart'; import '../blocs/auth/auth_event.dart';
import '../blocs/auth/auth_state.dart'; import '../blocs/auth/auth_state.dart';
import 'package:sign_in_button/sign_in_button.dart'; import 'package:sign_in_button/sign_in_button.dart';
import '../services/error_service.dart';
/// Login page widget for user authentication. /// Login page widget for user authentication.
/// ///
@@ -87,14 +88,13 @@ class _LoginPageState extends State<LoginPage> {
body: BlocConsumer<AuthBloc, AuthState>( body: BlocConsumer<AuthBloc, AuthState>(
listener: (context, state) { listener: (context, state) {
if (state is AuthAuthenticated) { if (state is AuthAuthenticated) {
Navigator.pushReplacementNamed(context, '/home'); Navigator.pushNamedAndRemoveUntil(
} else if (state is AuthError) { context,
ScaffoldMessenger.of(context).showSnackBar( '/home',
SnackBar( (route) => false,
content: Text(state.message),
backgroundColor: Colors.red,
),
); );
} else if (state is AuthError) {
ErrorService().showError(message: state.message);
} }
}, },
builder: (context, state) { builder: (context, state) {

View File

@@ -1,8 +1,46 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../blocs/auth/auth_bloc.dart';
import '../blocs/auth/auth_event.dart';
import '../blocs/auth/auth_state.dart';
import '../services/error_service.dart';
class ForgotPasswordPage extends StatelessWidget { class ForgotPasswordPage extends StatefulWidget {
const ForgotPasswordPage({super.key}); const ForgotPasswordPage({super.key});
@override
State<ForgotPasswordPage> createState() => _ForgotPasswordPageState();
}
class _ForgotPasswordPageState extends State<ForgotPasswordPage> {
final _emailController = TextEditingController();
final _formKey = GlobalKey<FormState>();
@override
void dispose() {
_emailController.dispose();
super.dispose();
}
String? _validateEmail(String? value) {
if (value == null || value.trim().isEmpty) {
return 'Email requis';
}
final emailRegex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
if (!emailRegex.hasMatch(value.trim())) {
return 'Email invalide';
}
return null;
}
void _submit() {
if (_formKey.currentState!.validate()) {
context.read<AuthBloc>().add(
AuthPasswordResetRequested(email: _emailController.text.trim()),
);
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@@ -16,87 +54,152 @@ class ForgotPasswordPage extends StatelessWidget {
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
elevation: 0, elevation: 0,
), ),
body: SafeArea( body: BlocListener<AuthBloc, AuthState>(
child: Padding( listener: (context, state) {
padding: const EdgeInsets.all(16.0), if (state is AuthPasswordResetSent) {
child: Center( ErrorService().showSnackbar(
child: Column( message: 'Email de réinitialisation envoyé !',
children: [ isError: false,
const Text( );
"Travel Mate", Navigator.pop(context);
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), } else if (state is AuthError) {
), ErrorService().showError(message: state.message);
}
const SizedBox(height: 24), },
child: SafeArea(
const Text( child: Padding(
"Vous avez oublié votre mot de passe ? \n Ne vous inquiétez pas vous pouvez le réinitaliser !", padding: const EdgeInsets.all(16.0),
textAlign: TextAlign.center, child: Center(
style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold), child: SingleChildScrollView(
), child: Form(
key: _formKey,
const SizedBox(height: 40), child: Column(
children: [
const Text( const Text(
"Quel est votre email ? \n Si celui-ci existe dans note base de donées, nous vous enverrons un mail avec un mot de passe unique.", "Travel Mate",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
),
const SizedBox(height: 24),
const TextField(
decoration: InputDecoration(
labelText: 'example@travelmate.com',
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12)),
),
),
),
const SizedBox(height: 40),
ElevatedButton(
onPressed: () {
// Logique de connexion
},
style: ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text('Envoyer', style: TextStyle(fontSize: 18)),
),
const SizedBox(height: 20),
Container(
width: double.infinity,
height: 1,
color: Colors.grey.shade300,
),
const SizedBox(height: 24),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Pas encore inscrit ? "),
GestureDetector(
onTap: () {
// Go to sign up page
Navigator.pushNamed(context, '/signup');
},
child: const Text(
'Inscrivez-vous !',
style: TextStyle( style: TextStyle(
color: Color.fromARGB(255, 37, 109, 167), fontSize: 24,
decoration: TextDecoration.underline, fontWeight: FontWeight.bold,
), ),
), ),
),
], const SizedBox(height: 24),
const Text(
"Vous avez oublié votre mot de passe ? \n Ne vous inquiétez pas vous pouvez le réinitaliser !",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 40),
const Text(
"Quel est votre email ? \n Si celui-ci existe dans note base de donées, nous vous enverrons un mail avec un mot de passe unique.",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 24),
TextFormField(
controller: _emailController,
validator: _validateEmail,
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
labelText: 'Email',
hintText: 'example@travelmate.com',
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12)),
),
prefixIcon: Icon(Icons.email_outlined),
),
),
const SizedBox(height: 40),
BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) {
final isLoading = state is AuthLoading;
return ElevatedButton(
onPressed: isLoading ? null : _submit,
style: ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
backgroundColor:
Theme.of(context).brightness ==
Brightness.dark
? Colors.white
: Colors.black,
foregroundColor:
Theme.of(context).brightness ==
Brightness.dark
? Colors.black
: Colors.white,
),
child: isLoading
? SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
color:
Theme.of(context).brightness ==
Brightness.dark
? Colors.black
: Colors.white,
),
)
: const Text(
'Envoyer',
style: TextStyle(fontSize: 18),
),
);
},
),
const SizedBox(height: 20),
Container(
width: double.infinity,
height: 1,
color: Colors.grey.shade300,
),
const SizedBox(height: 24),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Pas encore inscrit ? "),
GestureDetector(
onTap: () {
// Go to sign up page
Navigator.pushReplacementNamed(
context,
'/signup',
);
},
child: const Text(
'Inscrivez-vous !',
style: TextStyle(
color: Color.fromARGB(255, 37, 109, 167),
decoration: TextDecoration.underline,
),
),
),
],
),
],
),
), ),
], ),
), ),
), ),
), ),

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:sign_in_button/sign_in_button.dart'; import 'package:sign_in_button/sign_in_button.dart';
import 'package:travel_mate/components/loading/laoding_content.dart'; import 'package:travel_mate/components/loading/laoding_content.dart';
import 'package:travel_mate/components/signup/password_requirements.dart';
import 'package:travel_mate/components/signup/sign_up_platform_content.dart'; import 'package:travel_mate/components/signup/sign_up_platform_content.dart';
import 'package:travel_mate/services/auth_service.dart'; import 'package:travel_mate/services/auth_service.dart';
import '../blocs/auth/auth_bloc.dart'; import '../blocs/auth/auth_bloc.dart';
@@ -66,6 +67,18 @@ class _SignUpPageState extends State<SignUpPage> {
if (value.length < 8) { if (value.length < 8) {
return 'Le mot de passe doit contenir au moins 8 caractères'; return 'Le mot de passe doit contenir au moins 8 caractères';
} }
if (!value.contains(RegExp(r'[A-Z]'))) {
return 'Le mot de passe doit contenir une majuscule';
}
if (!value.contains(RegExp(r'[a-z]'))) {
return 'Le mot de passe doit contenir une minuscule';
}
if (!value.contains(RegExp(r'[0-9]'))) {
return 'Le mot de passe doit contenir un chiffre';
}
if (!value.contains(RegExp(r'[!@#\$%^&*(),.?":{}|<>]'))) {
return 'Le mot de passe doit contenir un caractère spécial';
}
return null; return null;
} }
@@ -115,11 +128,13 @@ class _SignUpPageState extends State<SignUpPage> {
backgroundColor: Colors.green, backgroundColor: Colors.green,
), ),
); );
Navigator.pushReplacementNamed(context, '/home'); Navigator.pushNamedAndRemoveUntil(
} else if (state is AuthError) { context,
_errorService.showError( '/home',
message: 'Erreur lors de la création du compte', (route) => false,
); );
} else if (state is AuthError) {
_errorService.showError(message: state.message);
} }
}, },
builder: (context, state) { builder: (context, state) {
@@ -211,6 +226,7 @@ class _SignUpPageState extends State<SignUpPage> {
controller: _passwordController, controller: _passwordController,
validator: _validatePassword, validator: _validatePassword,
obscureText: _obscurePassword, obscureText: _obscurePassword,
onChanged: (value) => setState(() {}),
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Mot de passe', labelText: 'Mot de passe',
border: const OutlineInputBorder( border: const OutlineInputBorder(
@@ -231,6 +247,7 @@ class _SignUpPageState extends State<SignUpPage> {
), ),
), ),
), ),
PasswordRequirements(password: _passwordController.text),
const SizedBox(height: 20), const SizedBox(height: 20),
// Champ Confirmation mot de passe // Champ Confirmation mot de passe

View File

@@ -7,7 +7,8 @@ class AccountRepository {
final FirebaseFirestore _firestore = FirebaseFirestore.instance; final FirebaseFirestore _firestore = FirebaseFirestore.instance;
final _errorService = ErrorService(); final _errorService = ErrorService();
CollectionReference get _accountCollection => _firestore.collection('accounts'); CollectionReference get _accountCollection =>
_firestore.collection('accounts');
CollectionReference _membersCollection(String accountId) { CollectionReference _membersCollection(String accountId) {
return _accountCollection.doc(accountId).collection('members'); return _accountCollection.doc(accountId).collection('members');
@@ -32,8 +33,13 @@ class AccountRepository {
return accountRef.id; return accountRef.id;
}); });
} catch (e) { } catch (e, stackTrace) {
throw Exception('Erreur lors de la création du compte: $e'); _errorService.logError(
'account_repository.dart',
'Erreur lors de la création du compte: $e',
stackTrace,
);
throw Exception('Impossible de créer le compte');
} }
} }
@@ -41,7 +47,6 @@ class AccountRepository {
return _accountCollection return _accountCollection
.snapshots() .snapshots()
.asyncMap((snapshot) async { .asyncMap((snapshot) async {
List<Account> userAccounts = []; List<Account> userAccounts = [];
for (var accountDoc in snapshot.docs) { for (var accountDoc in snapshot.docs) {
@@ -54,14 +59,24 @@ class AccountRepository {
.get(); .get();
if (memberDoc.exists) { if (memberDoc.exists) {
final accountData = accountDoc.data() as Map<String, dynamic>; final accountData = accountDoc.data() as Map<String, dynamic>;
final account = Account.fromMap(accountData, accountId); // ✅ Ajout de l'ID final account = Account.fromMap(
accountData,
accountId,
); // ✅ Ajout de l'ID
final members = await getAccountMembers(accountId); final members = await getAccountMembers(accountId);
userAccounts.add(account.copyWith(members: members)); userAccounts.add(account.copyWith(members: members));
} else { } else {
_errorService.logInfo('account_repository.dart', 'Utilisateur NON membre de $accountId'); _errorService.logInfo(
'account_repository.dart',
'Utilisateur NON membre de $accountId',
);
} }
} catch (e, stackTrace) { } catch (e, stackTrace) {
_errorService.logError(e.toString(), stackTrace); _errorService.logError(
'account_repository.dart',
'Erreur processing account doc: $e',
stackTrace,
);
} }
} }
return userAccounts; return userAccounts;
@@ -71,13 +86,18 @@ class AccountRepository {
final prevIds = prev.map((a) => a.id).toSet(); final prevIds = prev.map((a) => a.id).toSet();
final nextIds = next.map((a) => a.id).toSet(); final nextIds = next.map((a) => a.id).toSet();
final identical = prevIds.difference(nextIds).isEmpty && final identical =
nextIds.difference(prevIds).isEmpty; prevIds.difference(nextIds).isEmpty &&
nextIds.difference(prevIds).isEmpty;
return identical; return identical;
}) })
.handleError((error, stackTrace) { .handleError((error, stackTrace) {
_errorService.logError(error, stackTrace); _errorService.logError(
'account_repository.dart',
'Erreur stream accounts: $error',
stackTrace,
);
return <Account>[]; return <Account>[];
}); });
} }
@@ -85,16 +105,16 @@ class AccountRepository {
Future<List<GroupMember>> getAccountMembers(String accountId) async { Future<List<GroupMember>> getAccountMembers(String accountId) async {
try { try {
final snapshot = await _membersCollection(accountId).get(); final snapshot = await _membersCollection(accountId).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>, } catch (e, stackTrace) {
doc.id, _errorService.logError(
); 'account_repository.dart',
}) 'Erreur lors de la récupération des membres: $e',
.toList(); stackTrace,
} catch (e) { );
throw Exception('Erreur lors de la récupération des membres: $e'); throw Exception('Impossible de récupérer les membres');
} }
} }
@@ -105,8 +125,13 @@ class AccountRepository {
return Account.fromMap(doc.data() as Map<String, dynamic>, doc.id); return Account.fromMap(doc.data() as Map<String, dynamic>, doc.id);
} }
return null; return null;
} catch (e) { } catch (e, stackTrace) {
throw Exception('Erreur lors de la récupération du compte: $e'); _errorService.logError(
'account_repository.dart',
'Erreur lors de la récupération du compte: $e',
stackTrace,
);
throw Exception('Impossible de récupérer le compte');
} }
} }
@@ -123,8 +148,13 @@ class AccountRepository {
return Account.fromMap(doc.data(), doc.id); return Account.fromMap(doc.data(), doc.id);
} }
return null; return null;
} catch (e) { } catch (e, stackTrace) {
throw Exception('Erreur lors de la récupération du compte: $e'); _errorService.logError(
'account_repository.dart',
'Erreur lors de la récupération du compte: $e',
stackTrace,
);
throw Exception('Impossible de récupérer le compte');
} }
} }
@@ -132,10 +162,17 @@ class AccountRepository {
try { try {
// Mettre à jour la date de modification // Mettre à jour la date de modification
final updatedAccount = account.copyWith(updatedAt: DateTime.now()); final updatedAccount = account.copyWith(updatedAt: DateTime.now());
await _firestore.collection('accounts').doc(accountId).update(updatedAccount.toMap()); await _firestore
} catch (e) { .collection('accounts')
_errorService.logError('account_repository.dart', 'Erreur lors de la mise à jour du compte: $e'); .doc(accountId)
throw Exception('Erreur lors de la mise à jour du compte: $e'); .update(updatedAccount.toMap());
} catch (e, stackTrace) {
_errorService.logError(
'account_repository.dart',
'Erreur lors de la mise à jour du compte: $e',
stackTrace,
);
throw Exception('Impossible de mettre à jour le compte');
} }
} }
@@ -159,21 +196,25 @@ class AccountRepository {
// Supprimer le compte // Supprimer le compte
await _accountCollection.doc(docId).delete(); await _accountCollection.doc(docId).delete();
} catch (e) { } catch (e, stackTrace) {
_errorService.logError('account_repository.dart', 'Erreur lors de la suppression du compte: $e'); _errorService.logError(
throw Exception('Erreur lors de la suppression du compte: $e'); 'account_repository.dart',
'Erreur lors de la suppression du compte: $e',
stackTrace,
);
throw Exception('Impossible de supprimer le compte');
} }
} }
Stream<List<GroupMember>> watchGroupMembers(String accountId) { Stream<List<GroupMember>> watchGroupMembers(String accountId) {
return _membersCollection(accountId).snapshots().map( return _membersCollection(accountId).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(),
); );
} }
Stream<Account?> watchAccount(String accountId) { Stream<Account?> watchAccount(String accountId) {
@@ -198,4 +239,35 @@ 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, stackTrace) {
_errorService.logError(
'account_repository.dart',
'Erreur lors de l\'ajout du membre: $e',
stackTrace,
);
throw Exception('Impossible d\'ajouter le membre');
}
}
Future<void> removeMemberFromAccount(
String accountId,
String memberId,
) async {
try {
await _membersCollection(accountId).doc(memberId).delete();
} catch (e, stackTrace) {
_errorService.logError(
'account_repository.dart',
'Erreur lors de la suppression du membre: $e',
stackTrace,
);
throw Exception('Impossible de supprimer le membre');
}
}
} }

View File

@@ -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',
'Ajout d\'une activité: ${activity.name}',
);
final docRef = await _firestore.collection(_collection).add(activity.toMap()); 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,7 +49,10 @@ 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
@@ -51,19 +68,36 @@ 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);
@@ -71,8 +105,14 @@ class ActivityRepository {
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,36 +151,61 @@ 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);
@@ -157,10 +234,13 @@ class ActivityRepository {
}); });
}); });
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,7 +279,10 @@ 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>[];
@@ -207,19 +296,28 @@ class ActivityRepository {
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
@@ -237,14 +335,23 @@ 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);
@@ -262,7 +369,10 @@ class ActivityRepository {
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 [];
} }
@@ -284,7 +394,10 @@ class ActivityRepository {
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;
} }
} }

View File

@@ -3,6 +3,7 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import '../models/user.dart'; import '../models/user.dart';
import '../services/auth_service.dart'; import '../services/auth_service.dart';
import '../services/error_service.dart'; import '../services/error_service.dart';
import '../services/notification_service.dart';
/// Repository for authentication operations and user data management. /// Repository for authentication operations and user data management.
/// ///
@@ -57,11 +58,12 @@ class AuthRepository {
email: email, email: email,
password: password, password: password,
); );
await _saveFCMToken(firebaseUser.user!.uid);
return await getUserFromFirestore(firebaseUser.user!.uid); return await getUserFromFirestore(firebaseUser.user!.uid);
} catch (e) { } catch (e, stackTrace) {
_errorService.showError(message: 'Utilisateur ou mot de passe incorrect'); _errorService.logError('AuthRepository', 'SignIn error: $e', stackTrace);
throw Exception('Utilisateur ou mot de passe incorrect');
} }
return null;
} }
/// Creates a new user account with email and password. /// Creates a new user account with email and password.
@@ -102,11 +104,14 @@ class AuthRepository {
); );
await _firestore.collection('users').doc(user.id).set(user.toMap()); await _firestore.collection('users').doc(user.id).set(user.toMap());
if (user.id != null) {
await _saveFCMToken(user.id!);
}
return user; return user;
} catch (e) { } catch (e, stackTrace) {
_errorService.showError(message: 'Erreur lors de la création du compte'); _errorService.logError('AuthRepository', 'SignUp error: $e', stackTrace);
throw Exception('Erreur lors de la création du compte');
} }
return null;
} }
/// Signs in a user using Google authentication. /// Signs in a user using Google authentication.
@@ -122,11 +127,16 @@ class AuthRepository {
String firstname, String firstname,
) async { ) async {
try { try {
final firebaseUser = await _authService.signInWithGoogle(); firebase_auth.User? firebaseUser = _authService.currentUser;
if (firebaseUser.user != null) { if (firebaseUser == null) {
final userCredential = await _authService.signInWithGoogle();
firebaseUser = userCredential.user;
}
if (firebaseUser != null) {
// Check if user already exists in Firestore // Check if user already exists in Firestore
final existingUser = await getUserFromFirestore(firebaseUser.user!.uid); final existingUser = await getUserFromFirestore(firebaseUser.uid);
if (existingUser != null) { if (existingUser != null) {
return existingUser; return existingUser;
@@ -134,23 +144,30 @@ class AuthRepository {
// Create new user document for first-time Google sign-in // Create new user document for first-time Google sign-in
final user = User( final user = User(
id: firebaseUser.user!.uid, id: firebaseUser.uid,
email: firebaseUser.user!.email ?? '', email: firebaseUser.email ?? '',
nom: name, nom: name,
prenom: firstname, prenom: firstname,
phoneNumber: phoneNumber, phoneNumber: phoneNumber,
profilePictureUrl: firebaseUser.user!.photoURL ?? 'Unknown', profilePictureUrl: firebaseUser.photoURL ?? 'Unknown',
platform: 'google', platform: 'google',
); );
await _firestore.collection('users').doc(user.id).set(user.toMap()); await _firestore.collection('users').doc(user.id).set(user.toMap());
if (user.id != null) {
await _saveFCMToken(user.id!);
}
return user; return user;
} }
return null; return null;
} catch (e) { } catch (e, stackTrace) {
_errorService.showError(message: 'Erreur lors de la connexion Google'); _errorService.logError(
'AuthRepository',
'Google SignUp error: $e',
stackTrace,
);
throw Exception('Erreur lors de la connexion Google');
} }
return null;
} }
Future<User?> signInWithGoogle() async { Future<User?> signInWithGoogle() async {
@@ -158,14 +175,21 @@ class AuthRepository {
final firebaseUser = await _authService.signInWithGoogle(); final firebaseUser = await _authService.signInWithGoogle();
final user = await getUserFromFirestore(firebaseUser.user!.uid); final user = await getUserFromFirestore(firebaseUser.user!.uid);
if (user != null) { if (user != null) {
if (user.id != null) {
await _saveFCMToken(user.id!);
}
return user; return user;
} else { } else {
throw Exception('Utilisateur non trouvé'); throw Exception('Utilisateur non trouvé');
} }
} catch (e) { } catch (e, stackTrace) {
_errorService.showError(message: 'Erreur lors de la connexion Google'); _errorService.logError(
'AuthRepository',
'Google SignIn error: $e',
stackTrace,
);
throw Exception('Erreur lors de la connexion Google');
} }
return null;
} }
/// Signs in a user using Apple authentication. /// Signs in a user using Apple authentication.
@@ -181,33 +205,45 @@ class AuthRepository {
String firstname, String firstname,
) async { ) async {
try { try {
final firebaseUser = await _authService.signInWithApple(); firebase_auth.User? firebaseUser = _authService.currentUser;
if (firebaseUser.user != null) { if (firebaseUser == null) {
final existingUser = await getUserFromFirestore(firebaseUser.user!.uid); final userCredential = await _authService.signInWithApple();
firebaseUser = userCredential.user;
}
if (firebaseUser != null) {
final existingUser = await getUserFromFirestore(firebaseUser.uid);
if (existingUser != null) { if (existingUser != null) {
return existingUser; return existingUser;
} }
final user = User( final user = User(
id: firebaseUser.user!.uid, id: firebaseUser.uid,
email: firebaseUser.user!.email ?? '', email: firebaseUser.email ?? '',
nom: name, nom: name,
prenom: firstname, prenom: firstname,
phoneNumber: phoneNumber, phoneNumber: phoneNumber,
profilePictureUrl: firebaseUser.user!.photoURL ?? 'Unknown', profilePictureUrl: firebaseUser.photoURL ?? 'Unknown',
platform: 'apple', platform: 'apple',
); );
await _firestore.collection('users').doc(user.id).set(user.toMap()); await _firestore.collection('users').doc(user.id).set(user.toMap());
if (user.id != null) {
await _saveFCMToken(user.id!);
}
return user; return user;
} }
return null; return null;
} catch (e) { } catch (e, stackTrace) {
_errorService.showError(message: 'Erreur lors de la connexion Apple'); _errorService.logError(
'AuthRepository',
'Apple SignUp error: $e',
stackTrace,
);
throw Exception('Erreur lors de la connexion Apple');
} }
return null;
} }
Future<User?> signInWithApple() async { Future<User?> signInWithApple() async {
@@ -215,14 +251,21 @@ class AuthRepository {
final firebaseUser = await _authService.signInWithApple(); final firebaseUser = await _authService.signInWithApple();
final user = await getUserFromFirestore(firebaseUser.user!.uid); final user = await getUserFromFirestore(firebaseUser.user!.uid);
if (user != null) { if (user != null) {
if (user.id != null) {
await _saveFCMToken(user.id!);
}
return user; return user;
} else { } else {
throw Exception('Utilisateur non trouvé'); throw Exception('Utilisateur non trouvé');
} }
} catch (e) { } catch (e, stackTrace) {
_errorService.showError(message: 'Erreur lors de la connexion Apple'); _errorService.logError(
'AuthRepository',
'Apple SignIn error: $e',
stackTrace,
);
throw Exception('Erreur lors de la connexion Apple');
} }
return null;
} }
/// Signs out the current user. /// Signs out the current user.
@@ -248,7 +291,7 @@ class AuthRepository {
/// ///
/// [uid] - The Firebase user ID to look up /// [uid] - The Firebase user ID to look up
/// ///
/// Returns the [User] model if found, null otherwise. /// Returns the [User] model if successful, null otherwise.
Future<User?> getUserFromFirestore(String uid) async { Future<User?> getUserFromFirestore(String uid) async {
try { try {
final doc = await _firestore.collection('users').doc(uid).get(); final doc = await _firestore.collection('users').doc(uid).get();
@@ -261,4 +304,23 @@ class AuthRepository {
return null; return null;
} }
} }
/// Helper method to save the FCM token for the authenticated user.
Future<void> _saveFCMToken(String userId) async {
try {
final token = await NotificationService().getFCMToken();
if (token != null) {
await _firestore.collection('users').doc(userId).set({
'fcmToken': token,
}, SetOptions(merge: true));
}
} catch (e, stackTrace) {
// Non-blocking error
_errorService.logError(
'AuthRepository',
'Error saving FCM token: $e',
stackTrace,
);
}
}
} }

View File

@@ -37,9 +37,13 @@ class BalanceRepository {
totalExpenses: totalExpenses, totalExpenses: totalExpenses,
calculatedAt: DateTime.now(), calculatedAt: DateTime.now(),
); );
} catch (e) { } catch (e, stackTrace) {
_errorService.logError('BalanceRepository', 'Erreur calcul balance: $e'); _errorService.logError(
rethrow; 'BalanceRepository',
'Erreur calcul balance: $e',
stackTrace,
);
throw Exception('Impossible de calculer la balance');
} }
} }
@@ -50,9 +54,13 @@ class BalanceRepository {
.first; .first;
return _calculateUserBalances(expenses); return _calculateUserBalances(expenses);
} catch (e) { } catch (e, stackTrace) {
_errorService.logError('BalanceRepository', 'Erreur calcul user balances: $e'); _errorService.logError(
rethrow; 'BalanceRepository',
'Erreur calcul user balances: $e',
stackTrace,
);
throw Exception('Impossible de calculer les balances utilisateurs');
} }
} }
@@ -65,19 +73,17 @@ class BalanceRepository {
if (expense.isArchived) continue; if (expense.isArchived) continue;
// Ajouter le payeur // Ajouter le payeur
userBalanceMap.putIfAbsent(expense.paidById, () => { userBalanceMap.putIfAbsent(
'name': expense.paidByName, expense.paidById,
'paid': 0.0, () => {'name': expense.paidByName, 'paid': 0.0, 'owed': 0.0},
'owed': 0.0, );
});
// Ajouter les participants // Ajouter les participants
for (final split in expense.splits) { for (final split in expense.splits) {
userBalanceMap.putIfAbsent(split.userId, () => { userBalanceMap.putIfAbsent(
'name': split.userName, split.userId,
'paid': 0.0, () => {'name': split.userName, 'paid': 0.0, 'owed': 0.0},
'owed': 0.0, );
});
} }
} }
@@ -125,10 +131,10 @@ class BalanceRepository {
// Créer des copies mutables des montants // Créer des copies mutables des montants
final creditorsRemaining = Map.fromEntries( final creditorsRemaining = Map.fromEntries(
creditors.map((c) => MapEntry(c.userId, c.balance)) creditors.map((c) => MapEntry(c.userId, c.balance)),
); );
final debtorsRemaining = Map.fromEntries( final debtorsRemaining = Map.fromEntries(
debtors.map((d) => MapEntry(d.userId, -d.balance)) debtors.map((d) => MapEntry(d.userId, -d.balance)),
); );
// Algorithme glouton pour minimiser le nombre de transactions // Algorithme glouton pour minimiser le nombre de transactions
@@ -139,15 +145,20 @@ class BalanceRepository {
if (creditAmount <= 0.01 || debtAmount <= 0.01) continue; if (creditAmount <= 0.01 || debtAmount <= 0.01) continue;
final settlementAmount = [creditAmount, debtAmount].reduce((a, b) => a < b ? a : b); final settlementAmount = [
creditAmount,
debtAmount,
].reduce((a, b) => a < b ? a : b);
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,
),
);
creditorsRemaining[creditor.userId] = creditAmount - settlementAmount; creditorsRemaining[creditor.userId] = creditAmount - settlementAmount;
debtorsRemaining[debtor.userId] = debtAmount - settlementAmount; debtorsRemaining[debtor.userId] = debtAmount - settlementAmount;

View File

@@ -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');
@@ -21,7 +23,9 @@ class GroupRepository {
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) {
@@ -31,60 +35,32 @@ class GroupRepository {
return groupRef.id; return groupRef.id;
}); });
} catch (e) { } catch (e, stackTrace) {
throw Exception('Erreur lors de la création du groupe: $e'); _errorService.logError(
'GroupRepository',
'Erreur création groupe: $e',
stackTrace,
);
throw Exception('Impossible de créer le groupe');
} }
} }
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(
'GroupRepository',
'Erreur stream groups: $error',
stackTrace,
);
return <Group>[]; return <Group>[];
}); });
} }
@@ -99,18 +75,42 @@ class GroupRepository {
final members = await getGroupMembers(groupId); final members = await getGroupMembers(groupId);
return group.copyWith(members: members); return group.copyWith(members: members);
} catch (e) { } catch (e, stackTrace) {
throw Exception('Erreur lors de la récupération du groupe: $e'); _errorService.logError(
'GroupRepository',
'Erreur get group: $e',
stackTrace,
);
throw Exception('Impossible de récupérer le groupe');
} }
} }
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;
@@ -118,94 +118,210 @@ class GroupRepository {
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, stackTrace) {
throw Exception('Erreur lors de la récupération du groupe: $e'); _errorService.logError(
'GroupRepository',
'Erreur get group by trip: $e',
stackTrace,
);
throw Exception('Impossible de récupérer le groupe du voyage');
}
}
/// 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, stackTrace) {
_errorService.logError(
'GroupRepository',
'Erreur de migration pour le groupe $groupId: $e',
stackTrace,
);
} }
} }
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>, } catch (e, stackTrace) {
doc.id, _errorService.logError(
); 'GroupRepository',
}) 'Erreur get members: $e',
.toList(); stackTrace,
} catch (e) { );
throw Exception('Erreur lors de la récupération des membres: $e'); throw Exception('Impossible de récupérer les membres');
} }
} }
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]),
}); });
} catch (e) {
throw Exception('Erreur lors de l\'ajout du membre: $e'); // 4. Mettre à jour la liste participants du voyage
await _firestore.collection('trips').doc(group.tripId).update({
'participants': FieldValue.arrayUnion([member.userId]),
});
} catch (e, stackTrace) {
_errorService.logError(
'GroupRepository',
'Erreur add member: $e',
stackTrace,
);
throw Exception('Impossible d\'ajouter le membre');
} }
} }
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]),
}); });
} catch (e) {
throw Exception('Erreur lors de la suppression du membre: $e'); // 4. Mettre à jour la liste participants du voyage
await _firestore.collection('trips').doc(group.tripId).update({
'participants': FieldValue.arrayRemove([userId]),
});
} catch (e, stackTrace) {
_errorService.logError(
'GroupRepository',
'Erreur remove member: $e',
stackTrace,
);
throw Exception('Impossible de supprimer le membre');
} }
} }
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, stackTrace) {
throw Exception('Erreur lors de la mise à jour du groupe: $e'); _errorService.logError(
'GroupRepository',
'Erreur update group: $e',
stackTrace,
);
throw Exception('Impossible de mettre à jour le groupe');
} }
} }
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, stackTrace) {
_errorService.logError(
'GroupRepository',
'Erreur delete group: $e',
stackTrace,
);
throw Exception('Impossible de supprimer le groupe');
} }
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(),
); );
}
Future<void> updateMemberDetails({
required String userId,
String? firstName,
String? lastName,
String? profilePictureUrl,
}) async {
try {
// 1. Trouver tous les groupes où l'utilisateur est membre
final groupsSnapshot = await _groupsCollection
.where('memberIds', arrayContains: userId)
.get();
// 2. Mettre à jour les infos du membre dans chaque groupe
for (final groupDoc in groupsSnapshot.docs) {
final memberRef = _membersCollection(groupDoc.id).doc(userId);
final updates = <String, dynamic>{};
if (firstName != null) updates['firstName'] = firstName;
if (lastName != null) updates['lastName'] = lastName;
if (profilePictureUrl != null) {
updates['profilePictureUrl'] = profilePictureUrl;
}
if (updates.isNotEmpty) {
await memberRef.update(updates);
}
}
} catch (e, stackTrace) {
_errorService.logError(
'GroupRepository',
'Erreur update member details: $e',
stackTrace,
);
// On ne throw pas d'exception ici pour ne pas bloquer l'update user principal
// C'est une opération "best effort"
}
} }
} }

View File

@@ -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

View File

@@ -1,8 +1,10 @@
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import '../models/trip.dart'; import '../models/trip.dart';
import '../services/error_service.dart';
class TripRepository { class TripRepository {
final FirebaseFirestore _firestore = FirebaseFirestore.instance; final FirebaseFirestore _firestore = FirebaseFirestore.instance;
final _errorService = ErrorService();
CollectionReference get _tripsCollection => _firestore.collection('trips'); CollectionReference get _tripsCollection => _firestore.collection('trips');
@@ -13,21 +15,31 @@ class TripRepository {
.where('participants', arrayContains: userId) .where('participants', arrayContains: userId)
.snapshots() .snapshots()
.map((snapshot) { .map((snapshot) {
final trips = snapshot.docs final trips = snapshot.docs
.map((doc) { .map((doc) {
try { try {
final data = doc.data() as Map<String, dynamic>; final data = doc.data() as Map<String, dynamic>;
return Trip.fromMap(data, doc.id); return Trip.fromMap(data, doc.id);
} catch (e) { } catch (e, stackTrace) {
return null; _errorService.logError(
} 'TripRepository',
}) 'Erreur parsing trip ${doc.id}: $e',
.whereType<Trip>() stackTrace,
.toList(); );
return trips; return null;
}); }
} catch (e) { })
throw Exception('Erreur lors de la récupération des voyages: $e'); .whereType<Trip>()
.toList();
return trips;
});
} catch (e, stackTrace) {
_errorService.logError(
'TripRepository',
'Erreur stream trips: $e',
stackTrace,
);
throw Exception('Impossible de récupérer les voyages');
} }
} }
@@ -38,8 +50,13 @@ class TripRepository {
// Ne pas modifier les timestamps ici, ils sont déjà au bon format // Ne pas modifier les timestamps ici, ils sont déjà au bon format
final docRef = await _tripsCollection.add(tripData); final docRef = await _tripsCollection.add(tripData);
return docRef.id; return docRef.id;
} catch (e) { } catch (e, stackTrace) {
throw Exception('Erreur lors de la création du voyage: $e'); _errorService.logError(
'TripRepository',
'Erreur création trip: $e',
stackTrace,
);
throw Exception('Impossible de créer le voyage');
} }
} }
@@ -53,8 +70,13 @@ class TripRepository {
} }
return Trip.fromMap(doc.data() as Map<String, dynamic>, doc.id); return Trip.fromMap(doc.data() as Map<String, dynamic>, doc.id);
} catch (e) { } catch (e, stackTrace) {
throw Exception('Erreur lors de la récupération du voyage: $e'); _errorService.logError(
'TripRepository',
'Erreur get trip: $e',
stackTrace,
);
throw Exception('Impossible de récupérer le voyage');
} }
} }
@@ -66,8 +88,13 @@ class TripRepository {
tripData['updatedAt'] = Timestamp.now(); tripData['updatedAt'] = Timestamp.now();
await _tripsCollection.doc(tripId).update(tripData); await _tripsCollection.doc(tripId).update(tripData);
} catch (e) { } catch (e, stackTrace) {
throw Exception('Erreur lors de la mise à jour du voyage: $e'); _errorService.logError(
'TripRepository',
'Erreur update trip: $e',
stackTrace,
);
throw Exception('Impossible de mettre à jour le voyage');
} }
} }
@@ -75,8 +102,13 @@ class TripRepository {
Future<void> deleteTrip(String tripId) async { Future<void> deleteTrip(String tripId) async {
try { try {
await _tripsCollection.doc(tripId).delete(); await _tripsCollection.doc(tripId).delete();
} catch (e) { } catch (e, stackTrace) {
throw Exception('Erreur lors de la suppression du voyage: $e'); _errorService.logError(
'TripRepository',
'Erreur delete trip: $e',
stackTrace,
);
throw Exception('Impossible de supprimer le voyage');
} }
} }
} }

View File

@@ -1,6 +1,7 @@
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import '../models/user.dart'; import '../models/user.dart';
import '../services/auth_service.dart'; import '../services/auth_service.dart';
import '../services/error_service.dart';
/// Repository for user data operations in Firestore. /// Repository for user data operations in Firestore.
/// ///
@@ -14,14 +15,14 @@ class UserRepository {
/// Authentication service for user-related operations. /// Authentication service for user-related operations.
final AuthService _authService; final AuthService _authService;
final _errorService = ErrorService();
/// Creates a new [UserRepository] with optional dependencies. /// Creates a new [UserRepository] with optional dependencies.
/// ///
/// If [firestore] or [authService] are not provided, default instances will be used. /// If [firestore] or [authService] are not provided, default instances will be used.
UserRepository({ UserRepository({FirebaseFirestore? firestore, AuthService? authService})
FirebaseFirestore? firestore, : _firestore = firestore ?? FirebaseFirestore.instance,
AuthService? authService, _authService = authService ?? AuthService();
}) : _firestore = firestore ?? FirebaseFirestore.instance,
_authService = authService ?? AuthService();
/// Retrieves a user by their unique ID. /// Retrieves a user by their unique ID.
/// ///
@@ -39,8 +40,13 @@ class UserRepository {
return User.fromMap({...data, 'id': uid}); return User.fromMap({...data, 'id': uid});
} }
return null; return null;
} catch (e) { } catch (e, stackTrace) {
throw Exception('Error retrieving user: $e'); _errorService.logError(
'UserRepository',
'Error retrieving user: $e',
stackTrace,
);
throw Exception('Impossible de récupérer l\'utilisateur');
} }
} }
@@ -67,8 +73,13 @@ class UserRepository {
return User.fromMap({...data, 'id': doc.id}); return User.fromMap({...data, 'id': doc.id});
} }
return null; return null;
} catch (e) { } catch (e, stackTrace) {
throw Exception('Error searching for user: $e'); _errorService.logError(
'UserRepository',
'Error searching for user: $e',
stackTrace,
);
throw Exception('Impossible de trouver l\'utilisateur');
} }
} }
@@ -87,8 +98,13 @@ class UserRepository {
await _authService.updateDisplayName(displayName: user.fullName); await _authService.updateDisplayName(displayName: user.fullName);
return true; return true;
} catch (e) { } catch (e, stackTrace) {
throw Exception('Erreur lors de la mise à jour: $e'); _errorService.logError(
'UserRepository',
'Erreur lors de la mise à jour: $e',
stackTrace,
);
throw Exception('Impossible de mettre à jour l\'utilisateur');
} }
} }
@@ -98,8 +114,13 @@ class UserRepository {
await _firestore.collection('users').doc(uid).delete(); await _firestore.collection('users').doc(uid).delete();
// Note: Vous devrez également supprimer le compte Firebase Auth // Note: Vous devrez également supprimer le compte Firebase Auth
return true; return true;
} catch (e) { } catch (e, stackTrace) {
throw Exception('Erreur lors de la suppression: $e'); _errorService.logError(
'UserRepository',
'Erreur lors de la suppression: $e',
stackTrace,
);
throw Exception('Impossible de supprimer l\'utilisateur');
} }
} }
@@ -120,8 +141,52 @@ class UserRepository {
newPassword: newPassword, newPassword: newPassword,
); );
return true; return true;
} catch (e) { } catch (e, stackTrace) {
throw Exception('Erreur lors du changement de mot de passe: $e'); _errorService.logError(
'UserRepository',
'Erreur lors du changement de mot de passe: $e',
stackTrace,
);
throw Exception('Impossible de changer le mot de passe');
}
}
// Récupérer plusieurs utilisateurs par leurs IDs
Future<List<User>> getUsersByIds(List<String> uids) async {
if (uids.isEmpty) return [];
try {
// Firestore 'in' query supports up to 10 values.
// If we have more, we need to split into chunks.
List<User> users = [];
// Remove duplicates
final uniqueIds = uids.toSet().toList();
// Split into chunks of 10
for (var i = 0; i < uniqueIds.length; i += 10) {
final end = (i + 10 < uniqueIds.length) ? i + 10 : uniqueIds.length;
final chunk = uniqueIds.sublist(i, end);
final querySnapshot = await _firestore
.collection('users')
.where(FieldPath.documentId, whereIn: chunk)
.get();
for (var doc in querySnapshot.docs) {
final data = doc.data();
users.add(User.fromMap({...data, 'id': doc.id}));
}
}
return users;
} catch (e, stackTrace) {
_errorService.logError(
'UserRepository',
'Error retrieving users by IDs: $e',
stackTrace,
);
return [];
} }
} }
} }

View File

@@ -1,8 +1,10 @@
import 'dart:io';
import 'dart:convert'; import 'dart:convert';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:flutter_dotenv/flutter_dotenv.dart'; import '../firebase_options.dart'; // Add this import
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 {
@@ -12,7 +14,17 @@ class ActivityPlacesService {
ActivityPlacesService._internal(); ActivityPlacesService._internal();
final ErrorService _errorService = ErrorService(); final ErrorService _errorService = ErrorService();
static final String _apiKey = dotenv.env['GOOGLE_MAPS_API_KEY'] ?? '';
static String get _apiKey {
try {
return DefaultFirebaseOptions.currentPlatform.apiKey;
} catch (e) {
LoggerService.error(
'ActivityPlacesService: Impossible de récupérer la clé API Firebase: $e',
);
return '';
}
}
/// Recherche des activités près d'une destination /// Recherche des activités près d'une destination
Future<List<Activity>> searchActivities({ Future<List<Activity>> searchActivities({
@@ -23,81 +35,75 @@ class ActivityPlacesService {
int maxResults = 20, int maxResults = 20,
int offset = 0, int offset = 0,
}) async { }) async {
try { LoggerService.info(
print( 'ActivityPlacesService: Recherche d\'activités pour: $destination (max: $maxResults, offset: $offset)',
'ActivityPlacesService: Recherche d\'activités pour: $destination (max: $maxResults, offset: $offset)', );
// 1. Géocoder la destination
final coordinates = await _geocodeDestination(destination);
// 2. Rechercher les activités par catégorie ou toutes les catégories
List<Activity> allActivities = [];
if (category != null) {
final activities = await _searchByCategory(
coordinates['lat']!,
coordinates['lng']!,
category,
tripId,
radius,
); );
allActivities.addAll(activities);
} else {
// Rechercher dans toutes les catégories principales
final mainCategories = [
ActivityCategory.attraction,
ActivityCategory.museum,
ActivityCategory.restaurant,
ActivityCategory.culture,
ActivityCategory.nature,
];
// 1. Géocoder la destination for (final cat in mainCategories) {
final coordinates = await _geocodeDestination(destination);
// 2. Rechercher les activités par catégorie ou toutes les catégories
List<Activity> allActivities = [];
if (category != null) {
final activities = await _searchByCategory( final activities = await _searchByCategory(
coordinates['lat']!, coordinates['lat']!,
coordinates['lng']!, coordinates['lng']!,
category, cat,
tripId, tripId,
radius, radius,
); );
allActivities.addAll(activities); allActivities.addAll(activities);
} else {
// Rechercher dans toutes les catégories principales
final mainCategories = [
ActivityCategory.attraction,
ActivityCategory.museum,
ActivityCategory.restaurant,
ActivityCategory.culture,
ActivityCategory.nature,
];
for (final cat in mainCategories) {
final activities = await _searchByCategory(
coordinates['lat']!,
coordinates['lng']!,
cat,
tripId,
radius,
);
allActivities.addAll(activities);
}
} }
}
// 3. Supprimer les doublons et trier par note // 3. Supprimer les doublons et trier par note
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',
);
// 4. Appliquer la pagination
final startIndex = offset;
final endIndex = (startIndex + maxResults).clamp(
0,
uniqueActivities.length,
);
if (startIndex >= uniqueActivities.length) {
LoggerService.info(
'ActivityPlacesService: Offset $startIndex dépasse le nombre total (${uniqueActivities.length})',
); );
// 4. Appliquer la pagination
final startIndex = offset;
final endIndex = (startIndex + maxResults).clamp(
0,
uniqueActivities.length,
);
if (startIndex >= uniqueActivities.length) {
print(
'ActivityPlacesService: Offset $startIndex dépasse le nombre total (${uniqueActivities.length})',
);
return [];
}
final paginatedResults = uniqueActivities.sublist(startIndex, endIndex);
print(
'ActivityPlacesService: Retour de ${paginatedResults.length} activités (offset: $offset, max: $maxResults)',
);
return paginatedResults;
} catch (e) {
print('ActivityPlacesService: Erreur lors de la recherche: $e');
_errorService.logError('activity_places_service', e);
return []; return [];
} }
final paginatedResults = uniqueActivities.sublist(startIndex, endIndex);
LoggerService.info(
'ActivityPlacesService: Retour de ${paginatedResults.length} activités (offset: $offset, max: $maxResults)',
);
return paginatedResults;
} }
/// Géocode une destination pour obtenir les coordonnées /// Géocode une destination pour obtenir les coordonnées
@@ -105,24 +111,36 @@ 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(
throw Exception('Clé API Google Maps non configurée'); 'ActivityPlacesService: Clé API Google Maps manquante',
);
throw Exception(
'Clé API Google Maps non configurée dans DefaultFirebaseOptions. Platform: ${Platform.isAndroid
? 'Android'
: Platform.isIOS
? 'iOS'
: 'Autre'}',
);
} }
final encodedDestination = Uri.encodeComponent(destination); final encodedDestination = Uri.encodeComponent(destination);
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&language=fr';
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 +148,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 +174,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
} }
} }
@@ -167,45 +187,52 @@ class ActivityPlacesService {
String tripId, String tripId,
int radius, int radius,
) async { ) async {
try { final url =
final url = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json'
'https://maps.googleapis.com/maps/api/place/nearbysearch/json' '?location=$lat,$lng'
'?location=$lat,$lng' '&radius=$radius'
'&radius=$radius' '&type=${category.googlePlaceType}'
'&type=${category.googlePlaceType}' '&key=$_apiKey'
'&key=$_apiKey'; '&language=fr';
final response = await http.get(Uri.parse(url)); final response = await http.get(Uri.parse(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 List<Activity> activities = []; final List<Activity> activities = [];
for (final place in data['results']) { for (final place in data['results']) {
try { try {
final activity = await _convertPlaceToActivity( final activity = await _convertPlaceToActivity(
place, place,
tripId, tripId,
category, category,
); );
if (activity != null) { if (activity != null) {
activities.add(activity); activities.add(activity);
}
} catch (e) {
print('ActivityPlacesService: Erreur conversion place: $e');
} }
} catch (e) {
LoggerService.error(
'ActivityPlacesService: Erreur conversion place: $e',
);
} }
return activities;
} }
}
return []; return activities;
} catch (e) { } else if (data['status'] == 'ZERO_RESULTS') {
print('ActivityPlacesService: Erreur recherche par catégorie: $e'); return [];
return []; } else {
LoggerService.error(
'ActivityPlacesService: Erreur API Places: ${data['status']} - ${data['error_message']}',
);
throw Exception(
'API Places Error: ${data['status']} - ${data['error_message']}',
);
}
} else {
throw Exception('Erreur HTTP ${response.statusCode}');
} }
} }
@@ -260,7 +287,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;
} }
} }
@@ -272,7 +299,8 @@ class ActivityPlacesService {
'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=formatted_address,formatted_phone_number,website,opening_hours,editorial_summary' '&fields=formatted_address,formatted_phone_number,website,opening_hours,editorial_summary'
'&key=$_apiKey'; '&key=$_apiKey'
'&language=fr';
final response = await http.get(Uri.parse(url)); final response = await http.get(Uri.parse(url));
@@ -285,7 +313,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;
} }
} }
@@ -325,57 +355,62 @@ class ActivityPlacesService {
required String tripId, required String tripId,
int radius = 5000, int radius = 5000,
}) async { }) async {
try { LoggerService.info(
print( 'ActivityPlacesService: Recherche textuelle: $query à $destination',
'ActivityPlacesService: Recherche textuelle: $query à $destination', );
);
// Géocoder la destination // Géocoder la destination
final coordinates = await _geocodeDestination(destination); final coordinates = await _geocodeDestination(destination);
final encodedQuery = Uri.encodeComponent(query); final encodedQuery = Uri.encodeComponent(query);
final url = final url =
'https://maps.googleapis.com/maps/api/place/textsearch/json' 'https://maps.googleapis.com/maps/api/place/textsearch/json'
'?query=$encodedQuery in $destination' '?query=$encodedQuery'
'&location=${coordinates['lat']},${coordinates['lng']}' '&location=${coordinates['lat']},${coordinates['lng']}'
'&radius=$radius' '&radius=$radius'
'&key=$_apiKey'; '&key=$_apiKey'
'&language=fr';
final response = await http.get(Uri.parse(url)); final response = await http.get(Uri.parse(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 List<Activity> activities = []; final List<Activity> activities = [];
for (final place in data['results']) { for (final place in data['results']) {
try { try {
// Déterminer la catégorie basée sur les types du lieu // Déterminer la catégorie basée sur les types du lieu
final types = List<String>.from(place['types'] ?? []); final types = List<String>.from(place['types'] ?? []);
final category = _determineCategoryFromTypes(types); final category = _determineCategoryFromTypes(types);
final activity = await _convertPlaceToActivity( final activity = await _convertPlaceToActivity(
place, place,
tripId, tripId,
category, category,
); );
if (activity != null) { if (activity != null) {
activities.add(activity); activities.add(activity);
}
} catch (e) {
print('ActivityPlacesService: Erreur conversion place: $e');
} }
} catch (e) {
LoggerService.error(
'ActivityPlacesService: Erreur conversion place: $e',
);
} }
return activities;
} }
}
return []; return activities;
} catch (e) { } else if (data['status'] == 'ZERO_RESULTS') {
print('ActivityPlacesService: Erreur recherche textuelle: $e'); return [];
return []; } else {
LoggerService.error(
'ActivityPlacesService: Erreur API Places Text Search: ${data['status']}',
);
throw Exception('API Error: ${data['status']}');
}
} else {
throw Exception('Erreur HTTP ${response.statusCode}');
} }
} }
@@ -423,11 +458,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 +472,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 +499,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>[],
@@ -484,65 +521,63 @@ class ActivityPlacesService {
int pageSize, int pageSize,
String? nextPageToken, String? nextPageToken,
) async { ) async {
try { String url =
String url = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json'
'https://maps.googleapis.com/maps/api/place/nearbysearch/json' '?location=$lat,$lng'
'?location=$lat,$lng' '&radius=$radius'
'&radius=$radius' '&type=${category.googlePlaceType}'
'&type=${category.googlePlaceType}' '&key=$_apiKey'
'&key=$_apiKey'; '&language=fr';
if (nextPageToken != null) { if (nextPageToken != null) {
url += '&pagetoken=$nextPageToken'; url += '&pagetoken=$nextPageToken';
} }
final response = await http.get(Uri.parse(url)); final response = await http.get(Uri.parse(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 List<Activity> activities = []; final List<Activity> activities = [];
final results = data['results'] as List? ?? []; final results = data['results'] as List? ?? [];
// Limiter à pageSize résultats // Limiter à pageSize résultats
final limitedResults = results.take(pageSize).toList(); final limitedResults = results.take(pageSize).toList();
for (final place in limitedResults) { for (final place in limitedResults) {
try { try {
final activity = await _convertPlaceToActivity( final activity = await _convertPlaceToActivity(
place, place,
tripId, tripId,
category, category,
); );
if (activity != null) { if (activity != null) {
activities.add(activity); activities.add(activity);
}
} catch (e) {
print('ActivityPlacesService: Erreur conversion place: $e');
} }
} catch (e) {
LoggerService.error(
'ActivityPlacesService: Erreur conversion place: $e',
);
} }
return {
'activities': activities,
'nextPageToken': data['next_page_token'],
'hasMoreData': data['next_page_token'] != null,
};
} }
}
return { return {
'activities': <Activity>[], 'activities': activities,
'nextPageToken': null, 'nextPageToken': data['next_page_token'],
'hasMoreData': false, 'hasMoreData': data['next_page_token'] != null,
}; };
} catch (e) { } else if (data['status'] == 'ZERO_RESULTS') {
print('ActivityPlacesService: Erreur recherche catégorie paginée: $e'); return {
return { 'activities': <Activity>[],
'activities': <Activity>[], 'nextPageToken': null,
'nextPageToken': null, 'hasMoreData': false,
'hasMoreData': false, };
}; } else {
throw Exception('API Error: ${data['status']}');
}
} else {
throw Exception('Erreur HTTP ${response.statusCode}');
} }
} }
@@ -555,72 +590,136 @@ class ActivityPlacesService {
int pageSize, int pageSize,
String? nextPageToken, String? nextPageToken,
) async { ) async {
try { // Pour toutes les catégories, on utilise une recherche plus générale
// Pour toutes les catégories, on utilise une recherche plus générale String url =
String url = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json'
'https://maps.googleapis.com/maps/api/place/nearbysearch/json' '?location=$lat,$lng'
'?location=$lat,$lng' '&radius=$radius'
'&radius=$radius' '&type=tourist_attraction'
'&type=tourist_attraction' '&key=$_apiKey'
'&key=$_apiKey'; '&language=fr';
if (nextPageToken != null) { if (nextPageToken != null) {
url += '&pagetoken=$nextPageToken'; url += '&pagetoken=$nextPageToken';
}
final response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
final data = json.decode(response.body);
if (data['status'] == 'OK') {
final List<Activity> activities = [];
final results = data['results'] as List? ?? [];
// Limiter à pageSize résultats
final limitedResults = results.take(pageSize).toList();
for (final place in limitedResults) {
try {
// Déterminer la catégorie basée sur les types du lieu
final types = List<String>.from(place['types'] ?? []);
final category = _determineCategoryFromTypes(types);
final activity = await _convertPlaceToActivity(
place,
tripId,
category,
);
if (activity != null) {
activities.add(activity);
}
} catch (e) {
LoggerService.error(
'ActivityPlacesService: Erreur conversion place: $e',
);
}
}
return {
'activities': activities,
'nextPageToken': data['next_page_token'],
'hasMoreData': data['next_page_token'] != null,
};
} else if (data['status'] == 'ZERO_RESULTS') {
return {
'activities': <Activity>[],
'nextPageToken': null,
'hasMoreData': false,
};
} else {
throw Exception('API Error: ${data['status']}');
}
} else {
throw Exception('Erreur HTTP ${response.statusCode}');
}
}
/// Récupère des suggestions d'autocomplétion
Future<List<Map<String, String>>> fetchSuggestions({
required String query,
double? lat,
double? lng,
}) async {
if (query.isEmpty) return [];
try {
String url =
'https://maps.googleapis.com/maps/api/place/autocomplete/json'
'?input=${Uri.encodeComponent(query)}'
'&key=$_apiKey'
'&language=fr';
if (lat != null && lng != null) {
url += '&location=$lat,$lng&radius=50000'; // 50km bias
} }
final response = await http.get(Uri.parse(url)); final response = await http.get(Uri.parse(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 List<Activity> activities = []; return (data['predictions'] as List).map<Map<String, String>>((p) {
final results = data['results'] as List? ?? []; return {
'description': p['description'] as String,
// Limiter à pageSize résultats 'placeId': p['place_id'] as String,
final limitedResults = results.take(pageSize).toList(); };
}).toList();
for (final place in limitedResults) {
try {
// Déterminer la catégorie basée sur les types du lieu
final types = List<String>.from(place['types'] ?? []);
final category = _determineCategoryFromTypes(types);
final activity = await _convertPlaceToActivity(
place,
tripId,
category,
);
if (activity != null) {
activities.add(activity);
}
} catch (e) {
print('ActivityPlacesService: Erreur conversion place: $e');
}
}
return {
'activities': activities,
'nextPageToken': data['next_page_token'],
'hasMoreData': data['next_page_token'] != null,
};
} }
} }
return [];
return {
'activities': <Activity>[],
'nextPageToken': null,
'hasMoreData': false,
};
} catch (e) { } catch (e) {
print( LoggerService.error('ActivityPlacesService: Erreur autocomplete: $e');
'ActivityPlacesService: Erreur recherche toutes catégories paginée: $e', return [];
}
}
/// Récupère une activité via son Place ID
Future<Activity?> getActivityByPlaceId({
required String placeId,
required String tripId,
}) async {
try {
final details = await _getPlaceDetails(placeId);
if (details == null) return null;
// Créer une map simulant la structure "place" attendue par _convertPlaceToActivity
// Note: _getPlaceDetails retourne "result", qui est déjà ce qu'on veut,
// mais _convertPlaceToActivity attend le format "search result" qui a geometry au premier niveau.
// Heureusement _getPlaceDetails retourne une structure compatible pour geometry/photos etc.
// On doit s'assurer d'avoir les types pour déterminer la catégorie
final types = List<String>.from(details['types'] ?? []);
final category = _determineCategoryFromTypes(types);
return await _convertPlaceToActivity(
details, // details a la structure nécessaire (geometry, name, etc)
tripId,
category,
); );
return { } catch (e) {
'activities': <Activity>[], LoggerService.error('ActivityPlacesService: Erreur get details: $e');
'nextPageToken': null, return null;
'hasMoreData': false,
};
} }
} }
} }

View File

@@ -0,0 +1,54 @@
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:flutter/foundation.dart';
/// Service wrapper for Google Analytics
class AnalyticsService {
final FirebaseAnalytics _analytics = FirebaseAnalytics.instance;
FirebaseAnalyticsObserver getAnalyticsObserver() =>
FirebaseAnalyticsObserver(analytics: _analytics);
Future<void> logEvent({
required String name,
Map<String, Object>? parameters,
}) async {
try {
await _analytics.logEvent(name: name, parameters: parameters);
} catch (e) {
debugPrint('Error logging analytics event: $e');
}
}
Future<void> setUserProperty({
required String name,
required String? value,
}) async {
try {
await _analytics.setUserProperty(name: name, value: value);
} catch (e) {
debugPrint('Error setting user property: $e');
}
}
Future<void> setUserId(String? id) async {
try {
await _analytics.setUserId(id: id);
} catch (e) {
debugPrint('Error setting user ID: $e');
}
}
Future<void> logScreenView({
required String screenName,
String? screenClass,
}) async {
try {
await _analytics.logScreenView(
screenName: screenName,
screenClass: screenClass,
);
} catch (e) {
debugPrint('Error logging screen view: $e');
}
}
}

View File

@@ -83,20 +83,30 @@ class AuthService {
/// ///
/// [password] - The user's current password for re-authentication /// [password] - The user's current password for re-authentication
/// [email] - The user's email address for re-authentication /// [email] - The user's email address for re-authentication
Future<void> deleteAccount({ Future<void> deleteAccount() async {
required String password, try {
required String email, await currentUser!.delete();
}) async { await firebaseAuth.signOut();
// Re-authenticate the user for security } on FirebaseAuthException catch (e) {
AuthCredential credential = EmailAuthProvider.credential( if (e.code == 'requires-recent-login') {
email: email, _errorService.logError(
password: password, 'Delete account requires recent login',
); StackTrace.current,
await currentUser!.reauthenticateWithCredential(credential); );
rethrow;
// Delete the user account permanently }
await currentUser!.delete(); _errorService.logError(
await firebaseAuth.signOut(); 'Error deleting account: ${e.code} - ${e.message}',
StackTrace.current,
);
rethrow;
} catch (e) {
_errorService.logError(
'Unknown error deleting account: $e',
StackTrace.current,
);
rethrow;
}
} }
/// Resets the user's password after re-authentication. /// Resets the user's password after re-authentication.
@@ -161,18 +171,35 @@ class AuthService {
} }
} on GoogleSignInException catch (e) { } on GoogleSignInException catch (e) {
_errorService.logError('Google Sign-In error: $e', StackTrace.current); _errorService.logError('Google Sign-In error: $e', StackTrace.current);
_errorService.showError(
message: 'La connexion avec Google a échoué. Veuillez réessayer.',
);
rethrow; rethrow;
} on FirebaseAuthException catch (e) { } on FirebaseAuthException catch (e) {
_errorService.logError( _errorService.logError(
'Firebase error during Google Sign-In initialization: $e', 'Firebase error during Google Sign-In initialization: $e',
StackTrace.current, StackTrace.current,
); );
if (e.code == 'account-exists-with-different-credential') {
_errorService.showError(
message:
'Un compte existe déjà avec cette adresse email. Veuillez vous connecter avec la méthode utilisée précédemment.',
);
} else {
_errorService.showError(
message:
'Une erreur est survenue lors de la connexion avec Google. Veuillez réessayer plus tard.',
);
}
rethrow; rethrow;
} catch (e) { } catch (e) {
_errorService.logError( _errorService.logError(
'Unknown error during Google Sign-In initialization: $e', 'Unknown error during Google Sign-In initialization: $e',
StackTrace.current, StackTrace.current,
); );
_errorService.showError(
message: 'Une erreur inattendue est survenue. Veuillez réessayer.',
);
rethrow; rethrow;
} }
} }
@@ -198,20 +225,20 @@ class AuthService {
} }
// Request Apple ID credential with platform-specific configuration // Request Apple ID credential with platform-specific configuration
final AuthorizationCredentialAppleID credential = final AuthorizationCredentialAppleID
await SignInWithApple.getAppleIDCredential( credential = await SignInWithApple.getAppleIDCredential(
scopes: [ scopes: [
AppleIDAuthorizationScopes.email, AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName, AppleIDAuthorizationScopes.fullName,
], ],
// Configuration for Android/Web // Configuration for Android/Web
webAuthenticationOptions: WebAuthenticationOptions( webAuthenticationOptions: WebAuthenticationOptions(
clientId: 'be.devdayronvl.TravelMate', clientId: 'be.devdayronvl.TravelMate.service',
redirectUri: Uri.parse( redirectUri: Uri.parse(
'https://your-project-id.firebaseapp.com/__/auth/handler', 'https://us-central1-travelmate-a47f5.cloudfunctions.net/callbacks_signInWithApple',
), ),
), ),
); );
// Create OAuth credential for Firebase // Create OAuth credential for Firebase
final OAuthCredential oauthCredential = OAuthProvider("apple.com") final OAuthCredential oauthCredential = OAuthProvider("apple.com")
@@ -237,24 +264,49 @@ class AuthService {
return userCredential; return userCredential;
} on SignInWithAppleException catch (e) { } on SignInWithAppleException catch (e) {
_errorService.logError('Apple Sign-In error: $e', StackTrace.current); _errorService.logError('Apple Sign-In error: $e', StackTrace.current);
_errorService.showError(
message: 'La connexion avec Apple a échoué. Veuillez réessayer.',
);
throw FirebaseAuthException( throw FirebaseAuthException(
code: 'ERROR_APPLE_SIGNIN_FAILED', code: 'ERROR_APPLE_SIGNIN_FAILED',
message: 'Apple Sign-In failed: ${e.toString()}', message: 'Apple Sign-In failed',
); );
} on FirebaseAuthException catch (e) { } on FirebaseAuthException catch (e) {
_errorService.logError( _errorService.logError(
'Firebase error during Apple Sign-In: $e', 'Firebase error during Apple Sign-In: $e',
StackTrace.current, StackTrace.current,
); );
if (e.code == 'account-exists-with-different-credential') {
_errorService.showError(
message:
'Un compte existe déjà avec cette adresse email. Veuillez vous connecter avec la méthode utilisée précédemment.',
);
} else if (e.code == 'invalid-credential') {
_errorService.showError(
message: 'Les informations de connexion sont invalides.',
);
} else if (e.code == 'user-disabled') {
_errorService.showError(
message: 'Ce compte utilisateur a été désactivé.',
);
} else {
_errorService.showError(
message:
'Une erreur est survenue lors de la connexion avec Apple. Veuillez réessayer plus tard.',
);
}
rethrow; rethrow;
} catch (e) { } catch (e) {
_errorService.logError( _errorService.logError(
'Unknown error during Apple Sign-In: $e', 'Unknown error during Apple Sign-In: $e',
StackTrace.current, StackTrace.current,
); );
_errorService.showError(
message: 'Une erreur inattendue est survenue. Veuillez réessayer.',
);
throw FirebaseAuthException( throw FirebaseAuthException(
code: 'ERROR_APPLE_SIGNIN_UNKNOWN', code: 'ERROR_APPLE_SIGNIN_UNKNOWN',
message: 'Unknown error during Apple Sign-In: $e', message: 'Unknown error during Apple Sign-In',
); );
} }
} }

View File

@@ -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);
@@ -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,23 +225,36 @@ 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
@@ -240,7 +265,8 @@ class BalanceService {
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,7 +279,10 @@ 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);
@@ -283,7 +312,10 @@ class BalanceService {
// 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;

View File

@@ -1,5 +1,6 @@
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.
/// ///
@@ -97,13 +98,12 @@ class ErrorService {
/// [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.
@@ -111,7 +111,7 @@ class ErrorService {
/// [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.
@@ -119,6 +119,6 @@ class ErrorService {
/// [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);
} }
} }

View 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);
}
}

View File

@@ -0,0 +1,36 @@
import 'dart:async';
class MapLocationRequest {
final double latitude;
final double longitude;
final String? name;
final DateTime timestamp;
MapLocationRequest({
required this.latitude,
required this.longitude,
this.name,
}) : timestamp = DateTime.now();
}
class MapNavigationService {
final _requestController = StreamController<MapLocationRequest>.broadcast();
MapLocationRequest? _lastRequest;
Stream<MapLocationRequest> get requestStream => _requestController.stream;
MapLocationRequest? get lastRequest => _lastRequest;
void navigateToLocation(double lat, double lng, {String? name}) {
final request = MapLocationRequest(
latitude: lat,
longitude: lng,
name: name,
);
_lastRequest = request;
_requestController.add(request);
}
void dispose() {
_requestController.close();
}
}

View File

@@ -9,8 +9,8 @@ class MessageService {
MessageService({ MessageService({
required MessageRepository messageRepository, required MessageRepository messageRepository,
ErrorService? errorService, ErrorService? errorService,
}) : _messageRepository = messageRepository, }) : _messageRepository = messageRepository,
_errorService = errorService ?? ErrorService(); _errorService = errorService ?? ErrorService();
// Envoyer un message // Envoyer un message
Future<void> sendMessage({ Future<void> sendMessage({
@@ -30,12 +30,13 @@ class MessageService {
senderId: senderId, senderId: senderId,
senderName: senderName, senderName: senderName,
); );
} catch (e) { } catch (e, stackTrace) {
_errorService.logError( _errorService.logError(
'message_service.dart', 'message_service.dart',
'Erreur lors de l\'envoi du message: $e', 'Erreur lors de l\'envoi du message: $e',
stackTrace,
); );
rethrow; throw Exception('Impossible d\'envoyer le message');
} }
} }
@@ -43,12 +44,13 @@ class MessageService {
Stream<List<Message>> getMessagesStream(String groupId) { Stream<List<Message>> getMessagesStream(String groupId) {
try { try {
return _messageRepository.getMessagesStream(groupId); return _messageRepository.getMessagesStream(groupId);
} catch (e) { } catch (e, stackTrace) {
_errorService.logError( _errorService.logError(
'message_service.dart', 'message_service.dart',
'Erreur lors de la récupération des messages: $e', 'Erreur lors de la récupération des messages: $e',
stackTrace,
); );
rethrow; throw Exception('Impossible de récupérer les messages');
} }
} }
@@ -62,12 +64,13 @@ class MessageService {
groupId: groupId, groupId: groupId,
messageId: messageId, messageId: messageId,
); );
} catch (e) { } catch (e, stackTrace) {
_errorService.logError( _errorService.logError(
'message_service.dart', 'message_service.dart',
'Erreur lors de la suppression du message: $e', 'Erreur lors de la suppression du message: $e',
stackTrace,
); );
rethrow; throw Exception('Impossible de supprimer le message');
} }
} }
@@ -87,12 +90,13 @@ class MessageService {
messageId: messageId, messageId: messageId,
newText: newText.trim(), newText: newText.trim(),
); );
} catch (e) { } catch (e, stackTrace) {
_errorService.logError( _errorService.logError(
'message_service.dart', 'message_service.dart',
'Erreur lors de la modification du message: $e', 'Erreur lors de la modification du message: $e',
stackTrace,
); );
rethrow; throw Exception('Impossible de modifier le message');
} }
} }
@@ -110,12 +114,13 @@ class MessageService {
userId: userId, userId: userId,
reaction: reaction, reaction: reaction,
); );
} catch (e) { } catch (e, stackTrace) {
_errorService.logError( _errorService.logError(
'message_service.dart', 'message_service.dart',
'Erreur lors de l\'ajout de la réaction: $e', 'Erreur lors de l\'ajout de la réaction: $e',
stackTrace,
); );
rethrow; throw Exception('Impossible d\'ajouter la réaction');
} }
} }
@@ -131,12 +136,13 @@ class MessageService {
messageId: messageId, messageId: messageId,
userId: userId, userId: userId,
); );
} catch (e) { } catch (e, stackTrace) {
_errorService.logError( _errorService.logError(
'message_service.dart', 'message_service.dart',
'Erreur lors de la suppression de la réaction: $e', 'Erreur lors de la suppression de la réaction: $e',
stackTrace,
); );
rethrow; throw Exception('Impossible de supprimer la réaction');
} }
} }
} }

View File

@@ -0,0 +1,256 @@
import 'dart:convert';
import 'dart:io';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:travel_mate/services/logger_service.dart';
import 'package:flutter/material.dart';
import 'package:travel_mate/services/error_service.dart';
import 'package:travel_mate/repositories/group_repository.dart';
import 'package:travel_mate/repositories/account_repository.dart';
import 'package:travel_mate/components/group/chat_group_content.dart';
import 'package:travel_mate/components/account/group_expenses_page.dart';
@pragma('vm:entry-point')
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
LoggerService.info('Handling a background message: ${message.messageId}');
}
class NotificationService {
static final NotificationService _instance = NotificationService._internal();
factory NotificationService() => _instance;
NotificationService._internal();
late final FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance;
late final FlutterLocalNotificationsPlugin _localNotifications =
FlutterLocalNotificationsPlugin();
bool _isInitialized = false;
Future<void> initialize() async {
if (_isInitialized) return;
// Request permissions
await _requestPermissions();
// Initialize local notifications
const androidSettings = AndroidInitializationSettings(
'@mipmap/ic_launcher',
);
const iosSettings = DarwinInitializationSettings();
const initSettings = InitializationSettings(
android: androidSettings,
iOS: iosSettings,
);
await _localNotifications.initialize(
initSettings,
onDidReceiveNotificationResponse: (details) {
// Handle notification tap
LoggerService.info('Notification tapped: ${details.payload}');
if (details.payload != null) {
try {
final data = json.decode(details.payload!) as Map<String, dynamic>;
_handleNotificationTap(data);
} catch (e) {
LoggerService.error('Error parsing notification payload', error: e);
}
}
},
);
// Handle foreground messages
FirebaseMessaging.onMessage.listen(_handleForegroundMessage);
// Handle token refresh
FirebaseMessaging.instance.onTokenRefresh.listen(_onTokenRefresh);
// Setup interacted message (Deep Linking)
// We don't call this here anymore, it will be called from HomePage
// await setupInteractedMessage();
_isInitialized = true;
LoggerService.info('NotificationService initialized');
// Print current token for debugging
final token = await getFCMToken();
LoggerService.info('Current FCM Token: $token');
}
/// Sets up the background message listener.
/// Should be called when the app is ready to handle navigation.
void startListening() {
// Handle any interaction when the app is in the background via a
// Stream listener
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
_handleNotificationTap(message.data);
});
}
/// Checks for an initial message (app opened from terminated state)
/// and handles it if present.
Future<void> handleInitialMessage() async {
// Get any messages which caused the application to open from
// a terminated state.
RemoteMessage? initialMessage = await _firebaseMessaging
.getInitialMessage();
if (initialMessage != null) {
LoggerService.info('Found initial message: ${initialMessage.data}');
_handleNotificationTap(initialMessage.data);
}
}
Future<void> _handleNotificationTap(Map<String, dynamic> data) async {
LoggerService.info('Handling notification tap with data: $data');
// DEBUG: Show snackbar to verify payload
// ErrorService().showSnackbar(message: 'Debug: Payload $data', isError: false);
final type = data['type'];
try {
if (type == 'message') {
final groupId = data['groupId'];
if (groupId != null) {
final groupRepository = GroupRepository();
final group = await groupRepository.getGroupById(groupId);
if (group != null) {
ErrorService.navigatorKey.currentState?.push(
MaterialPageRoute(
builder: (context) => ChatGroupContent(group: group),
),
);
} else {
LoggerService.error('Group not found: $groupId');
// ErrorService().showError(message: 'Groupe introuvable: $groupId');
}
} else {
LoggerService.error('Missing groupId in payload');
// ErrorService().showError(message: 'Payload invalide: groupId manquant');
}
} else if (type == 'expense') {
final tripId = data['tripId'];
if (tripId != null) {
final accountRepository = AccountRepository();
final groupRepository = GroupRepository();
final account = await accountRepository.getAccountByTripId(tripId);
final group = await groupRepository.getGroupByTripId(tripId);
if (account != null && group != null) {
ErrorService.navigatorKey.currentState?.push(
MaterialPageRoute(
builder: (context) =>
GroupExpensesPage(account: account, group: group),
),
);
} else {
LoggerService.error('Account or Group not found for trip: $tripId');
// ErrorService().showError(message: 'Compte ou Groupe introuvable');
}
}
} else {
LoggerService.info('Unknown notification type: $type');
}
} catch (e) {
LoggerService.error('Error handling notification tap: $e');
ErrorService().showError(message: 'Erreur navigation: $e');
}
}
Future<void> _onTokenRefresh(String newToken) async {
LoggerService.info('FCM Token refreshed: $newToken');
// We need the user ID to save the token.
// Since this service is a singleton, we might not have direct access to the user ID here
// without injecting the repository or bloc.
// For now, we rely on the AuthBloc to update the token on login/start.
// Ideally, we should save it here if we have the user ID.
}
Future<void> _requestPermissions() async {
NotificationSettings settings = await _firebaseMessaging.requestPermission(
alert: true,
badge: true,
sound: true,
);
LoggerService.info(
'User granted permission: ${settings.authorizationStatus}',
);
}
Future<String?> getFCMToken() async {
try {
if (Platform.isIOS) {
String? apnsToken = await _firebaseMessaging.getAPNSToken();
int retries = 0;
while (apnsToken == null && retries < 10) {
LoggerService.info(
'Waiting for APNS token... (Attempt ${retries + 1}/10)',
);
await Future.delayed(const Duration(seconds: 2));
apnsToken = await _firebaseMessaging.getAPNSToken();
retries++;
}
if (apnsToken == null) {
LoggerService.error('APNS token not available after retries');
return null;
}
}
final token = await _firebaseMessaging.getToken();
LoggerService.info('NotificationService - FCM Token: $token');
return token;
} catch (e) {
LoggerService.error('Error getting FCM token: $e');
return null;
}
}
Future<void> saveTokenToFirestore(String userId) async {
try {
final token = await getFCMToken();
if (token != null) {
await FirebaseFirestore.instance.collection('users').doc(userId).set({
'fcmToken': token,
}, SetOptions(merge: true));
LoggerService.info('FCM Token saved to Firestore for user: $userId');
}
} catch (e) {
LoggerService.error('Error saving FCM token to Firestore: $e');
}
}
Future<void> _handleForegroundMessage(RemoteMessage message) async {
LoggerService.info('Got a message whilst in the foreground!');
LoggerService.info('Message data: ${message.data}');
if (message.notification != null) {
LoggerService.info(
'Message also contained a notification: ${message.notification}',
);
// Show local notification
const androidDetails = AndroidNotificationDetails(
'high_importance_channel',
'High Importance Notifications',
importance: Importance.max,
priority: Priority.high,
);
const iosDetails = DarwinNotificationDetails();
const details = NotificationDetails(
android: androidDetails,
iOS: iosDetails,
);
await _localNotifications.show(
message.hashCode,
message.notification?.title,
message.notification?.body,
details,
);
}
}
}

Some files were not shown because too many files have changed in this diff Show More