feat: Add map navigation, enhance FCM deep linking, localize Google Places API, and refine activity display.

This commit is contained in:
Van Leemput Dayron
2025-12-04 11:24:30 +01:00
parent cf4c6447dd
commit e174c1274d
13 changed files with 991 additions and 383 deletions

View File

@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:travel_mate/blocs/trip/trip_bloc.dart';
import 'package:travel_mate/blocs/trip/trip_event.dart';
@@ -9,11 +9,14 @@ import 'package:travel_mate/components/home/create_trip_content.dart';
import 'package:travel_mate/models/trip.dart';
import 'package:travel_mate/components/map/map_content.dart';
import 'package:travel_mate/services/error_service.dart';
import 'package:travel_mate/services/logger_service.dart';
import 'package:travel_mate/repositories/group_repository.dart';
import 'package:travel_mate/repositories/user_repository.dart';
import 'package:travel_mate/repositories/account_repository.dart';
import 'package:travel_mate/models/group_member.dart';
import 'package:travel_mate/components/activities/activities_page.dart';
import 'package:travel_mate/components/activities/activity_detail_dialog.dart';
import 'package:travel_mate/components/home/calendar/calendar_page.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:intl/intl.dart';
@@ -22,7 +25,7 @@ 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/models/settlement.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';
@@ -238,30 +241,38 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
// Méthode pour ouvrir Waze
Future<void> _openWaze() async {
final location = Uri.encodeComponent(widget.trip.location);
try {
// Essayer d'abord l'URL scheme pour l'app mobile
final appUrl = 'waze://?q=$location';
final appUri = Uri.parse(appUrl);
if (await canLaunchUrl(appUri)) {
await launchUrl(appUri);
return;
String wazeUrl;
// Utiliser les coordonnées si disponibles (plus précis)
if (widget.trip.latitude != null && widget.trip.longitude != null) {
final lat = widget.trip.latitude;
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 webUrl = 'https://waze.com/ul?q=$location';
final webUri = Uri.parse(webUrl);
if (await canLaunchUrl(webUri)) {
await launchUrl(webUri, mode: LaunchMode.externalApplication);
return;
}
final uri = Uri.parse(wazeUrl);
_errorService.showError(
message:
'Impossible d\'ouvrir Waze. Vérifiez que l\'application est installée.',
);
if (await canLaunchUrl(uri)) {
await launchUrl(uri, mode: LaunchMode.externalApplication);
} 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) {
LoggerService.error('Error opening Waze', error: e);
_errorService.showError(message: 'Erreur lors de l\'ouverture de Waze');
}
}
@@ -1035,14 +1046,7 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
if (activity.date == null) return const SizedBox.shrink();
return Padding(
padding: const EdgeInsets.only(bottom: 12),
child: _buildActivityCard(
title: activity.name,
date: DateFormat(
'd MMM, HH:mm',
'fr_FR',
).format(activity.date!),
icon: _getCategoryIcon(activity.category),
),
child: _buildActivityCard(activity: activity),
);
}),
],
@@ -1060,70 +1064,79 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
return Icons.place;
}
Widget _buildActivityCard({
required String title,
required String date,
required IconData icon,
}) {
Widget _buildActivityCard({required Activity activity}) {
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,
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,
),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
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: 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),
),
child: Icon(icon, color: Colors.teal, size: 24),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: theme.textTheme.bodyLarge?.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.onSurface,
const SizedBox(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),
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),
),
],
Icon(
Icons.chevron_right,
color: theme.colorScheme.onSurface.withValues(alpha: 0.4),
),
],
),
),
);
}
@@ -1214,13 +1227,7 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
'${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';
'${debtsToReceive.map((s) => '${s.fromUserName} (${s.amount.toStringAsFixed(2)}€)').join(' et ')} vous doivent de l\'argent';
}
}
}