Compare commits
10 Commits
68f546d0e8
...
9b11836409
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b11836409 | ||
|
|
9f2bfcaa55 | ||
|
|
e174c1274d | ||
|
|
cf4c6447dd | ||
|
|
a74d76b485 | ||
|
|
fd19b88eef | ||
|
|
f3ae91ccf9 | ||
|
|
6757cb013a | ||
|
|
1e70b9e09f | ||
|
|
b4bcc8f498 |
5
.firebaserc
Normal file
5
.firebaserc
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"projects": {
|
||||||
|
"default": "travelmate-a47f5"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ android {
|
|||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
isCoreLibraryDesugaringEnabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
@@ -59,6 +60,10 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4")
|
||||||
|
}
|
||||||
|
|
||||||
flutter {
|
flutter {
|
||||||
source = "../.."
|
source = "../.."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
<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"
|
||||||
@@ -40,6 +41,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
|
||||||
@@ -48,6 +63,9 @@
|
|||||||
<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="AIzaSyCAtz1_d5K0ANwxAA_T84iq7Ac_gsUs_oM"/>
|
||||||
|
<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 +77,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>
|
||||||
|
|||||||
@@ -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
2
functions/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
node_modules/
|
||||||
|
*.local
|
||||||
@@ -1,11 +1,84 @@
|
|||||||
const functions = require("firebase-functions");
|
const functions = require("firebase-functions/v1");
|
||||||
const admin = require("firebase-admin");
|
const admin = require("firebase-admin");
|
||||||
|
|
||||||
admin.initializeApp();
|
admin.initializeApp();
|
||||||
|
|
||||||
// Helper function to send notifications
|
// Helper function to send notifications to a list of users
|
||||||
async function sendNotificationToTripParticipants(tripId, title, body, excludeUserId) {
|
async function sendNotificationToUsers(userIds, title, body, excludeUserId, data = {}) {
|
||||||
|
console.log(`Starting sendNotificationToUsers. Total users: ${userIds.length}, Exclude: ${excludeUserId}`);
|
||||||
try {
|
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();
|
const tripDoc = await admin.firestore().collection("trips").doc(tripId).get();
|
||||||
if (!tripDoc.exists) {
|
if (!tripDoc.exists) {
|
||||||
console.log(`Trip ${tripId} not found`);
|
console.log(`Trip ${tripId} not found`);
|
||||||
@@ -14,54 +87,13 @@ async function sendNotificationToTripParticipants(tripId, title, body, excludeUs
|
|||||||
|
|
||||||
const trip = tripDoc.data();
|
const trip = tripDoc.data();
|
||||||
const participants = trip.participants || [];
|
const participants = trip.participants || [];
|
||||||
// Add creator if not in participants list (though usually they are)
|
|
||||||
if (trip.createdBy && !participants.includes(trip.createdBy)) {
|
if (trip.createdBy && !participants.includes(trip.createdBy)) {
|
||||||
participants.push(trip.createdBy);
|
participants.push(trip.createdBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
const tokens = [];
|
console.log(`Found trip participants: ${JSON.stringify(participants)}`);
|
||||||
|
|
||||||
for (const userId of participants) {
|
// Fetch creator name
|
||||||
if (userId === excludeUserId) continue;
|
|
||||||
|
|
||||||
const userDoc = await admin.firestore().collection("users").doc(userId).get();
|
|
||||||
if (userDoc.exists) {
|
|
||||||
const userData = userDoc.data();
|
|
||||||
if (userData.fcmToken) {
|
|
||||||
tokens.push(userData.fcmToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tokens.length > 0) {
|
|
||||||
const message = {
|
|
||||||
notification: {
|
|
||||||
title: title,
|
|
||||||
body: body,
|
|
||||||
},
|
|
||||||
tokens: tokens,
|
|
||||||
data: {
|
|
||||||
tripId: tripId,
|
|
||||||
click_action: "FLUTTER_NOTIFICATION_CLICK",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await admin.messaging().sendMulticast(message);
|
|
||||||
console.log(`${response.successCount} messages were sent successfully`);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error sending notification:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.onActivityCreated = functions.firestore
|
|
||||||
.document("trips/{tripId}/activities/{activityId}")
|
|
||||||
.onCreate(async (snapshot, context) => {
|
|
||||||
const activity = snapshot.data();
|
|
||||||
const tripId = context.params.tripId;
|
|
||||||
const createdBy = activity.createdBy || "Unknown"; // Assuming createdBy field exists
|
|
||||||
|
|
||||||
// Fetch creator name if possible, otherwise use generic message
|
|
||||||
let creatorName = "Quelqu'un";
|
let creatorName = "Quelqu'un";
|
||||||
if (createdBy !== "Unknown") {
|
if (createdBy !== "Unknown") {
|
||||||
const userDoc = await admin.firestore().collection("users").doc(createdBy).get();
|
const userDoc = await admin.firestore().collection("users").doc(createdBy).get();
|
||||||
@@ -70,56 +102,95 @@ exports.onActivityCreated = functions.firestore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await sendNotificationToTripParticipants(
|
await sendNotificationToUsers(
|
||||||
tripId,
|
participants,
|
||||||
"Nouvelle activité !",
|
"Nouvelle activité !",
|
||||||
`${creatorName} a ajouté une nouvelle activité : ${activity.title}`,
|
`${creatorName} a ajouté une nouvelle activité : ${activity.name || activity.title}`,
|
||||||
createdBy
|
createdBy,
|
||||||
|
{ tripId: tripId }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
exports.onMessageCreated = functions.firestore
|
exports.onMessageCreated = functions.firestore
|
||||||
.document("trips/{tripId}/messages/{messageId}")
|
.document("groups/{groupId}/messages/{messageId}")
|
||||||
.onCreate(async (snapshot, context) => {
|
.onCreate(async (snapshot, context) => {
|
||||||
|
console.log(`onMessageCreated triggered for ${context.params.messageId} in group ${context.params.groupId}`);
|
||||||
const message = snapshot.data();
|
const message = snapshot.data();
|
||||||
const tripId = context.params.tripId;
|
const groupId = context.params.groupId;
|
||||||
const senderId = message.senderId;
|
const senderId = message.senderId;
|
||||||
|
|
||||||
let senderName = "Quelqu'un";
|
// Fetch group to get members
|
||||||
if (senderId) {
|
const groupDoc = await admin.firestore().collection("groups").doc(groupId).get();
|
||||||
const userDoc = await admin.firestore().collection("users").doc(senderId).get();
|
if (!groupDoc.exists) {
|
||||||
if (userDoc.exists) {
|
console.log(`Group ${groupId} not found`);
|
||||||
senderName = userDoc.data().prenom || "Quelqu'un";
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await sendNotificationToTripParticipants(
|
const group = groupDoc.data();
|
||||||
tripId,
|
const memberIds = group.memberIds || [];
|
||||||
|
console.log(`Found group members: ${JSON.stringify(memberIds)}`);
|
||||||
|
|
||||||
|
let senderName = message.senderName || "Quelqu'un";
|
||||||
|
|
||||||
|
await sendNotificationToUsers(
|
||||||
|
memberIds,
|
||||||
"Nouveau message",
|
"Nouveau message",
|
||||||
`${senderName} : ${message.content}`,
|
`${senderName} : ${message.text}`,
|
||||||
senderId
|
senderId,
|
||||||
|
{ groupId: groupId }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
exports.onExpenseCreated = functions.firestore
|
exports.onExpenseCreated = functions.firestore
|
||||||
.document("trips/{tripId}/expenses/{expenseId}")
|
.document("expenses/{expenseId}")
|
||||||
.onCreate(async (snapshot, context) => {
|
.onCreate(async (snapshot, context) => {
|
||||||
|
console.log(`onExpenseCreated triggered for ${context.params.expenseId}`);
|
||||||
const expense = snapshot.data();
|
const expense = snapshot.data();
|
||||||
const tripId = context.params.tripId;
|
const groupId = expense.groupId;
|
||||||
const paidBy = expense.paidBy;
|
const paidBy = expense.paidById || expense.paidBy;
|
||||||
|
|
||||||
let payerName = "Quelqu'un";
|
if (!groupId) {
|
||||||
if (paidBy) {
|
console.log("No groupId found in expense");
|
||||||
const userDoc = await admin.firestore().collection("users").doc(paidBy).get();
|
return;
|
||||||
if (userDoc.exists) {
|
|
||||||
payerName = userDoc.data().prenom || "Quelqu'un";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await sendNotificationToTripParticipants(
|
// Fetch group to get members
|
||||||
tripId,
|
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",
|
"Nouvelle dépense",
|
||||||
`${payerName} a ajouté une dépense : ${expense.amount} ${expense.currency || '€'}`,
|
`${payerName} a ajouté une dépense : ${expense.amount} ${expense.currency || '€'}`,
|
||||||
paidBy
|
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);
|
||||||
|
});
|
||||||
|
|||||||
11099
functions/package-lock.json
generated
11099
functions/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,25 +1,23 @@
|
|||||||
{
|
{
|
||||||
"name": "functions",
|
"name": "functions",
|
||||||
"description": "Cloud Functions for Travel Mate",
|
"description": "Cloud Functions for Firebase",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint .",
|
"serve": "firebase emulators:start --only functions",
|
||||||
"serve": "firebase emulators:start --only functions",
|
"shell": "firebase functions:shell",
|
||||||
"shell": "firebase functions:shell",
|
"start": "npm run shell",
|
||||||
"start": "npm run shell",
|
"deploy": "firebase deploy --only functions",
|
||||||
"deploy": "firebase deploy --only functions",
|
"logs": "firebase functions:log"
|
||||||
"logs": "firebase functions:log"
|
},
|
||||||
},
|
"engines": {
|
||||||
"engines": {
|
"node": "20"
|
||||||
"node": "18"
|
},
|
||||||
},
|
"main": "index.js",
|
||||||
"main": "index.js",
|
"dependencies": {
|
||||||
"dependencies": {
|
"firebase-admin": "^13.6.0",
|
||||||
"firebase-admin": "^11.8.0",
|
"firebase-functions": "^7.0.0"
|
||||||
"firebase-functions": "^4.3.1"
|
},
|
||||||
},
|
"devDependencies": {
|
||||||
"devDependencies": {
|
"firebase-functions-test": "^3.4.1"
|
||||||
"eslint": "^8.15.0",
|
},
|
||||||
"eslint-config-google": "^0.14.0"
|
"private": true
|
||||||
},
|
|
||||||
"private": true
|
|
||||||
}
|
}
|
||||||
@@ -1216,6 +1216,9 @@ PODS:
|
|||||||
- Firebase/Firestore (12.4.0):
|
- Firebase/Firestore (12.4.0):
|
||||||
- Firebase/CoreOnly
|
- Firebase/CoreOnly
|
||||||
- FirebaseFirestore (~> 12.4.0)
|
- FirebaseFirestore (~> 12.4.0)
|
||||||
|
- Firebase/Messaging (12.4.0):
|
||||||
|
- Firebase/CoreOnly
|
||||||
|
- FirebaseMessaging (~> 12.4.0)
|
||||||
- Firebase/Storage (12.4.0):
|
- Firebase/Storage (12.4.0):
|
||||||
- Firebase/CoreOnly
|
- Firebase/CoreOnly
|
||||||
- FirebaseStorage (~> 12.4.0)
|
- FirebaseStorage (~> 12.4.0)
|
||||||
@@ -1223,9 +1226,13 @@ PODS:
|
|||||||
- Firebase/Auth (= 12.4.0)
|
- Firebase/Auth (= 12.4.0)
|
||||||
- firebase_core
|
- firebase_core
|
||||||
- Flutter
|
- Flutter
|
||||||
- firebase_core (4.2.0):
|
- firebase_core (4.2.1):
|
||||||
- Firebase/CoreOnly (= 12.4.0)
|
- Firebase/CoreOnly (= 12.4.0)
|
||||||
- Flutter
|
- Flutter
|
||||||
|
- firebase_messaging (16.0.4):
|
||||||
|
- Firebase/Messaging (= 12.4.0)
|
||||||
|
- firebase_core
|
||||||
|
- Flutter
|
||||||
- firebase_storage (13.0.3):
|
- firebase_storage (13.0.3):
|
||||||
- Firebase/Storage (= 12.4.0)
|
- Firebase/Storage (= 12.4.0)
|
||||||
- firebase_core
|
- firebase_core
|
||||||
@@ -1269,6 +1276,20 @@ PODS:
|
|||||||
- 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)
|
||||||
|
- FirebaseInstallations (12.4.0):
|
||||||
|
- FirebaseCore (~> 12.4.0)
|
||||||
|
- GoogleUtilities/Environment (~> 8.1)
|
||||||
|
- GoogleUtilities/UserDefaults (~> 8.1)
|
||||||
|
- PromisesObjC (~> 2.4)
|
||||||
|
- FirebaseMessaging (12.4.0):
|
||||||
|
- FirebaseCore (~> 12.4.0)
|
||||||
|
- FirebaseInstallations (~> 12.4.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.4.0)
|
- FirebaseSharedSwift (12.4.0)
|
||||||
- FirebaseStorage (12.4.0):
|
- FirebaseStorage (12.4.0):
|
||||||
- FirebaseAppCheckInterop (~> 12.4.0)
|
- FirebaseAppCheckInterop (~> 12.4.0)
|
||||||
@@ -1278,6 +1299,8 @@ PODS:
|
|||||||
- 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,6 +1315,9 @@ PODS:
|
|||||||
- FlutterMacOS
|
- FlutterMacOS
|
||||||
- GoogleSignIn (~> 9.0)
|
- GoogleSignIn (~> 9.0)
|
||||||
- GTMSessionFetcher (>= 3.4.0)
|
- GTMSessionFetcher (>= 3.4.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)
|
||||||
@@ -1456,8 +1482,10 @@ DEPENDENCIES:
|
|||||||
- cloud_firestore (from `.symlinks/plugins/cloud_firestore/ios`)
|
- cloud_firestore (from `.symlinks/plugins/cloud_firestore/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`)
|
||||||
@@ -1485,9 +1513,12 @@ SPEC REPOS:
|
|||||||
- FirebaseCoreInternal
|
- FirebaseCoreInternal
|
||||||
- FirebaseFirestore
|
- FirebaseFirestore
|
||||||
- FirebaseFirestoreInternal
|
- FirebaseFirestoreInternal
|
||||||
|
- FirebaseInstallations
|
||||||
|
- FirebaseMessaging
|
||||||
- FirebaseSharedSwift
|
- FirebaseSharedSwift
|
||||||
- FirebaseStorage
|
- FirebaseStorage
|
||||||
- Google-Maps-iOS-Utils
|
- Google-Maps-iOS-Utils
|
||||||
|
- GoogleDataTransport
|
||||||
- GoogleMaps
|
- GoogleMaps
|
||||||
- GoogleSignIn
|
- GoogleSignIn
|
||||||
- GoogleUtilities
|
- GoogleUtilities
|
||||||
@@ -1507,10 +1538,14 @@ EXTERNAL SOURCES:
|
|||||||
: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:
|
||||||
@@ -1542,7 +1577,8 @@ SPEC CHECKSUMS:
|
|||||||
cloud_firestore: 79014bb3b303d451717ed5fe69fded8a2b2e8dc2
|
cloud_firestore: 79014bb3b303d451717ed5fe69fded8a2b2e8dc2
|
||||||
Firebase: f07b15ae5a6ec0f93713e30b923d9970d144af3e
|
Firebase: f07b15ae5a6ec0f93713e30b923d9970d144af3e
|
||||||
firebase_auth: c2b8be95d602d4e8a9148fae72333ef78e69cc20
|
firebase_auth: c2b8be95d602d4e8a9148fae72333ef78e69cc20
|
||||||
firebase_core: 744984dbbed8b3036abf34f0b98d80f130a7e464
|
firebase_core: f1aafb21c14f497e5498f7ffc4dc63cbb52b2594
|
||||||
|
firebase_messaging: c17a29984eafce4b2997fe078bb0a9e0b06f5dde
|
||||||
firebase_storage: 0ba617a05b24aec050395e4d5d3773c0d7518a15
|
firebase_storage: 0ba617a05b24aec050395e4d5d3773c0d7518a15
|
||||||
FirebaseAppCheckInterop: f734c802f21fe1da0837708f0f9a27218c8a4ed0
|
FirebaseAppCheckInterop: f734c802f21fe1da0837708f0f9a27218c8a4ed0
|
||||||
FirebaseAuth: 4a2aed737c84114a9d9b33d11ae1b147d6b94889
|
FirebaseAuth: 4a2aed737c84114a9d9b33d11ae1b147d6b94889
|
||||||
@@ -1552,13 +1588,17 @@ SPEC CHECKSUMS:
|
|||||||
FirebaseCoreInternal: d7f5a043c2cd01a08103ab586587c1468047bca6
|
FirebaseCoreInternal: d7f5a043c2cd01a08103ab586587c1468047bca6
|
||||||
FirebaseFirestore: 2a6183381cf7679b1bb000eb76a8e3178e25dee2
|
FirebaseFirestore: 2a6183381cf7679b1bb000eb76a8e3178e25dee2
|
||||||
FirebaseFirestoreInternal: 6577a27cd5dc3722b900042527f86d4ea1626134
|
FirebaseFirestoreInternal: 6577a27cd5dc3722b900042527f86d4ea1626134
|
||||||
|
FirebaseInstallations: ae9f4902cb5bf1d0c5eaa31ec1f4e5495a0714e2
|
||||||
|
FirebaseMessaging: d33971b7bb252745ea6cd31ab190d1a1df4b8ed5
|
||||||
FirebaseSharedSwift: 93426a1de92f19e1199fac5295a4f8df16458daa
|
FirebaseSharedSwift: 93426a1de92f19e1199fac5295a4f8df16458daa
|
||||||
FirebaseStorage: 20d6b56fb8a40ebaa03d6a2889fe33dac64adb73
|
FirebaseStorage: 20d6b56fb8a40ebaa03d6a2889fe33dac64adb73
|
||||||
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
|
||||||
|
GoogleDataTransport: aae35b7ea0c09004c3797d53c8c41f66f219d6a7
|
||||||
GoogleMaps: 0608099d4870cac8754bdba9b6953db543432438
|
GoogleMaps: 0608099d4870cac8754bdba9b6953db543432438
|
||||||
GoogleSignIn: c7f09cfbc85a1abf69187be091997c317cc33b77
|
GoogleSignIn: c7f09cfbc85a1abf69187be091997c317cc33b77
|
||||||
GoogleUtilities: 00c88b9a86066ef77f0da2fab05f65d7768ed8e1
|
GoogleUtilities: 00c88b9a86066ef77f0da2fab05f65d7768ed8e1
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -62,17 +75,12 @@
|
|||||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleURLTypes</key>
|
|
||||||
<array>
|
<key>LSApplicationQueriesSchemes</key>
|
||||||
<dict>
|
<array>
|
||||||
<key>CFBundleURLName</key>
|
<string>comgooglemaps</string>
|
||||||
<string>Apple Sign-In</string>
|
<string>waze</string>
|
||||||
<key>CFBundleURLSchemes</key>
|
</array>
|
||||||
<array>
|
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
||||||
</array>
|
|
||||||
</dict>
|
|
||||||
</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>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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';
|
||||||
@@ -51,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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,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,
|
||||||
@@ -106,8 +117,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 with members: $e',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
|
emit(const AccountError('Impossible de créer le compte'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,8 +135,12 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
|||||||
await _repository.addMemberToAccount(event.accountId, event.member);
|
await _repository.addMemberToAccount(event.accountId, event.member);
|
||||||
emit(AccountOperationSuccess('Membre ajouté avec succès'));
|
emit(AccountOperationSuccess('Membre ajouté avec succès'));
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
_errorService.logError(e.toString(), stackTrace);
|
_errorService.logError(
|
||||||
emit(AccountError('Erreur lors de l\'ajout du membre: ${e.toString()}'));
|
'AccountBloc',
|
||||||
|
'Error adding member: $e',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
|
emit(const AccountError('Impossible d\'ajouter le membre'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,11 +150,18 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
|||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
emit(AccountLoading());
|
emit(AccountLoading());
|
||||||
await _repository.removeMemberFromAccount(event.accountId, event.memberId);
|
await _repository.removeMemberFromAccount(
|
||||||
|
event.accountId,
|
||||||
|
event.memberId,
|
||||||
|
);
|
||||||
emit(AccountOperationSuccess('Membre supprimé avec succès'));
|
emit(AccountOperationSuccess('Membre supprimé avec succès'));
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
_errorService.logError(e.toString(), stackTrace);
|
_errorService.logError(
|
||||||
emit(AccountError('Erreur lors de la suppression du membre: ${e.toString()}'));
|
'AccountBloc',
|
||||||
|
'Error removing member: $e',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
|
emit(const AccountError('Impossible de supprimer le membre'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,10 +56,11 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
emit(
|
emit(
|
||||||
ActivityLoaded(activities: activities, filteredActivities: activities),
|
ActivityLoaded(activities: activities, filteredActivities: activities),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
_errorService.logError(
|
_errorService.logError(
|
||||||
'activity_bloc',
|
'activity_bloc',
|
||||||
'Erreur chargement activités: $e',
|
'Erreur chargement activités: $e',
|
||||||
|
stackTrace,
|
||||||
);
|
);
|
||||||
emit(const ActivityError('Impossible de charger les activités'));
|
emit(const ActivityError('Impossible de charger les activités'));
|
||||||
}
|
}
|
||||||
@@ -83,10 +84,11 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
emit(
|
emit(
|
||||||
ActivityLoaded(activities: activities, filteredActivities: activities),
|
ActivityLoaded(activities: activities, filteredActivities: activities),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
_errorService.logError(
|
_errorService.logError(
|
||||||
'activity_bloc',
|
'activity_bloc',
|
||||||
'Erreur chargement activités: $e',
|
'Erreur chargement activités: $e',
|
||||||
|
stackTrace,
|
||||||
);
|
);
|
||||||
emit(const ActivityError('Impossible de charger les activités'));
|
emit(const ActivityError('Impossible de charger les activités'));
|
||||||
}
|
}
|
||||||
@@ -112,8 +114,12 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
// Recharger les activités pour mettre à jour l'UI
|
// Recharger les activités pour mettre à jour l'UI
|
||||||
add(LoadActivities(event.tripId));
|
add(LoadActivities(event.tripId));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
_errorService.logError('activity_bloc', 'Erreur mise à jour date: $e');
|
_errorService.logError(
|
||||||
|
'activity_bloc',
|
||||||
|
'Erreur mise à jour date: $e',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
emit(const ActivityError('Impossible de mettre à jour la date'));
|
emit(const ActivityError('Impossible de mettre à jour la date'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,8 +168,12 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
isLoading: false,
|
isLoading: false,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
_errorService.logError('activity_bloc', 'Erreur recherche activités: $e');
|
_errorService.logError(
|
||||||
|
'activity_bloc',
|
||||||
|
'Erreur recherche activités: $e',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
emit(const ActivityError('Impossible de rechercher les activités'));
|
emit(const ActivityError('Impossible de rechercher les activités'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,10 +221,11 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
isLoading: false,
|
isLoading: false,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
_errorService.logError(
|
_errorService.logError(
|
||||||
'activity_bloc',
|
'activity_bloc',
|
||||||
'Erreur recherche activités avec coordonnées: $e',
|
'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'));
|
||||||
}
|
}
|
||||||
@@ -240,8 +251,12 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
emit(
|
emit(
|
||||||
ActivitySearchResults(searchResults: searchResults, query: event.query),
|
ActivitySearchResults(searchResults: searchResults, query: event.query),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
_errorService.logError('activity_bloc', 'Erreur recherche textuelle: $e');
|
_errorService.logError(
|
||||||
|
'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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,8 +307,12 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
} 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é'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -350,8 +369,12 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
} 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é'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -418,8 +441,12 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
} 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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -479,8 +506,8 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
} 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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -511,8 +538,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é'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -593,8 +624,12 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
} 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é'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -614,8 +649,8 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
vote: 1,
|
vote: 1,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
_errorService.logError('activity_bloc', 'Erreur favori: $e');
|
_errorService.logError('activity_bloc', 'Erreur favori: $e', stackTrace);
|
||||||
emit(const ActivityError('Impossible de modifier les favoris'));
|
emit(const ActivityError('Impossible de modifier les favoris'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ 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';
|
||||||
|
|
||||||
/// 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> {
|
||||||
@@ -69,6 +70,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
|
// Save FCM Token on auto-login
|
||||||
|
await NotificationService().saveTokenToFirestore(user.id!);
|
||||||
emit(AuthAuthenticated(user: user));
|
emit(AuthAuthenticated(user: user));
|
||||||
} else {
|
} else {
|
||||||
emit(AuthUnauthenticated());
|
emit(AuthUnauthenticated());
|
||||||
@@ -77,7 +80,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 +101,14 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
|
// Save FCM Token
|
||||||
|
await NotificationService().saveTokenToFirestore(user.id!);
|
||||||
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 +132,14 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
|
// Save FCM Token
|
||||||
|
await NotificationService().saveTokenToFirestore(user.id!);
|
||||||
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 +157,8 @@ 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!);
|
||||||
emit(AuthAuthenticated(user: user));
|
emit(AuthAuthenticated(user: user));
|
||||||
} else {
|
} else {
|
||||||
emit(
|
emit(
|
||||||
@@ -160,7 +169,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(AuthError(message: e.toString()));
|
emit(AuthError(message: e.toString().replaceAll('Exception: ', '')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +192,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
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: ', '')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +215,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
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 +233,8 @@ 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!);
|
||||||
emit(AuthAuthenticated(user: user));
|
emit(AuthAuthenticated(user: user));
|
||||||
} else {
|
} else {
|
||||||
emit(
|
emit(
|
||||||
@@ -234,7 +245,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(AuthError(message: e.toString()));
|
emit(AuthError(message: e.toString().replaceAll('Exception: ', '')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +272,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: ', '')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,9 +105,13 @@ class BalanceBloc extends Bloc<BalanceEvent, BalanceState> {
|
|||||||
emit(
|
emit(
|
||||||
GroupBalancesLoaded(balances: userBalances, settlements: settlements),
|
GroupBalancesLoaded(balances: userBalances, settlements: settlements),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
_errorService.logError('BalanceBloc', 'Error loading balance: $e');
|
_errorService.logError(
|
||||||
emit(BalanceError(e.toString()));
|
'BalanceBloc',
|
||||||
|
'Error loading balance: $e',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
|
emit(const BalanceError('Impossible de charger la balance'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,9 +147,13 @@ class BalanceBloc extends Bloc<BalanceEvent, BalanceState> {
|
|||||||
emit(
|
emit(
|
||||||
GroupBalancesLoaded(balances: userBalances, settlements: settlements),
|
GroupBalancesLoaded(balances: userBalances, settlements: settlements),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
_errorService.logError('BalanceBloc', 'Error refreshing balance: $e');
|
_errorService.logError(
|
||||||
emit(BalanceError(e.toString()));
|
'BalanceBloc',
|
||||||
|
'Error refreshing balance: $e',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
|
emit(const BalanceError('Impossible de rafraîchir la balance'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,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é'),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
);
|
);
|
||||||
} 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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ class ExpenseBloc extends Bloc<ExpenseEvent, ExpenseState> {
|
|||||||
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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,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é'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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];
|
||||||
|
|||||||
@@ -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,21 @@ 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,
|
||||||
|
);
|
||||||
|
emit(const TripError('Impossible de charger les voyages'));
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles [_TripsUpdated] events.
|
/// Handles [_TripsUpdated] events.
|
||||||
@@ -106,10 +116,7 @@ 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,
|
|
||||||
Emitter<TripState> emit,
|
|
||||||
) {
|
|
||||||
emit(TripLoaded(event.trips));
|
emit(TripLoaded(event.trips));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,9 +144,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 +170,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 +198,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 +213,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());
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
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/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 +19,8 @@ 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 _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 +50,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 +68,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 +82,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 +129,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 +164,13 @@ class UserBloc extends Bloc<event.UserEvent, state.UserState> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
emit(state.UserLoaded(updatedUser));
|
emit(state.UserLoaded(updatedUser));
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
emit(state.UserError('Error updating user: $e'));
|
_errorService.logError(
|
||||||
|
'UserBloc',
|
||||||
|
'Error updating user: $e',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
|
emit(state.UserError('Impossible de mettre à jour l\'utilisateur'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,9 @@
|
|||||||
/// 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';
|
||||||
@@ -70,10 +72,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: () {},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,30 +93,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,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,9 +126,12 @@ class _AccountContentState extends State<AccountContent> {
|
|||||||
listener: (context, accountState) {
|
listener: (context, accountState) {
|
||||||
if (accountState is AccountError) {
|
if (accountState is AccountError) {
|
||||||
ErrorContent(
|
ErrorContent(
|
||||||
message: 'Erreur de chargement des comptes : ${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),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -156,10 +146,7 @@ class _AccountContentState extends State<AccountContent> {
|
|||||||
loadingWidget: const Scaffold(
|
loadingWidget: const Scaffold(
|
||||||
body: Center(child: CircularProgressIndicator()),
|
body: Center(child: CircularProgressIndicator()),
|
||||||
),
|
),
|
||||||
errorWidget: ErrorContent(
|
errorWidget: ErrorContent(message: 'User error', onRetry: () {}),
|
||||||
message: 'User error',
|
|
||||||
onRetry: () {},
|
|
||||||
),
|
|
||||||
noUserWidget: const Scaffold(
|
noUserWidget: const Scaffold(
|
||||||
body: Center(child: Text('Utilisateur non connecté')),
|
body: Center(child: Text('Utilisateur non connecté')),
|
||||||
),
|
),
|
||||||
@@ -241,7 +228,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',
|
||||||
@@ -280,14 +271,14 @@ class _AccountContentState extends State<AccountContent> {
|
|||||||
child: ListView(
|
child: ListView(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
children: [
|
children: [
|
||||||
...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),
|
||||||
);
|
);
|
||||||
})
|
}),
|
||||||
],
|
],
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,9 +300,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)
|
||||||
@@ -324,7 +316,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,
|
||||||
@@ -332,7 +327,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) {
|
||||||
@@ -341,7 +337,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'),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ 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';
|
||||||
@@ -191,11 +192,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;
|
||||||
@@ -247,11 +245,8 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
|||||||
}).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;
|
||||||
}
|
}
|
||||||
@@ -299,22 +294,16 @@ class _AddExpenseDialogState extends State<AddExpenseDialog> {
|
|||||||
|
|
||||||
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(
|
? 'Dépense ajoutée'
|
||||||
widget.expenseToEdit == null
|
: 'Dépense modifiée',
|
||||||
? 'Dépense ajoutée'
|
isError: false,
|
||||||
: 'Dépense modifiée',
|
|
||||||
),
|
|
||||||
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) {
|
||||||
|
|||||||
@@ -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();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import 'balances_tab.dart';
|
|||||||
import 'expenses_tab.dart';
|
import 'expenses_tab.dart';
|
||||||
import '../../models/user_balance.dart';
|
import '../../models/user_balance.dart';
|
||||||
import '../../models/expense.dart';
|
import '../../models/expense.dart';
|
||||||
|
import '../../services/error_service.dart';
|
||||||
|
|
||||||
class GroupExpensesPage extends StatefulWidget {
|
class GroupExpensesPage extends StatefulWidget {
|
||||||
final Account account;
|
final Account account;
|
||||||
@@ -93,20 +94,13 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
|||||||
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(
|
|
||||||
content: Text(state.message),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else if (state is ExpensesLoaded) {
|
} else if (state is ExpensesLoaded) {
|
||||||
// Rafraîchir les balances quand les dépenses changent (ex: via stream)
|
// Rafraîchir les balances quand les dépenses changent (ex: via stream)
|
||||||
context.read<BalanceBloc>().add(
|
context.read<BalanceBloc>().add(
|
||||||
@@ -213,8 +207,8 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
|
heroTag: 'group_expenses_fab',
|
||||||
onPressed: _showAddExpenseDialog,
|
onPressed: _showAddExpenseDialog,
|
||||||
heroTag: "add_expense_fab",
|
|
||||||
backgroundColor: Colors.blue,
|
backgroundColor: Colors.blue,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
elevation: 4,
|
elevation: 4,
|
||||||
@@ -393,12 +387,7 @@ class _GroupExpensesPageState extends State<GroupExpensesPage>
|
|||||||
AddExpenseDialog(group: widget.group, currentUser: userState.user),
|
AddExpenseDialog(group: widget.group, 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,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 '../../blocs/activity/activity_bloc.dart';
|
import '../../blocs/activity/activity_bloc.dart';
|
||||||
import '../../blocs/activity/activity_event.dart';
|
import '../../blocs/activity/activity_event.dart';
|
||||||
import '../../blocs/activity/activity_state.dart';
|
import '../../blocs/activity/activity_state.dart';
|
||||||
@@ -10,6 +11,8 @@ import '../../services/activity_cache_service.dart';
|
|||||||
import '../loading/laoding_content.dart';
|
import '../loading/laoding_content.dart';
|
||||||
import '../../blocs/user/user_bloc.dart';
|
import '../../blocs/user/user_bloc.dart';
|
||||||
import '../../blocs/user/user_state.dart';
|
import '../../blocs/user/user_state.dart';
|
||||||
|
import '../../services/error_service.dart';
|
||||||
|
import 'activity_detail_dialog.dart';
|
||||||
|
|
||||||
class ActivitiesPage extends StatefulWidget {
|
class ActivitiesPage extends StatefulWidget {
|
||||||
final Trip trip;
|
final Trip trip;
|
||||||
@@ -120,22 +123,15 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
return BlocListener<ActivityBloc, ActivityState>(
|
return BlocListener<ActivityBloc, ActivityState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (state is ActivityError) {
|
if (state is ActivityError) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ErrorService().showError(
|
||||||
SnackBar(
|
message: state.message,
|
||||||
content: Text(state.message),
|
onRetry: () {
|
||||||
backgroundColor: Colors.red,
|
if (_tabController.index == 2) {
|
||||||
action: SnackBarAction(
|
_searchGoogleActivities();
|
||||||
label: 'Réessayer',
|
} else {
|
||||||
textColor: Colors.white,
|
_loadActivities();
|
||||||
onPressed: () {
|
}
|
||||||
if (_tabController.index == 2) {
|
},
|
||||||
_searchGoogleActivities();
|
|
||||||
} else {
|
|
||||||
_loadActivities();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,20 +148,14 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Afficher un feedback de succès
|
// Afficher un feedback de succès
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
// Afficher un feedback de succès
|
||||||
SnackBar(
|
ErrorService().showSnackbar(
|
||||||
content: Text('${state.activity.name} ajoutée au voyage !'),
|
message: '${state.activity.name} ajoutée au voyage !',
|
||||||
duration: const Duration(seconds: 2),
|
isError: false,
|
||||||
backgroundColor: Colors.green,
|
onRetry: () {
|
||||||
action: SnackBarAction(
|
// Revenir à l'onglet des activités du voyage
|
||||||
label: 'Voir',
|
_tabController.animateTo(0);
|
||||||
textColor: Colors.white,
|
},
|
||||||
onPressed: () {
|
|
||||||
// Revenir à l'onglet des activités du voyage
|
|
||||||
_tabController.animateTo(0);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -217,21 +207,13 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
_tripActivities.add(state.newlyAddedActivity!);
|
_tripActivities.add(state.newlyAddedActivity!);
|
||||||
});
|
});
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ErrorService().showSnackbar(
|
||||||
SnackBar(
|
message:
|
||||||
content: Text(
|
|
||||||
'${state.newlyAddedActivity!.name} ajoutée au voyage !',
|
'${state.newlyAddedActivity!.name} ajoutée au voyage !',
|
||||||
),
|
isError: false,
|
||||||
duration: const Duration(seconds: 2),
|
onRetry: () {
|
||||||
backgroundColor: Colors.green,
|
_tabController.animateTo(0);
|
||||||
action: SnackBarAction(
|
},
|
||||||
label: 'Voir',
|
|
||||||
textColor: Colors.white,
|
|
||||||
onPressed: () {
|
|
||||||
_tabController.animateTo(0);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -655,315 +637,330 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
activity.name.toLowerCase().trim(),
|
activity.name.toLowerCase().trim(),
|
||||||
);
|
);
|
||||||
|
|
||||||
return Card(
|
return GestureDetector(
|
||||||
margin: const EdgeInsets.only(bottom: 12),
|
onTap: () {
|
||||||
child: Column(
|
showDialog(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
context: context,
|
||||||
children: [
|
builder: (context) => ActivityDetailDialog(activity: activity),
|
||||||
// Image de l'activité
|
);
|
||||||
if (activity.imageUrl != null && activity.imageUrl!.isNotEmpty)
|
},
|
||||||
ClipRRect(
|
child: Card(
|
||||||
borderRadius: const BorderRadius.vertical(
|
margin: const EdgeInsets.only(bottom: 12),
|
||||||
top: Radius.circular(12),
|
child: Column(
|
||||||
),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
child: SizedBox(
|
children: [
|
||||||
height: 200,
|
// Image de l'activité
|
||||||
width: double.infinity,
|
if (activity.imageUrl != null && activity.imageUrl!.isNotEmpty)
|
||||||
child: Image.network(
|
ClipRRect(
|
||||||
activity.imageUrl!,
|
borderRadius: const BorderRadius.vertical(
|
||||||
fit: BoxFit.cover,
|
top: Radius.circular(12),
|
||||||
errorBuilder: (context, error, stackTrace) {
|
),
|
||||||
return Container(
|
child: SizedBox(
|
||||||
height: 200,
|
height: 200,
|
||||||
color: theme.colorScheme.surfaceContainerHighest,
|
width: double.infinity,
|
||||||
child: Column(
|
child: Image.network(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
activity.imageUrl!,
|
||||||
children: [
|
fit: BoxFit.cover,
|
||||||
Icon(
|
errorBuilder: (context, error, stackTrace) {
|
||||||
Icons.image_not_supported,
|
return Container(
|
||||||
size: 48,
|
height: 200,
|
||||||
color: theme.colorScheme.onSurfaceVariant,
|
color: theme.colorScheme.surfaceContainerHighest,
|
||||||
),
|
child: Column(
|
||||||
const SizedBox(height: 8),
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
Text(
|
children: [
|
||||||
'Image non disponible',
|
Icon(
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
Icons.image_not_supported,
|
||||||
|
size: 48,
|
||||||
color: theme.colorScheme.onSurfaceVariant,
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 8),
|
||||||
],
|
Text(
|
||||||
),
|
'Image non disponible',
|
||||||
);
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
},
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
loadingBuilder: (context, child, loadingProgress) {
|
),
|
||||||
if (loadingProgress == null) return child;
|
),
|
||||||
return Container(
|
],
|
||||||
height: 200,
|
|
||||||
color: theme.colorScheme.surfaceContainerHighest,
|
|
||||||
child: Center(
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
value: loadingProgress.expectedTotalBytes != null
|
|
||||||
? loadingProgress.cumulativeBytesLoaded /
|
|
||||||
loadingProgress.expectedTotalBytes!
|
|
||||||
: null,
|
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
},
|
||||||
},
|
loadingBuilder: (context, child, loadingProgress) {
|
||||||
|
if (loadingProgress == null) return child;
|
||||||
|
return Container(
|
||||||
|
height: 200,
|
||||||
|
color: theme.colorScheme.surfaceContainerHighest,
|
||||||
|
child: Center(
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
value: loadingProgress.expectedTotalBytes != null
|
||||||
|
? loadingProgress.cumulativeBytesLoaded /
|
||||||
|
loadingProgress.expectedTotalBytes!
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
|
|
||||||
// Contenu de la carte
|
// Contenu de la carte
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
// Icône de catégorie
|
// Icône de catégorie
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: theme.colorScheme.primary.withValues(alpha: 0.1),
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
child: Icon(
|
|
||||||
_getCategoryIcon(activity.category),
|
|
||||||
color: theme.colorScheme.primary,
|
|
||||||
size: 20,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
// Nom et catégorie
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
activity.name,
|
|
||||||
style: theme.textTheme.titleMedium?.copyWith(
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
activity.category,
|
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
|
||||||
color: theme.colorScheme.primary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// Note
|
|
||||||
if (activity.rating != null)
|
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.all(8),
|
||||||
horizontal: 8,
|
|
||||||
vertical: 4,
|
|
||||||
),
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.amber.withValues(alpha: 0.1),
|
color: theme.colorScheme.primary.withValues(
|
||||||
borderRadius: BorderRadius.circular(12),
|
alpha: 0.1,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Icon(
|
||||||
mainAxisSize: MainAxisSize.min,
|
_getCategoryIcon(activity.category),
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
// Nom et catégorie
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const Icon(
|
|
||||||
Icons.star,
|
|
||||||
color: Colors.amber,
|
|
||||||
size: 16,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Text(
|
Text(
|
||||||
activity.rating!.toStringAsFixed(1),
|
activity.name,
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
style: theme.textTheme.titleMedium?.copyWith(
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Text(
|
||||||
|
activity.category,
|
||||||
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
// Note
|
||||||
),
|
if (activity.rating != null)
|
||||||
if (activity.description.isNotEmpty) ...[
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Text(
|
|
||||||
activity.description,
|
|
||||||
style: theme.textTheme.bodyMedium?.copyWith(
|
|
||||||
color: theme.colorScheme.onSurface.withValues(alpha: 0.8),
|
|
||||||
),
|
|
||||||
maxLines: 2,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
if (activity.address != null) ...[
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
Icons.location_on,
|
|
||||||
size: 16,
|
|
||||||
color: theme.colorScheme.onSurface.withValues(
|
|
||||||
alpha: 0.6,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
activity.address!,
|
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
|
||||||
color: theme.colorScheme.onSurface.withValues(
|
|
||||||
alpha: 0.6,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
// Boutons d'action et votes (différents selon le contexte)
|
|
||||||
if (isGoogleSuggestion) ...[
|
|
||||||
// Pour les suggestions Google : bouton d'ajout ou indication si déjà ajoutée
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
if (activityAlreadyExists) ...[
|
|
||||||
// Activité déjà dans le voyage
|
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 12,
|
horizontal: 8,
|
||||||
vertical: 8,
|
vertical: 4,
|
||||||
),
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.orange.withValues(alpha: 0.1),
|
color: Colors.amber.withValues(alpha: 0.1),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
border: Border.all(
|
|
||||||
color: Colors.orange.withValues(alpha: 0.3),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
const Icon(
|
||||||
Icons.check_circle,
|
Icons.star,
|
||||||
|
color: Colors.amber,
|
||||||
size: 16,
|
size: 16,
|
||||||
color: Colors.orange.shade700,
|
|
||||||
),
|
),
|
||||||
const SizedBox(width: 6),
|
const SizedBox(width: 4),
|
||||||
Text(
|
Text(
|
||||||
'Déjà dans le voyage',
|
activity.rating!.toStringAsFixed(1),
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
color: Colors.orange.shade700,
|
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
] else ...[
|
],
|
||||||
// Bouton pour ajouter l'activité
|
),
|
||||||
|
if (activity.description.isNotEmpty) ...[
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Text(
|
||||||
|
activity.description,
|
||||||
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurface.withValues(
|
||||||
|
alpha: 0.8,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
maxLines: 2,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
if (activity.address != null) ...[
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.location_on,
|
||||||
|
size: 16,
|
||||||
|
color: theme.colorScheme.onSurface.withValues(
|
||||||
|
alpha: 0.6,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ElevatedButton.icon(
|
child: Text(
|
||||||
onPressed: () => _addGoogleActivityToTrip(activity),
|
activity.address!,
|
||||||
icon: const Icon(Icons.add, size: 18),
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
label: const Text('Ajouter au voyage'),
|
color: theme.colorScheme.onSurface.withValues(
|
||||||
style: ElevatedButton.styleFrom(
|
alpha: 0.6,
|
||||||
backgroundColor: theme.colorScheme.primary,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
] else ...[
|
const SizedBox(height: 12),
|
||||||
// Pour les activités du voyage : système de votes
|
// Boutons d'action et votes (différents selon le contexte)
|
||||||
Row(
|
if (isGoogleSuggestion) ...[
|
||||||
children: [
|
// Pour les suggestions Google : bouton d'ajout ou indication si déjà ajoutée
|
||||||
// Votes positifs (pouces verts)
|
Row(
|
||||||
Container(
|
children: [
|
||||||
padding: const EdgeInsets.symmetric(
|
if (activityAlreadyExists) ...[
|
||||||
horizontal: 8,
|
// Activité déjà dans le voyage
|
||||||
vertical: 4,
|
Container(
|
||||||
),
|
padding: const EdgeInsets.symmetric(
|
||||||
decoration: BoxDecoration(
|
horizontal: 12,
|
||||||
color: Colors.green.withValues(alpha: 0.1),
|
vertical: 8,
|
||||||
borderRadius: BorderRadius.circular(12),
|
),
|
||||||
),
|
decoration: BoxDecoration(
|
||||||
child: Row(
|
color: Colors.orange.withValues(alpha: 0.1),
|
||||||
mainAxisSize: MainAxisSize.min,
|
borderRadius: BorderRadius.circular(12),
|
||||||
children: [
|
border: Border.all(
|
||||||
Text(
|
color: Colors.orange.withValues(alpha: 0.3),
|
||||||
'${activity.positiveVotes}',
|
),
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.check_circle,
|
||||||
|
size: 16,
|
||||||
|
color: Colors.orange.shade700,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Text(
|
||||||
|
'Déjà dans le voyage',
|
||||||
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
|
color: Colors.orange.shade700,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
] else ...[
|
||||||
|
// Bouton pour ajouter l'activité
|
||||||
|
Expanded(
|
||||||
|
child: ElevatedButton.icon(
|
||||||
|
onPressed: () =>
|
||||||
|
_addGoogleActivityToTrip(activity),
|
||||||
|
icon: const Icon(Icons.add, size: 18),
|
||||||
|
label: const Text('Ajouter au voyage'),
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: theme.colorScheme.primary,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 12,
|
||||||
|
),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
] else ...[
|
||||||
|
// Pour les activités du voyage : système de votes
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
// Votes positifs (pouces verts)
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 8,
|
||||||
|
vertical: 4,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.green.withValues(alpha: 0.1),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'${activity.positiveVotes}',
|
||||||
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
|
color: Colors.green.shade700,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Icon(
|
||||||
|
Icons.thumb_up,
|
||||||
|
size: 16,
|
||||||
color: Colors.green.shade700,
|
color: Colors.green.shade700,
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
const SizedBox(width: 4),
|
),
|
||||||
Icon(
|
|
||||||
Icons.thumb_up,
|
|
||||||
size: 16,
|
|
||||||
color: Colors.green.shade700,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(width: 8),
|
||||||
const SizedBox(width: 8),
|
// Votes négatifs (pouces rouges)
|
||||||
// Votes négatifs (pouces rouges)
|
Container(
|
||||||
Container(
|
padding: const EdgeInsets.symmetric(
|
||||||
padding: const EdgeInsets.symmetric(
|
horizontal: 8,
|
||||||
horizontal: 8,
|
vertical: 4,
|
||||||
vertical: 4,
|
),
|
||||||
),
|
decoration: BoxDecoration(
|
||||||
decoration: BoxDecoration(
|
color: Colors.red.withValues(alpha: 0.1),
|
||||||
color: Colors.red.withValues(alpha: 0.1),
|
borderRadius: BorderRadius.circular(12),
|
||||||
borderRadius: BorderRadius.circular(12),
|
),
|
||||||
),
|
child: Row(
|
||||||
child: Row(
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisSize: MainAxisSize.min,
|
children: [
|
||||||
children: [
|
Text(
|
||||||
Text(
|
'${activity.negativeVotes}',
|
||||||
'${activity.negativeVotes}',
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
color: Colors.red.shade700,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Icon(
|
||||||
|
Icons.thumb_down,
|
||||||
|
size: 16,
|
||||||
color: Colors.red.shade700,
|
color: Colors.red.shade700,
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
const SizedBox(width: 4),
|
),
|
||||||
Icon(
|
|
||||||
Icons.thumb_down,
|
|
||||||
size: 16,
|
|
||||||
color: Colors.red.shade700,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
const Spacer(),
|
||||||
const Spacer(),
|
// Bouton J'aime/J'aime pas
|
||||||
// Bouton J'aime/J'aime pas
|
IconButton(
|
||||||
IconButton(
|
onPressed: () => _voteForActivity(activity.id, 1),
|
||||||
onPressed: () => _voteForActivity(activity.id, 1),
|
icon: const Icon(Icons.thumb_up),
|
||||||
icon: const Icon(Icons.thumb_up),
|
iconSize: 20,
|
||||||
iconSize: 20,
|
),
|
||||||
),
|
IconButton(
|
||||||
IconButton(
|
onPressed: () => _voteForActivity(activity.id, -1),
|
||||||
onPressed: () => _voteForActivity(activity.id, -1),
|
icon: const Icon(Icons.thumb_down),
|
||||||
icon: const Icon(Icons.thumb_down),
|
iconSize: 20,
|
||||||
iconSize: 20,
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
],
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1026,12 +1023,9 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
|
|
||||||
// Si l'activité a été trouvée et que l'utilisateur a déjà voté
|
// Si l'activité a été trouvée et que l'utilisateur a déjà voté
|
||||||
if (currentActivity.id.isNotEmpty && currentActivity.hasUserVoted(userId)) {
|
if (currentActivity.id.isNotEmpty && currentActivity.hasUserVoted(userId)) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ErrorService().showSnackbar(
|
||||||
const SnackBar(
|
message: 'Vous avez déjà voté pour cette activité',
|
||||||
content: Text('Vous avez déjà voté pour cette activité'),
|
isError: true,
|
||||||
backgroundColor: Colors.orange,
|
|
||||||
duration: Duration(seconds: 2),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1044,13 +1038,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
final message = vote == 1
|
final message = vote == 1
|
||||||
? 'Vote positif ajouté !'
|
? 'Vote positif ajouté !'
|
||||||
: 'Vote négatif ajouté !';
|
: 'Vote négatif ajouté !';
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ErrorService().showSnackbar(message: message, isError: false);
|
||||||
SnackBar(
|
|
||||||
content: Text(message),
|
|
||||||
duration: const Duration(seconds: 1),
|
|
||||||
backgroundColor: vote == 1 ? Colors.green : Colors.orange,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _addGoogleActivityToTrip(Activity activity) {
|
void _addGoogleActivityToTrip(Activity activity) {
|
||||||
@@ -1059,6 +1047,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
|||||||
tripId: widget.trip.id,
|
tripId: widget.trip.id,
|
||||||
// Générer un nouvel ID unique pour cette activité dans le voyage
|
// Générer un nouvel ID unique pour cette activité dans le voyage
|
||||||
id: DateTime.now().millisecondsSinceEpoch.toString(),
|
id: DateTime.now().millisecondsSinceEpoch.toString(),
|
||||||
|
createdBy: FirebaseAuth.instance.currentUser?.uid,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Afficher le LoadingContent avec la tâche d'ajout
|
// Afficher le LoadingContent avec la tâche d'ajout
|
||||||
|
|||||||
322
lib/components/activities/activity_detail_dialog.dart
Normal file
322
lib/components/activities/activity_detail_dialog.dart
Normal 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)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -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,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -10,6 +10,7 @@ import '../../models/group.dart';
|
|||||||
import '../../models/group_member.dart';
|
import '../../models/group_member.dart';
|
||||||
import '../../models/message.dart';
|
import '../../models/message.dart';
|
||||||
import '../../repositories/group_repository.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.
|
||||||
///
|
///
|
||||||
@@ -220,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) {
|
||||||
@@ -338,7 +334,8 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
vertical: 12,
|
vertical: 12,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
maxLines: null,
|
maxLines: 5,
|
||||||
|
minLines: 1,
|
||||||
textCapitalization: TextCapitalization.sentences,
|
textCapitalization: TextCapitalization.sentences,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -410,12 +407,10 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Trouver le membre qui a envoyé le message pour récupérer son pseudo actuel
|
// Trouver le membre qui a envoyé le message pour récupérer son pseudo actuel
|
||||||
final senderMember =
|
final senderMember = widget.group.members.cast<GroupMember?>().firstWhere(
|
||||||
widget.group.members.firstWhere(
|
(m) => m?.userId == message.senderId,
|
||||||
(m) => m.userId == message.senderId,
|
orElse: () => null,
|
||||||
orElse: () => null as dynamic,
|
);
|
||||||
)
|
|
||||||
as dynamic;
|
|
||||||
|
|
||||||
// Utiliser le pseudo actuel du membre, ou le senderName en fallback
|
// Utiliser le pseudo actuel du membre, ou le senderName en fallback
|
||||||
final displayName = senderMember != null
|
final displayName = senderMember != null
|
||||||
@@ -871,20 +866,15 @@ class _ChatGroupContentState extends State<ChatGroupContent> {
|
|||||||
// Le stream listener va automatiquement mettre à jour les membres
|
// Le stream listener va automatiquement mettre à jour les membres
|
||||||
// Pas besoin de fermer le dialog ou de faire un refresh manuel
|
// Pas besoin de fermer le dialog ou de faire un refresh manuel
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ErrorService().showSnackbar(
|
||||||
SnackBar(
|
message: 'Pseudo modifié en "$newPseudo"',
|
||||||
content: Text('Pseudo modifié en "$newPseudo"'),
|
isError: false,
|
||||||
backgroundColor: Colors.green,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ErrorService().showError(
|
||||||
SnackBar(
|
message: 'Erreur lors de la modification du pseudo: $e',
|
||||||
content: Text('Erreur lors de la modification du pseudo: $e'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
@@ -209,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,
|
||||||
@@ -220,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,
|
||||||
@@ -232,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,
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import '../../../models/activity.dart';
|
|||||||
import '../../../blocs/activity/activity_bloc.dart';
|
import '../../../blocs/activity/activity_bloc.dart';
|
||||||
import '../../../blocs/activity/activity_state.dart';
|
import '../../../blocs/activity/activity_state.dart';
|
||||||
import '../../../blocs/activity/activity_event.dart';
|
import '../../../blocs/activity/activity_event.dart';
|
||||||
|
import '../../../repositories/user_repository.dart';
|
||||||
|
import '../../../models/user.dart';
|
||||||
|
|
||||||
class CalendarPage extends StatefulWidget {
|
class CalendarPage extends StatefulWidget {
|
||||||
final Trip trip;
|
final Trip trip;
|
||||||
@@ -20,7 +22,7 @@ class CalendarPage extends StatefulWidget {
|
|||||||
class _CalendarPageState extends State<CalendarPage> {
|
class _CalendarPageState extends State<CalendarPage> {
|
||||||
late DateTime _focusedDay;
|
late DateTime _focusedDay;
|
||||||
DateTime? _selectedDay;
|
DateTime? _selectedDay;
|
||||||
CalendarFormat _calendarFormat = CalendarFormat.month;
|
final CalendarFormat _calendarFormat = CalendarFormat.week;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -70,13 +72,32 @@ class _CalendarPageState extends State<CalendarPage> {
|
|||||||
@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;
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
backgroundColor: isDarkMode
|
||||||
|
? theme.scaffoldBackgroundColor
|
||||||
|
: Colors.white,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Calendrier du voyage'),
|
title: Text(
|
||||||
backgroundColor: theme.colorScheme.surface,
|
widget.trip.title,
|
||||||
foregroundColor: theme.colorScheme.onSurface,
|
style: theme.textTheme.titleLarge?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
centerTitle: true,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
elevation: 0,
|
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>(
|
body: BlocBuilder<ActivityBloc, ActivityState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
@@ -88,8 +109,7 @@ class _CalendarPageState extends State<CalendarPage> {
|
|||||||
if (state is ActivityLoaded) {
|
if (state is ActivityLoaded) {
|
||||||
allActivities = state.activities;
|
allActivities = state.activities;
|
||||||
} else if (state is ActivitySearchResults) {
|
} else if (state is ActivitySearchResults) {
|
||||||
// Fallback if we are in search state, though ideally we should be in loaded state
|
// Fallback if we are in search state
|
||||||
// This might happen if we navigate back and forth
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter approved activities
|
// Filter approved activities
|
||||||
@@ -113,215 +133,124 @@ class _CalendarPageState extends State<CalendarPage> {
|
|||||||
scheduledActivities,
|
scheduledActivities,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Sort by time
|
||||||
|
selectedActivities.sort((a, b) => a.date!.compareTo(b.date!));
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
TableCalendar(
|
// Calendar Strip
|
||||||
firstDay: DateTime.now().subtract(const Duration(days: 365)),
|
Container(
|
||||||
lastDay: DateTime.now().add(const Duration(days: 365)),
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
focusedDay: _focusedDay,
|
decoration: BoxDecoration(
|
||||||
calendarFormat: _calendarFormat,
|
color: isDarkMode ? theme.cardColor : Colors.grey[100],
|
||||||
selectedDayPredicate: (day) {
|
borderRadius: BorderRadius.circular(12),
|
||||||
return isSameDay(_selectedDay, day);
|
),
|
||||||
},
|
child: TableCalendar(
|
||||||
onDaySelected: (selectedDay, focusedDay) {
|
firstDay: DateTime.now().subtract(const Duration(days: 365)),
|
||||||
setState(() {
|
lastDay: DateTime.now().add(const Duration(days: 365)),
|
||||||
_selectedDay = selectedDay;
|
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;
|
_focusedDay = focusedDay;
|
||||||
});
|
},
|
||||||
},
|
eventLoader: (day) {
|
||||||
onFormatChanged: (format) {
|
return _getActivitiesForDay(day, scheduledActivities);
|
||||||
setState(() {
|
|
||||||
_calendarFormat = format;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onPageChanged: (focusedDay) {
|
|
||||||
_focusedDay = focusedDay;
|
|
||||||
},
|
|
||||||
eventLoader: (day) {
|
|
||||||
return _getActivitiesForDay(day, scheduledActivities);
|
|
||||||
},
|
|
||||||
calendarBuilders: CalendarBuilders(
|
|
||||||
markerBuilder: (context, day, events) {
|
|
||||||
if (events.isEmpty) return null;
|
|
||||||
return Positioned(
|
|
||||||
bottom: 1,
|
|
||||||
child: Container(
|
|
||||||
width: 7,
|
|
||||||
height: 7,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
color: theme.colorScheme.primary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
calendarStyle: CalendarStyle(
|
|
||||||
todayDecoration: BoxDecoration(
|
|
||||||
color: theme.colorScheme.primary.withValues(alpha: 0.5),
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
|
||||||
selectedDecoration: BoxDecoration(
|
|
||||||
color: theme.colorScheme.primary,
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const Divider(),
|
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
// Timeline View
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: SingleChildScrollView(
|
||||||
children: [
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||||
// Scheduled Activities for Selected Day
|
child: Column(
|
||||||
Expanded(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
flex: 3,
|
children: [
|
||||||
child: Column(
|
// Timeline
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
if (selectedActivities.isEmpty)
|
||||||
children: [
|
Padding(
|
||||||
Padding(
|
padding: const EdgeInsets.symmetric(vertical: 32),
|
||||||
padding: const EdgeInsets.all(8.0),
|
child: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
'Activités du ${DateFormat('dd/MM/yyyy').format(_selectedDay!)}',
|
'Aucune activité prévue ce jour',
|
||||||
style: theme.textTheme.titleMedium,
|
style: theme.textTheme.bodyLarge?.copyWith(
|
||||||
),
|
color: theme.colorScheme.onSurface.withValues(
|
||||||
),
|
alpha: 0.5,
|
||||||
Expanded(
|
|
||||||
child: selectedActivities.isEmpty
|
|
||||||
? Center(
|
|
||||||
child: Text(
|
|
||||||
'Aucune activité prévue',
|
|
||||||
style: theme.textTheme.bodyMedium
|
|
||||||
?.copyWith(
|
|
||||||
color: theme.colorScheme.onSurface
|
|
||||||
.withValues(alpha: 0.6),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: ListView.builder(
|
|
||||||
itemCount: selectedActivities.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final activity =
|
|
||||||
selectedActivities[index];
|
|
||||||
return ListTile(
|
|
||||||
title: Text(activity.name),
|
|
||||||
subtitle: Text(
|
|
||||||
'${activity.category} - ${DateFormat('HH:mm').format(activity.date!)}',
|
|
||||||
),
|
|
||||||
trailing: IconButton(
|
|
||||||
icon: const Icon(Icons.close),
|
|
||||||
onPressed: () {
|
|
||||||
context.read<ActivityBloc>().add(
|
|
||||||
UpdateActivityDate(
|
|
||||||
tripId: widget.trip.id!,
|
|
||||||
activityId: activity.id,
|
|
||||||
date: null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const VerticalDivider(),
|
|
||||||
// Unscheduled Activities
|
|
||||||
Expanded(
|
|
||||||
flex: 2,
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Text(
|
|
||||||
'À planifier',
|
|
||||||
style: theme.textTheme.titleMedium,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: unscheduledActivities.isEmpty
|
|
||||||
? Center(
|
|
||||||
child: Text(
|
|
||||||
'Tout est planifié !',
|
|
||||||
style: theme.textTheme.bodyMedium
|
|
||||||
?.copyWith(
|
|
||||||
color: theme.colorScheme.onSurface
|
|
||||||
.withValues(alpha: 0.6),
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: ListView.builder(
|
|
||||||
itemCount: unscheduledActivities.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final activity =
|
|
||||||
unscheduledActivities[index];
|
|
||||||
return Draggable<Activity>(
|
|
||||||
data: activity,
|
|
||||||
feedback: Material(
|
|
||||||
elevation: 4,
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
color: theme.cardColor,
|
|
||||||
child: Text(activity.name),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: ListTile(
|
|
||||||
title: Text(
|
|
||||||
activity.name,
|
|
||||||
style: theme.textTheme.bodySmall,
|
|
||||||
),
|
|
||||||
trailing: IconButton(
|
|
||||||
icon: const Icon(Icons.arrow_back),
|
|
||||||
onPressed: () {
|
|
||||||
if (_selectedDay != null) {
|
|
||||||
_selectTimeAndSchedule(
|
|
||||||
activity,
|
|
||||||
_selectedDay!,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// Zone de drop pour le calendrier
|
|
||||||
DragTarget<Activity>(
|
|
||||||
onWillAcceptWithDetails: (details) => true,
|
|
||||||
onAcceptWithDetails: (details) {
|
|
||||||
if (_selectedDay != null) {
|
|
||||||
_selectTimeAndSchedule(
|
|
||||||
details.data,
|
|
||||||
_selectedDay!,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
builder: (context, candidateData, rejectedData) {
|
|
||||||
return Container(
|
|
||||||
height: 50,
|
|
||||||
color: candidateData.isNotEmpty
|
|
||||||
? theme.colorScheme.primary.withValues(
|
|
||||||
alpha: 0.1,
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
child: Center(
|
|
||||||
child: Text(
|
|
||||||
'Glisser ici pour planifier',
|
|
||||||
style: TextStyle(
|
|
||||||
color: theme.colorScheme.primary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
},
|
),
|
||||||
),
|
),
|
||||||
],
|
)
|
||||||
|
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),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -330,4 +259,229 @@ class _CalendarPageState extends State<CalendarPage> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
59
lib/components/home/calendar/calendar_page.dart_snippet
Normal file
59
lib/components/home/calendar/calendar_page.dart_snippet
Normal 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'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -876,17 +876,16 @@ 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(
|
_errorService.showError(message: 'Email invalide');
|
||||||
context,
|
|
||||||
).showSnackBar(SnackBar(content: Text('Email invalide')));
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_participants.contains(email)) {
|
if (_participants.contains(email)) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
_errorService.showSnackbar(
|
||||||
SnackBar(content: Text('Ce participant est déjà ajouté')),
|
message: 'Ce participant est déjà ajouté',
|
||||||
|
isError: true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -962,11 +961,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
_errorService.showSnackbar(
|
||||||
SnackBar(
|
message: 'Groupe et compte mis à jour avec succès !',
|
||||||
content: Text('Groupe et compte mis à jour avec succès !'),
|
isError: false,
|
||||||
backgroundColor: Colors.green,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
@@ -1048,11 +1045,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
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;
|
||||||
@@ -1066,9 +1061,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;
|
||||||
});
|
});
|
||||||
@@ -1083,8 +1076,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;
|
||||||
@@ -1129,14 +1123,10 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
// 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)',
|
||||||
),
|
isError: true, // Warning displayed as error for now
|
||||||
backgroundColor: Colors.orange,
|
|
||||||
duration: Duration(seconds: 2),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1167,9 +1157,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
}
|
}
|
||||||
} 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;
|
||||||
@@ -1200,11 +1188,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
|||||||
});
|
});
|
||||||
} 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,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -155,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>();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:travel_mate/blocs/trip/trip_bloc.dart';
|
import 'package:travel_mate/blocs/trip/trip_bloc.dart';
|
||||||
import 'package:travel_mate/blocs/trip/trip_event.dart';
|
import 'package:travel_mate/blocs/trip/trip_event.dart';
|
||||||
@@ -9,14 +10,29 @@ import 'package:travel_mate/components/home/create_trip_content.dart';
|
|||||||
import 'package:travel_mate/models/trip.dart';
|
import 'package:travel_mate/models/trip.dart';
|
||||||
import 'package:travel_mate/components/map/map_content.dart';
|
import 'package:travel_mate/components/map/map_content.dart';
|
||||||
import 'package:travel_mate/services/error_service.dart';
|
import 'package:travel_mate/services/error_service.dart';
|
||||||
import 'package:travel_mate/services/activity_cache_service.dart';
|
import 'package:travel_mate/services/logger_service.dart';
|
||||||
|
|
||||||
import 'package:travel_mate/repositories/group_repository.dart';
|
import 'package:travel_mate/repositories/group_repository.dart';
|
||||||
import 'package:travel_mate/repositories/user_repository.dart';
|
import 'package:travel_mate/repositories/user_repository.dart';
|
||||||
import 'package:travel_mate/repositories/account_repository.dart';
|
import 'package:travel_mate/repositories/account_repository.dart';
|
||||||
import 'package:travel_mate/models/group_member.dart';
|
import 'package:travel_mate/models/group_member.dart';
|
||||||
import 'package:travel_mate/components/activities/activities_page.dart';
|
import 'package:travel_mate/components/activities/activities_page.dart';
|
||||||
|
import 'package:travel_mate/components/activities/activity_detail_dialog.dart';
|
||||||
import 'package:travel_mate/components/home/calendar/calendar_page.dart';
|
import 'package:travel_mate/components/home/calendar/calendar_page.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:travel_mate/models/activity.dart';
|
||||||
|
import 'package:travel_mate/blocs/activity/activity_state.dart';
|
||||||
|
import 'package:travel_mate/blocs/balance/balance_bloc.dart';
|
||||||
|
import 'package:travel_mate/blocs/balance/balance_event.dart';
|
||||||
|
import 'package:travel_mate/blocs/balance/balance_state.dart';
|
||||||
|
|
||||||
|
import 'package:travel_mate/blocs/user/user_bloc.dart';
|
||||||
|
import 'package:travel_mate/blocs/user/user_state.dart' as user_state;
|
||||||
|
import 'package:travel_mate/components/account/group_expenses_page.dart';
|
||||||
|
import 'package:travel_mate/models/group.dart';
|
||||||
|
import 'package:travel_mate/models/account.dart';
|
||||||
|
import 'package:travel_mate/models/user_balance.dart';
|
||||||
|
|
||||||
class ShowTripDetailsContent extends StatefulWidget {
|
class ShowTripDetailsContent extends StatefulWidget {
|
||||||
final Trip trip;
|
final Trip trip;
|
||||||
@@ -28,49 +44,48 @@ class ShowTripDetailsContent extends StatefulWidget {
|
|||||||
|
|
||||||
class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
||||||
final ErrorService _errorService = ErrorService();
|
final ErrorService _errorService = ErrorService();
|
||||||
final ActivityCacheService _cacheService = ActivityCacheService();
|
|
||||||
final GroupRepository _groupRepository = GroupRepository();
|
final GroupRepository _groupRepository = GroupRepository();
|
||||||
final UserRepository _userRepository = UserRepository();
|
final UserRepository _userRepository = UserRepository();
|
||||||
final AccountRepository _accountRepository = AccountRepository();
|
final AccountRepository _accountRepository = AccountRepository();
|
||||||
|
|
||||||
|
Group? _group;
|
||||||
|
Account? _account;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
// Lancer la recherche d'activités Google en arrière-plan
|
// Charger les activités du voyage depuis la DB
|
||||||
_preloadGoogleActivities();
|
if (widget.trip.id != null) {
|
||||||
|
context.read<ActivityBloc>().add(LoadActivities(widget.trip.id!));
|
||||||
|
_loadGroupAndAccount();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Précharger les activités Google en arrière-plan
|
Future<void> _loadGroupAndAccount() async {
|
||||||
void _preloadGoogleActivities() {
|
if (widget.trip.id == null) return;
|
||||||
// Attendre un moment avant de lancer la recherche pour ne pas bloquer l'UI
|
|
||||||
Future.delayed(const Duration(milliseconds: 500), () {
|
|
||||||
if (mounted && widget.trip.id != null) {
|
|
||||||
// Vérifier si on a déjà des activités en cache
|
|
||||||
if (_cacheService.hasCachedActivities(widget.trip.id!)) {
|
|
||||||
return; // Utiliser le cache
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sinon, lancer la recherche avec le maximum d'activités
|
try {
|
||||||
context.read<ActivityBloc>().add(
|
final group = await _groupRepository.getGroupByTripId(widget.trip.id!);
|
||||||
widget.trip.hasCoordinates
|
final account = await _accountRepository.getAccountByTripId(
|
||||||
? SearchActivitiesWithCoordinates(
|
widget.trip.id!,
|
||||||
tripId: widget.trip.id!,
|
);
|
||||||
latitude: widget.trip.latitude!,
|
|
||||||
longitude: widget.trip.longitude!,
|
if (mounted) {
|
||||||
category: null,
|
setState(() {
|
||||||
maxResults: 100, // Charger le maximum d'activités possible
|
_group = group;
|
||||||
reset: true,
|
_account = account;
|
||||||
)
|
});
|
||||||
: SearchActivities(
|
|
||||||
tripId: widget.trip.id!,
|
if (group != null) {
|
||||||
destination: widget.trip.location,
|
context.read<BalanceBloc>().add(LoadGroupBalances(group.id));
|
||||||
category: null,
|
}
|
||||||
maxResults: 100, // Charger le maximum d'activités possible
|
|
||||||
reset: true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
} catch (e) {
|
||||||
|
_errorService.logError(
|
||||||
|
'ShowTripDetailsContent',
|
||||||
|
'Error loading group/account: $e',
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculer les jours restants avant le voyage
|
// Calculer les jours restants avant le voyage
|
||||||
@@ -227,30 +242,38 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
|
|
||||||
// Méthode pour ouvrir Waze
|
// Méthode pour ouvrir Waze
|
||||||
Future<void> _openWaze() async {
|
Future<void> _openWaze() async {
|
||||||
final location = Uri.encodeComponent(widget.trip.location);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Essayer d'abord l'URL scheme pour l'app mobile
|
String wazeUrl;
|
||||||
final appUrl = 'waze://?q=$location';
|
|
||||||
final appUri = Uri.parse(appUrl);
|
// Utiliser les coordonnées si disponibles (plus précis)
|
||||||
if (await canLaunchUrl(appUri)) {
|
if (widget.trip.latitude != null && widget.trip.longitude != null) {
|
||||||
await launchUrl(appUri);
|
final lat = widget.trip.latitude;
|
||||||
return;
|
final lng = widget.trip.longitude;
|
||||||
|
// Format: https://www.waze.com/ul?ll=lat%2Clng&navigate=yes
|
||||||
|
wazeUrl = 'https://www.waze.com/ul?ll=$lat%2C$lng&navigate=yes';
|
||||||
|
LoggerService.info('Opening Waze with coordinates: $lat, $lng');
|
||||||
|
} else {
|
||||||
|
// Fallback sur l'adresse/nom
|
||||||
|
final location = Uri.encodeComponent(widget.trip.location);
|
||||||
|
wazeUrl = 'https://www.waze.com/ul?q=$location&navigate=yes';
|
||||||
|
LoggerService.info(
|
||||||
|
'Opening Waze with location query: ${widget.trip.location}',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback vers l'URL web
|
final uri = Uri.parse(wazeUrl);
|
||||||
final webUrl = 'https://waze.com/ul?q=$location';
|
|
||||||
final webUri = Uri.parse(webUrl);
|
|
||||||
if (await canLaunchUrl(webUri)) {
|
|
||||||
await launchUrl(webUri, mode: LaunchMode.externalApplication);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_errorService.showError(
|
if (await canLaunchUrl(uri)) {
|
||||||
message:
|
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||||
'Impossible d\'ouvrir Waze. Vérifiez que l\'application est installée.',
|
} else {
|
||||||
);
|
LoggerService.warning('Could not launch Waze URL: $wazeUrl');
|
||||||
|
_errorService.showError(
|
||||||
|
message:
|
||||||
|
'Impossible d\'ouvrir Waze. Vérifiez que l\'application est installée.',
|
||||||
|
);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
LoggerService.error('Error opening Waze', error: e);
|
||||||
_errorService.showError(message: 'Erreur lors de l\'ouverture de Waze');
|
_errorService.showError(message: 'Erreur lors de l\'ouverture de Waze');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -446,7 +469,19 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
icon: Icons.account_balance_wallet,
|
icon: Icons.account_balance_wallet,
|
||||||
title: 'Dépenses',
|
title: 'Dépenses',
|
||||||
color: Colors.orange,
|
color: Colors.orange,
|
||||||
onTap: () => _showComingSoon('Dépenses'),
|
onTap: () {
|
||||||
|
if (_group != null && _account != null) {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => GroupExpensesPage(
|
||||||
|
group: _group!,
|
||||||
|
account: _account!,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
_buildActionButton(
|
_buildActionButton(
|
||||||
icon: Icons.map,
|
icon: Icons.map,
|
||||||
@@ -546,15 +581,6 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showComingSoon(String feature) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text('$feature - Fonctionnalité à venir'),
|
|
||||||
backgroundColor: Colors.blue,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _showOptionsMenu() {
|
void _showOptionsMenu() {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
@@ -564,50 +590,99 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
shape: const RoundedRectangleBorder(
|
shape: const RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||||
),
|
),
|
||||||
builder: (context) => Container(
|
builder: (context) {
|
||||||
padding: const EdgeInsets.all(20),
|
return BlocBuilder<UserBloc, user_state.UserState>(
|
||||||
child: Column(
|
builder: (context, state) {
|
||||||
mainAxisSize: MainAxisSize.min,
|
final currentUser = state is user_state.UserLoaded
|
||||||
children: [
|
? state.user
|
||||||
ListTile(
|
: null;
|
||||||
leading: Icon(Icons.edit, color: theme.colorScheme.primary),
|
final isCreator = currentUser?.id == widget.trip.createdBy;
|
||||||
title: Text(
|
|
||||||
'Modifier le voyage',
|
return Container(
|
||||||
style: theme.textTheme.bodyLarge?.copyWith(
|
padding: const EdgeInsets.all(20),
|
||||||
color: theme.colorScheme.onSurface,
|
child: Column(
|
||||||
),
|
mainAxisSize: MainAxisSize.min,
|
||||||
),
|
children: [
|
||||||
onTap: () {
|
if (isCreator) ...[
|
||||||
Navigator.pop(context);
|
ListTile(
|
||||||
Navigator.push(
|
leading: Icon(
|
||||||
context,
|
Icons.edit,
|
||||||
MaterialPageRoute(
|
color: theme.colorScheme.primary,
|
||||||
builder: (context) =>
|
),
|
||||||
CreateTripContent(tripToEdit: widget.trip),
|
title: Text(
|
||||||
|
'Modifier le voyage',
|
||||||
|
style: theme.textTheme.bodyLarge?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
CreateTripContent(tripToEdit: widget.trip),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.delete, color: Colors.red),
|
||||||
|
title: Text(
|
||||||
|
'Supprimer le voyage',
|
||||||
|
style: theme.textTheme.bodyLarge?.copyWith(
|
||||||
|
color: Colors.red,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
_confirmDeleteTrip();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
],
|
||||||
|
ListTile(
|
||||||
|
leading: Icon(
|
||||||
|
Icons.share,
|
||||||
|
color: theme.colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
'Partager le code',
|
||||||
|
style: theme.textTheme.bodyLarge?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
// Implement share functionality
|
||||||
|
if (_group != null) {
|
||||||
|
// Use share_plus package to share the code
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('ID du groupe : ${_group!.id}'),
|
||||||
|
action: SnackBarAction(
|
||||||
|
label: 'Copier',
|
||||||
|
onPressed: () {
|
||||||
|
Clipboard.setData(
|
||||||
|
ClipboardData(text: _group!.id),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
],
|
||||||
},
|
|
||||||
),
|
|
||||||
ListTile(
|
|
||||||
leading: const Icon(Icons.delete, color: Colors.red),
|
|
||||||
title: Text(
|
|
||||||
'Supprimer le voyage',
|
|
||||||
style: theme.textTheme.bodyLarge?.copyWith(
|
|
||||||
color: theme.colorScheme.onSurface,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
onTap: () {
|
);
|
||||||
Navigator.pop(context);
|
},
|
||||||
_showDeleteConfirmation();
|
);
|
||||||
},
|
},
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showDeleteConfirmation() {
|
void _confirmDeleteTrip() {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
showDialog(
|
showDialog(
|
||||||
@@ -868,11 +943,8 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
_addParticipantByEmail(emailController.text);
|
_addParticipantByEmail(emailController.text);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
} else {
|
} else {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
_errorService.showError(
|
||||||
const SnackBar(
|
message: 'Veuillez entrer un email valide',
|
||||||
content: Text('Veuillez entrer un email valide'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -940,11 +1012,9 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
TripUpdateRequested(trip: updatedTrip),
|
TripUpdateRequested(trip: updatedTrip),
|
||||||
);
|
);
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
_errorService.showSnackbar(
|
||||||
SnackBar(
|
message: '${user.prenom} a été ajouté au voyage',
|
||||||
content: Text('${user.prenom} a été ajouté au voyage'),
|
isError: false,
|
||||||
backgroundColor: Colors.green,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Rafraîchir la page
|
// Rafraîchir la page
|
||||||
@@ -970,110 +1040,153 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
|
|
||||||
Widget _buildNextActivitiesSection() {
|
Widget _buildNextActivitiesSection() {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
return Column(
|
|
||||||
children: [
|
return BlocBuilder<ActivityBloc, ActivityState>(
|
||||||
Row(
|
builder: (context, state) {
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
List<Activity> activities = [];
|
||||||
|
if (state is ActivityLoaded) {
|
||||||
|
activities = state.activities;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter scheduled activities and sort by date
|
||||||
|
final scheduledActivities = activities
|
||||||
|
.where((a) => a.date != null && a.date!.isAfter(DateTime.now()))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
scheduledActivities.sort((a, b) => a.date!.compareTo(b.date!));
|
||||||
|
|
||||||
|
// Take next 3 activities
|
||||||
|
final nextActivities = scheduledActivities.take(3).toList();
|
||||||
|
|
||||||
|
if (nextActivities.isEmpty) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Row(
|
||||||
'Prochaines activités',
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
style: theme.textTheme.titleMedium?.copyWith(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: theme.colorScheme.onSurface,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => _navigateToActivities(),
|
|
||||||
child: Text(
|
|
||||||
'Tout voir',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.teal,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
_buildActivityCard(
|
|
||||||
title: 'Visite du Colisée',
|
|
||||||
date: '11 août, 10:00',
|
|
||||||
icon: Icons.museum,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
_buildActivityCard(
|
|
||||||
title: 'Dîner à Trastevere',
|
|
||||||
date: '11 août, 20:30',
|
|
||||||
icon: Icons.restaurant,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildActivityCard({
|
|
||||||
required String title,
|
|
||||||
required String date,
|
|
||||||
required IconData icon,
|
|
||||||
}) {
|
|
||||||
final theme = Theme.of(context);
|
|
||||||
final isDarkMode = theme.brightness == Brightness.dark;
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.all(16),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: theme.cardColor,
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
border: Border.all(
|
|
||||||
color: isDarkMode
|
|
||||||
? Colors.white.withValues(alpha: 0.1)
|
|
||||||
: Colors.black.withValues(alpha: 0.05),
|
|
||||||
width: 1,
|
|
||||||
),
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.black.withValues(alpha: 0.05),
|
|
||||||
blurRadius: 10,
|
|
||||||
offset: const Offset(0, 2),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.teal.withValues(alpha: 0.1),
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
child: Icon(icon, color: Colors.teal, size: 24),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 16),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
title,
|
'Prochaines activités',
|
||||||
style: theme.textTheme.bodyLarge?.copyWith(
|
style: theme.textTheme.titleMedium?.copyWith(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: theme.colorScheme.onSurface,
|
color: theme.colorScheme.onSurface,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
TextButton(
|
||||||
Text(
|
onPressed: () => Navigator.push(
|
||||||
date,
|
context,
|
||||||
style: theme.textTheme.bodyMedium?.copyWith(
|
MaterialPageRoute(
|
||||||
color: theme.colorScheme.onSurface.withValues(alpha: 0.6),
|
builder: (context) => CalendarPage(trip: widget.trip),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
'Voir calendrier',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.teal,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
...nextActivities.map((activity) {
|
||||||
|
if (activity.date == null) return const SizedBox.shrink();
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 12),
|
||||||
|
child: _buildActivityCard(activity: activity),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
return Icons.place;
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildActivityCard({required Activity activity}) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final isDarkMode = theme.brightness == Brightness.dark;
|
||||||
|
|
||||||
|
final date = activity.date != null
|
||||||
|
? DateFormat('d MMM, HH:mm', 'fr_FR').format(activity.date!)
|
||||||
|
: 'Date inconnue';
|
||||||
|
final icon = _getCategoryIcon(activity.category);
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => ActivityDetailDialog(activity: activity),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.cardColor,
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
border: Border.all(
|
||||||
|
color: isDarkMode
|
||||||
|
? Colors.white.withValues(alpha: 0.1)
|
||||||
|
: Colors.black.withValues(alpha: 0.05),
|
||||||
|
width: 1,
|
||||||
),
|
),
|
||||||
Icon(
|
boxShadow: [
|
||||||
Icons.chevron_right,
|
BoxShadow(
|
||||||
color: theme.colorScheme.onSurface.withValues(alpha: 0.4),
|
color: Colors.black.withValues(alpha: 0.05),
|
||||||
),
|
blurRadius: 10,
|
||||||
],
|
offset: const Offset(0, 2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.teal.withValues(alpha: 0.1),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Icon(icon, color: Colors.teal, size: 24),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
activity.name,
|
||||||
|
style: theme.textTheme.bodyLarge?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: theme.colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text(
|
||||||
|
date,
|
||||||
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurface.withValues(alpha: 0.6),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Icon(
|
||||||
|
Icons.chevron_right,
|
||||||
|
color: theme.colorScheme.onSurface.withValues(alpha: 0.4),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1081,61 +1194,187 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
|||||||
Widget _buildExpensesCard() {
|
Widget _buildExpensesCard() {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
return Container(
|
return BlocBuilder<BalanceBloc, BalanceState>(
|
||||||
margin: const EdgeInsets.only(top: 24),
|
builder: (context, state) {
|
||||||
padding: const EdgeInsets.all(16),
|
String balanceText = 'Chargement...';
|
||||||
decoration: BoxDecoration(
|
bool isLoading = state is BalanceLoading;
|
||||||
color: const Color(0xFFFDF4E3), // Light beige background
|
bool isPositive = true;
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
),
|
if (state is GroupBalancesLoaded) {
|
||||||
child: Row(
|
final userState = context.read<UserBloc>().state;
|
||||||
children: [
|
if (userState is user_state.UserLoaded) {
|
||||||
Container(
|
final currentUserId = userState.user.id;
|
||||||
padding: const EdgeInsets.all(10),
|
|
||||||
decoration: const BoxDecoration(
|
// Filter settlements involving the current user
|
||||||
color: Colors.orange,
|
final mySettlements = state.settlements
|
||||||
shape: BoxShape.circle,
|
.where(
|
||||||
|
(s) =>
|
||||||
|
!s.isCompleted &&
|
||||||
|
(s.fromUserId == currentUserId ||
|
||||||
|
s.toUserId == currentUserId),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
if (mySettlements.isEmpty) {
|
||||||
|
// Check if user has a balance of 0
|
||||||
|
final myBalanceObj = state.balances.firstWhere(
|
||||||
|
(b) => b.userId == currentUserId,
|
||||||
|
orElse: () => const UserBalance(
|
||||||
|
userId: '',
|
||||||
|
userName: '',
|
||||||
|
totalPaid: 0,
|
||||||
|
totalOwed: 0,
|
||||||
|
balance: 0,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (myBalanceObj.balance.abs() < 0.01) {
|
||||||
|
balanceText = 'Vous êtes à jour';
|
||||||
|
} else {
|
||||||
|
// Fallback to total balance if no settlements found but balance exists
|
||||||
|
isPositive = myBalanceObj.balance >= 0;
|
||||||
|
final amountStr =
|
||||||
|
'${myBalanceObj.balance.abs().toStringAsFixed(2)} €';
|
||||||
|
balanceText = isPositive
|
||||||
|
? 'On vous doit $amountStr'
|
||||||
|
: 'Vous devez $amountStr';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Construct detailed string
|
||||||
|
final debtsToPay = mySettlements
|
||||||
|
.where((s) => s.fromUserId == currentUserId)
|
||||||
|
.toList();
|
||||||
|
final debtsToReceive = mySettlements
|
||||||
|
.where((s) => s.toUserId == currentUserId)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
if (debtsToPay.isNotEmpty) {
|
||||||
|
isPositive = false;
|
||||||
|
final details = debtsToPay
|
||||||
|
.map(
|
||||||
|
(s) =>
|
||||||
|
'${s.amount.toStringAsFixed(2)}€ à ${s.toUserName}',
|
||||||
|
)
|
||||||
|
.join(' et ');
|
||||||
|
balanceText = 'Vous devez $details';
|
||||||
|
} else if (debtsToReceive.isNotEmpty) {
|
||||||
|
isPositive = true;
|
||||||
|
final details = debtsToReceive
|
||||||
|
.map(
|
||||||
|
(s) =>
|
||||||
|
'${s.amount.toStringAsFixed(2)}€ de ${s.fromUserName}',
|
||||||
|
)
|
||||||
|
.join(' et ');
|
||||||
|
balanceText =
|
||||||
|
'On vous doit $details'; // Or "X owes you..." but "On vous doit" is generic enough or we can be specific
|
||||||
|
// Let's be specific as requested: "X doit vous payer..." or similar?
|
||||||
|
// The user asked: "vous devez 21 euros à John..." (active voice for user paying).
|
||||||
|
// For receiving, "John vous doit 21 euros..." would be symmetric.
|
||||||
|
// Let's try to match the requested format for paying first.
|
||||||
|
|
||||||
|
if (debtsToReceive.length == 1) {
|
||||||
|
balanceText =
|
||||||
|
'${debtsToReceive.first.fromUserName} vous doit ${debtsToReceive.first.amount.toStringAsFixed(2)}€';
|
||||||
|
} else {
|
||||||
|
balanceText =
|
||||||
|
'${debtsToReceive.map((s) => '${s.fromUserName} (${s.amount.toStringAsFixed(2)}€)').join(' et ')} vous doivent de l\'argent';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
if (_group != null && _account != null) {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
GroupExpensesPage(group: _group!, account: _account!),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
margin: const EdgeInsets.only(top: 24),
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: const Color(0xFFFDF4E3), // Light beige background
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
),
|
),
|
||||||
child: const Icon(
|
child: Row(
|
||||||
Icons.warning_amber_rounded,
|
|
||||||
color: Colors.white,
|
|
||||||
size: 24,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 16),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Container(
|
||||||
'Dépenses',
|
padding: const EdgeInsets.all(10),
|
||||||
style: theme.textTheme.bodyLarge?.copyWith(
|
decoration: const BoxDecoration(
|
||||||
fontWeight: FontWeight.bold,
|
color: Colors.orange,
|
||||||
color: const Color(0xFF5D4037), // Brown text
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.warning_amber_rounded,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 24,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(width: 16),
|
||||||
Text(
|
Expanded(
|
||||||
'Vous devez 25€ à Clara',
|
child: Column(
|
||||||
style: theme.textTheme.bodyMedium?.copyWith(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
color: const Color(0xFF8D6E63), // Lighter brown
|
children: [
|
||||||
|
Text(
|
||||||
|
'Dépenses',
|
||||||
|
style: theme.textTheme.bodyLarge?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: const Color(0xFF5D4037), // Brown text
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
if (isLoading)
|
||||||
|
const SizedBox(
|
||||||
|
height: 20,
|
||||||
|
width: 20,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
Text(
|
||||||
|
balanceText,
|
||||||
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: const Color(0xFF8D6E63), // Lighter brown
|
||||||
|
),
|
||||||
|
maxLines: 2,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
if (_group != null && _account != null) {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => GroupExpensesPage(
|
||||||
|
group: _group!,
|
||||||
|
account: _account!,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Text(
|
||||||
|
'Régler',
|
||||||
|
style: TextStyle(
|
||||||
|
color: const Color(0xFF5D4037),
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
TextButton(
|
);
|
||||||
onPressed: () => _showComingSoon('Régler les dépenses'),
|
},
|
||||||
child: Text(
|
|
||||||
'Régler',
|
|
||||||
style: TextStyle(
|
|
||||||
color: const Color(0xFF5D4037),
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ class _LoadingContentState extends State<LoadingContent>
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ 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 '../../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;
|
||||||
@@ -32,8 +36,37 @@ class _MapContentState extends State<MapContent> {
|
|||||||
@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 &&
|
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) {
|
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
|
||||||
@@ -46,6 +79,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();
|
||||||
@@ -416,13 +497,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,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -663,6 +738,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),
|
||||||
|
|||||||
@@ -502,11 +502,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,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -668,11 +666,9 @@ class ProfileContent extends StatelessWidget {
|
|||||||
|
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
LoggerService.info('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) {
|
||||||
@@ -736,22 +732,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;
|
||||||
}
|
}
|
||||||
@@ -765,11 +755,9 @@ class ProfileContent extends StatelessWidget {
|
|||||||
|
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
Navigator.of(dialogContext).pop();
|
Navigator.of(dialogContext).pop();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
_errorService.showSnackbar(
|
||||||
SnackBar(
|
message: 'Mot de passe changé !',
|
||||||
content: Text('Mot de passe changé !'),
|
isError: false,
|
||||||
backgroundColor: Colors.green,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -823,11 +811,8 @@ class ProfileContent extends StatelessWidget {
|
|||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (confirmationController.text != 'CONFIRMER') {
|
if (confirmationController.text != 'CONFIRMER') {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
_errorService.showError(
|
||||||
SnackBar(
|
message: 'Veuillez écrire CONFIRMER pour valider',
|
||||||
content: Text('Veuillez écrire CONFIRMER pour valider'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -848,14 +833,10 @@ class ProfileContent extends StatelessWidget {
|
|||||||
if (e.code == 'requires-recent-login') {
|
if (e.code == 'requires-recent-login') {
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
Navigator.of(dialogContext).pop();
|
Navigator.of(dialogContext).pop();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
_errorService.showSnackbar(
|
||||||
SnackBar(
|
message:
|
||||||
content: Text(
|
|
||||||
'Par sécurité, veuillez vous reconnecter avant de supprimer votre compte',
|
'Par sécurité, veuillez vous reconnecter avant de supprimer votre compte',
|
||||||
),
|
isError: true, // It's a warning/error
|
||||||
backgroundColor: Colors.orange,
|
|
||||||
duration: Duration(seconds: 4),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ 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 '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,6 +37,8 @@ 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,
|
||||||
@@ -42,6 +47,12 @@ void main() async {
|
|||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
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();
|
||||||
|
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
@@ -117,6 +128,10 @@ class MyApp extends StatelessWidget {
|
|||||||
expenseRepository: context.read<ExpenseRepository>(),
|
expenseRepository: context.read<ExpenseRepository>(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
// Map navigation service
|
||||||
|
RepositoryProvider<MapNavigationService>(
|
||||||
|
create: (context) => MapNavigationService(),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
child: MultiBlocProvider(
|
child: MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class Activity {
|
|||||||
final DateTime createdAt;
|
final DateTime createdAt;
|
||||||
final DateTime updatedAt;
|
final DateTime updatedAt;
|
||||||
final DateTime? date; // Date prévue pour l'activité
|
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,
|
||||||
@@ -42,6 +43,7 @@ class Activity {
|
|||||||
required this.createdAt,
|
required this.createdAt,
|
||||||
required this.updatedAt,
|
required this.updatedAt,
|
||||||
this.date,
|
this.date,
|
||||||
|
this.createdBy,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Calcule le score total des votes
|
/// Calcule le score total des votes
|
||||||
@@ -108,6 +110,7 @@ class Activity {
|
|||||||
DateTime? updatedAt,
|
DateTime? updatedAt,
|
||||||
DateTime? date,
|
DateTime? date,
|
||||||
bool clearDate = false,
|
bool clearDate = false,
|
||||||
|
String? createdBy,
|
||||||
}) {
|
}) {
|
||||||
return Activity(
|
return Activity(
|
||||||
id: id ?? this.id,
|
id: id ?? this.id,
|
||||||
@@ -129,6 +132,7 @@ class Activity {
|
|||||||
createdAt: createdAt ?? this.createdAt,
|
createdAt: createdAt ?? this.createdAt,
|
||||||
updatedAt: updatedAt ?? this.updatedAt,
|
updatedAt: updatedAt ?? this.updatedAt,
|
||||||
date: clearDate ? null : (date ?? this.date),
|
date: clearDate ? null : (date ?? this.date),
|
||||||
|
createdBy: createdBy ?? this.createdBy,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +158,7 @@ class Activity {
|
|||||||
'createdAt': Timestamp.fromDate(createdAt),
|
'createdAt': Timestamp.fromDate(createdAt),
|
||||||
'updatedAt': Timestamp.fromDate(updatedAt),
|
'updatedAt': Timestamp.fromDate(updatedAt),
|
||||||
'date': date != null ? Timestamp.fromDate(date!) : null,
|
'date': date != null ? Timestamp.fromDate(date!) : null,
|
||||||
|
'createdBy': createdBy,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,6 +184,7 @@ class Activity {
|
|||||||
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,
|
date: map['date'] != null ? (map['date'] as Timestamp).toDate() : null,
|
||||||
|
createdBy: map['createdBy'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ 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';
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
class HomePage extends StatefulWidget {
|
||||||
const HomePage({super.key});
|
const HomePage({super.key});
|
||||||
@@ -36,6 +39,24 @@ 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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPage(int index) {
|
Widget _buildPage(int index) {
|
||||||
@@ -119,12 +140,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 +148,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 +156,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 +220,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),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
||||||
///
|
///
|
||||||
@@ -89,12 +90,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
if (state is AuthAuthenticated) {
|
if (state is AuthAuthenticated) {
|
||||||
Navigator.pushReplacementNamed(context, '/home');
|
Navigator.pushReplacementNamed(context, '/home');
|
||||||
} else if (state is AuthError) {
|
} else if (state is AuthError) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ErrorService().showError(message: state.message);
|
||||||
SnackBar(
|
|
||||||
content: Text(state.message),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.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/auth/auth_state.dart';
|
import '../blocs/auth/auth_state.dart';
|
||||||
|
import '../services/error_service.dart';
|
||||||
|
|
||||||
class ForgotPasswordPage extends StatefulWidget {
|
class ForgotPasswordPage extends StatefulWidget {
|
||||||
const ForgotPasswordPage({super.key});
|
const ForgotPasswordPage({super.key});
|
||||||
@@ -56,20 +57,13 @@ class _ForgotPasswordPageState extends State<ForgotPasswordPage> {
|
|||||||
body: BlocListener<AuthBloc, AuthState>(
|
body: BlocListener<AuthBloc, AuthState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (state is AuthPasswordResetSent) {
|
if (state is AuthPasswordResetSent) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ErrorService().showSnackbar(
|
||||||
SnackBar(
|
message: 'Email de réinitialisation envoyé !',
|
||||||
content: Text('Email de réinitialisation envoyé !'),
|
isError: false,
|
||||||
backgroundColor: Colors.green,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
} else if (state is AuthError) {
|
} else if (state is AuthError) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ErrorService().showError(message: state.message);
|
||||||
SnackBar(
|
|
||||||
content: Text(state.message),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
|
|||||||
@@ -117,9 +117,7 @@ class _SignUpPageState extends State<SignUpPage> {
|
|||||||
);
|
);
|
||||||
Navigator.pushReplacementNamed(context, '/home');
|
Navigator.pushReplacementNamed(context, '/home');
|
||||||
} else if (state is AuthError) {
|
} else if (state is AuthError) {
|
||||||
_errorService.showError(
|
_errorService.showError(message: state.message);
|
||||||
message: 'Erreur lors de la création du compte',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
|
|||||||
@@ -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) {
|
||||||
@@ -201,19 +242,32 @@ class AccountRepository {
|
|||||||
|
|
||||||
Future<void> addMemberToAccount(String accountId, GroupMember member) async {
|
Future<void> addMemberToAccount(String accountId, GroupMember member) async {
|
||||||
try {
|
try {
|
||||||
await _membersCollection(accountId).doc(member.userId).set(member.toMap());
|
await _membersCollection(
|
||||||
} catch (e) {
|
accountId,
|
||||||
_errorService.logError('account_repository.dart', 'Erreur lors de l\'ajout du membre: $e');
|
).doc(member.userId).set(member.toMap());
|
||||||
throw Exception('Erreur lors de l\'ajout du membre: $e');
|
} 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 {
|
Future<void> removeMemberFromAccount(
|
||||||
|
String accountId,
|
||||||
|
String memberId,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
await _membersCollection(accountId).doc(memberId).delete();
|
await _membersCollection(accountId).doc(memberId).delete();
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
_errorService.logError('account_repository.dart', 'Erreur lors de la suppression du membre: $e');
|
_errorService.logError(
|
||||||
throw Exception('Erreur lors de la suppression du membre: $e');
|
'account_repository.dart',
|
||||||
|
'Erreur lors de la suppression du membre: $e',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
|
throw Exception('Impossible de supprimer le membre');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,10 +60,10 @@ class AuthRepository {
|
|||||||
);
|
);
|
||||||
await _saveFCMToken(firebaseUser.user!.uid);
|
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.
|
||||||
@@ -108,10 +108,10 @@ class AuthRepository {
|
|||||||
await _saveFCMToken(user.id!);
|
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.
|
||||||
@@ -160,10 +160,14 @@ class AuthRepository {
|
|||||||
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 {
|
||||||
@@ -178,10 +182,14 @@ class AuthRepository {
|
|||||||
} 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.
|
||||||
@@ -228,10 +236,14 @@ class AuthRepository {
|
|||||||
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 {
|
||||||
@@ -246,10 +258,14 @@ class AuthRepository {
|
|||||||
} 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.
|
||||||
@@ -298,9 +314,13 @@ class AuthRepository {
|
|||||||
'fcmToken': token,
|
'fcmToken': token,
|
||||||
}, SetOptions(merge: true));
|
}, SetOptions(merge: true));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
// Non-blocking error
|
// Non-blocking error
|
||||||
print('Error saving FCM token: $e');
|
_errorService.logError(
|
||||||
|
'AuthRepository',
|
||||||
|
'Error saving FCM token: $e',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -35,8 +35,13 @@ 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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +56,11 @@ class GroupRepository {
|
|||||||
}).toList();
|
}).toList();
|
||||||
})
|
})
|
||||||
.handleError((error, stackTrace) {
|
.handleError((error, stackTrace) {
|
||||||
_errorService.logError(error, stackTrace);
|
_errorService.logError(
|
||||||
|
'GroupRepository',
|
||||||
|
'Erreur stream groups: $error',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
return <Group>[];
|
return <Group>[];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -66,8 +75,13 @@ 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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,8 +118,13 @@ 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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,10 +141,11 @@ class GroupRepository {
|
|||||||
'Migration réussie pour le groupe $groupId',
|
'Migration réussie pour le groupe $groupId',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
_errorService.logError(
|
_errorService.logError(
|
||||||
'GroupRepository',
|
'GroupRepository',
|
||||||
'Erreur de migration pour le groupe $groupId: $e',
|
'Erreur de migration pour le groupe $groupId: $e',
|
||||||
|
stackTrace,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,8 +156,13 @@ class GroupRepository {
|
|||||||
return snapshot.docs.map((doc) {
|
return snapshot.docs.map((doc) {
|
||||||
return GroupMember.fromMap(doc.data() as Map<String, dynamic>, doc.id);
|
return GroupMember.fromMap(doc.data() as Map<String, dynamic>, doc.id);
|
||||||
}).toList();
|
}).toList();
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
throw Exception('Erreur lors de la récupération des membres: $e');
|
_errorService.logError(
|
||||||
|
'GroupRepository',
|
||||||
|
'Erreur get members: $e',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
|
throw Exception('Impossible de récupérer les membres');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,8 +185,13 @@ class GroupRepository {
|
|||||||
await _firestore.collection('trips').doc(group.tripId).update({
|
await _firestore.collection('trips').doc(group.tripId).update({
|
||||||
'participants': FieldValue.arrayUnion([member.userId]),
|
'participants': FieldValue.arrayUnion([member.userId]),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
throw Exception('Erreur lors de l\'ajout du membre: $e');
|
_errorService.logError(
|
||||||
|
'GroupRepository',
|
||||||
|
'Erreur add member: $e',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
|
throw Exception('Impossible d\'ajouter le membre');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,8 +214,13 @@ class GroupRepository {
|
|||||||
await _firestore.collection('trips').doc(group.tripId).update({
|
await _firestore.collection('trips').doc(group.tripId).update({
|
||||||
'participants': FieldValue.arrayRemove([userId]),
|
'participants': FieldValue.arrayRemove([userId]),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
throw Exception('Erreur lors de la suppression du membre: $e');
|
_errorService.logError(
|
||||||
|
'GroupRepository',
|
||||||
|
'Erreur remove member: $e',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
|
throw Exception('Impossible de supprimer le membre');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,8 +232,13 @@ class GroupRepository {
|
|||||||
group.toMap()
|
group.toMap()
|
||||||
..['updatedAt'] = DateTime.now().millisecondsSinceEpoch,
|
..['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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,8 +266,13 @@ class GroupRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await _groupsCollection.doc(groupId).delete();
|
await _groupsCollection.doc(groupId).delete();
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
throw Exception('Erreur lors de la suppression du groupe: $e');
|
_errorService.logError(
|
||||||
|
'GroupRepository',
|
||||||
|
'Erreur delete group: $e',
|
||||||
|
stackTrace,
|
||||||
|
);
|
||||||
|
throw Exception('Impossible de supprimer le groupe');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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 [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ class ActivityPlacesService {
|
|||||||
|
|
||||||
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';
|
||||||
|
|
||||||
LoggerService.info('ActivityPlacesService: Géocodage de "$destination"');
|
LoggerService.info('ActivityPlacesService: Géocodage de "$destination"');
|
||||||
LoggerService.info('ActivityPlacesService: URL = $url');
|
LoggerService.info('ActivityPlacesService: URL = $url');
|
||||||
@@ -184,7 +184,8 @@ class ActivityPlacesService {
|
|||||||
'?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));
|
||||||
|
|
||||||
@@ -287,7 +288,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));
|
||||||
|
|
||||||
@@ -356,7 +358,8 @@ class ActivityPlacesService {
|
|||||||
'?query=$encodedQuery in $destination'
|
'?query=$encodedQuery in $destination'
|
||||||
'&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));
|
||||||
|
|
||||||
@@ -513,7 +516,8 @@ class ActivityPlacesService {
|
|||||||
'?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';
|
||||||
@@ -589,7 +593,8 @@ class ActivityPlacesService {
|
|||||||
'?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';
|
||||||
|
|||||||
@@ -171,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,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")
|
||||||
@@ -247,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',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
lib/services/map_navigation_service.dart
Normal file
36
lib/services/map_navigation_service.dart
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,22 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
import 'package:flutter_local_notifications/flutter_local_notifications.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: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 {
|
class NotificationService {
|
||||||
static final NotificationService _instance = NotificationService._internal();
|
static final NotificationService _instance = NotificationService._internal();
|
||||||
@@ -34,14 +50,123 @@ class NotificationService {
|
|||||||
onDidReceiveNotificationResponse: (details) {
|
onDidReceiveNotificationResponse: (details) {
|
||||||
// Handle notification tap
|
// Handle notification tap
|
||||||
LoggerService.info('Notification tapped: ${details.payload}');
|
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
|
// Handle foreground messages
|
||||||
FirebaseMessaging.onMessage.listen(_handleForegroundMessage);
|
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;
|
_isInitialized = true;
|
||||||
LoggerService.info('NotificationService initialized');
|
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 {
|
Future<void> _requestPermissions() async {
|
||||||
@@ -58,13 +183,46 @@ class NotificationService {
|
|||||||
|
|
||||||
Future<String?> getFCMToken() async {
|
Future<String?> getFCMToken() async {
|
||||||
try {
|
try {
|
||||||
return await _firebaseMessaging.getToken();
|
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) {
|
} catch (e) {
|
||||||
LoggerService.error('Error getting FCM token: $e');
|
LoggerService.error('Error getting FCM token: $e');
|
||||||
return null;
|
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 {
|
Future<void> _handleForegroundMessage(RemoteMessage message) async {
|
||||||
LoggerService.info('Got a message whilst in the foreground!');
|
LoggerService.info('Got a message whilst in the foreground!');
|
||||||
LoggerService.info('Message data: ${message.data}');
|
LoggerService.info('Message data: ${message.data}');
|
||||||
|
|||||||
Reference in New Issue
Block a user