feat: Implement activity management feature with Firestore integration

- Added AddActivityBottomSheet for adding custom activities to trips.
- Created Activity model to represent tourist activities.
- Developed ActivityRepository for managing activities in Firestore.
- Integrated ActivityPlacesService for searching activities via Google Places API.
- Updated ShowTripDetailsContent to navigate to activities page.
- Enhanced main.dart to include ActivityBloc and necessary repositories.
This commit is contained in:
Dayron
2025-11-03 16:40:33 +01:00
parent 64fcc88984
commit 8ff9e12fd4
11 changed files with 3185 additions and 1 deletions

View File

@@ -0,0 +1,742 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../blocs/activity/activity_bloc.dart';
import '../../blocs/activity/activity_event.dart';
import '../../blocs/activity/activity_state.dart';
import '../../blocs/user/user_bloc.dart';
import '../../blocs/user/user_state.dart' as user_state;
import '../../models/activity.dart';
import '../../models/trip.dart';
import '../../services/error_service.dart';
import 'activity_card.dart';
import 'add_activity_bottom_sheet.dart';
/// Page principale des activités pour un voyage
class ActivitiesPage extends StatefulWidget {
final Trip trip;
const ActivitiesPage({
Key? key,
required this.trip,
}) : super(key: key);
@override
State<ActivitiesPage> createState() => _ActivitiesPageState();
}
class _ActivitiesPageState extends State<ActivitiesPage>
with TickerProviderStateMixin {
late TabController _tabController;
final ErrorService _errorService = ErrorService();
String? _selectedCategory;
final TextEditingController _searchController = TextEditingController();
@override
void initState() {
super.initState();
_tabController = TabController(length: 2, vsync: this);
// Charger les activités
if (widget.trip.id != null) {
context.read<ActivityBloc>().add(LoadActivities(widget.trip.id!));
}
}
@override
void dispose() {
_tabController.dispose();
_searchController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final isDarkMode = theme.brightness == Brightness.dark;
return Scaffold(
backgroundColor: theme.scaffoldBackgroundColor,
body: BlocListener<ActivityBloc, ActivityState>(
listener: (context, state) {
if (state is ActivityOperationSuccess) {
_errorService.showSnackbar(message: state.message, isError: false);
} else if (state is ActivityError) {
_errorService.showSnackbar(message: state.message, isError: true);
}
},
child: CustomScrollView(
slivers: [
// AppBar personnalisée
SliverAppBar(
expandedHeight: 120,
floating: false,
pinned: true,
backgroundColor: Colors.transparent,
elevation: 0,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: theme.colorScheme.onSurface),
onPressed: () => Navigator.pop(context),
),
actions: [
IconButton(
icon: Icon(Icons.person_add, color: theme.colorScheme.onSurface),
onPressed: () {
// TODO: Ajouter participants
},
),
],
flexibleSpace: FlexibleSpaceBar(
titlePadding: const EdgeInsets.only(left: 16, bottom: 16),
title: Text(
'Voyage à ${widget.trip.location}',
style: theme.textTheme.titleLarge?.copyWith(
color: theme.colorScheme.onSurface,
fontWeight: FontWeight.w600,
),
),
),
),
// Barre de recherche
SliverToBoxAdapter(
child: Container(
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: theme.cardColor,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: isDarkMode
? Colors.white.withOpacity(0.1)
: Colors.black.withOpacity(0.1),
),
),
child: Row(
children: [
Icon(
Icons.search,
color: theme.colorScheme.onSurface.withOpacity(0.5),
),
const SizedBox(width: 12),
Expanded(
child: TextField(
controller: _searchController,
decoration: InputDecoration(
hintText: 'Rechercher restaurants, musées...',
border: InputBorder.none,
hintStyle: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.5),
),
),
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface,
),
onSubmitted: (query) {
if (query.isNotEmpty) {
context.read<ActivityBloc>().add(
SearchActivitiesByText(
tripId: widget.trip.id!,
destination: widget.trip.location,
query: query,
),
);
}
},
),
),
],
),
),
),
// Filtres par catégorie
SliverToBoxAdapter(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Bouton suggestions Google
const SizedBox(height: 8),
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: _searchGoogleActivities,
icon: const Icon(Icons.place),
label: const Text('Découvrir des activités avec Google'),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
),
const SizedBox(height: 16),
// Catégories populaires
Text(
'Catégories populaires',
style: Theme.of(context).textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 8),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
_buildCategoryButton(ActivityCategory.attraction, 'Attractions'),
const SizedBox(width: 8),
_buildCategoryButton(ActivityCategory.restaurant, 'Restaurants'),
const SizedBox(width: 8),
_buildCategoryButton(ActivityCategory.museum, 'Musées'),
const SizedBox(width: 8),
_buildCategoryButton(ActivityCategory.nature, 'Nature'),
const SizedBox(width: 8),
_buildCategoryButton(ActivityCategory.culture, 'Culture'),
],
),
),
const SizedBox(height: 16),
// Filtres
Row(
children: [
_buildFilterChip(
label: 'Catégorie',
icon: Icons.filter_list,
isActive: _selectedCategory != null,
onTap: _showCategoryFilter,
),
const SizedBox(width: 8),
_buildFilterChip(
label: 'Prix',
icon: Icons.euro,
isActive: false,
onTap: _showPriceFilter,
),
const SizedBox(width: 8),
_buildFilterChip(
label: 'Heure',
icon: Icons.access_time,
isActive: false,
onTap: () {
// TODO: Filtre par heure
},
),
],
),
],
),
),
),
// Onglets
SliverToBoxAdapter(
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
decoration: BoxDecoration(
color: theme.cardColor,
borderRadius: BorderRadius.circular(8),
),
child: TabBar(
controller: _tabController,
indicator: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(8),
),
labelColor: Colors.white,
unselectedLabelColor: theme.colorScheme.onSurface.withOpacity(0.7),
dividerColor: Colors.transparent,
tabs: const [
Tab(text: 'Suggestions'),
Tab(text: 'Activités votées'),
],
),
),
),
// Contenu des onglets
SliverFillRemaining(
child: TabBarView(
controller: _tabController,
children: [
_buildSuggestionsTab(),
_buildVotedActivitiesTab(),
],
),
),
],
),
),
// Bouton flottant pour ajouter une activité
floatingActionButton: FloatingActionButton(
onPressed: () => _showAddActivitySheet(),
backgroundColor: Colors.blue,
child: const Icon(Icons.add, color: Colors.white),
),
);
}
Widget _buildFilterChip({
required String label,
required IconData icon,
required bool isActive,
required VoidCallback onTap,
}) {
final theme = Theme.of(context);
return GestureDetector(
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: isActive ? Colors.blue : theme.cardColor,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: isActive
? Colors.blue
: theme.colorScheme.onSurface.withOpacity(0.2),
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
icon,
size: 16,
color: isActive
? Colors.white
: theme.colorScheme.onSurface.withOpacity(0.7),
),
const SizedBox(width: 4),
Text(
label,
style: theme.textTheme.bodySmall?.copyWith(
color: isActive
? Colors.white
: theme.colorScheme.onSurface.withOpacity(0.7),
fontWeight: FontWeight.w500,
),
),
],
),
),
);
}
Widget _buildSuggestionsTab() {
return BlocBuilder<ActivityBloc, ActivityState>(
builder: (context, state) {
if (state is ActivityLoading || state is ActivitySearching) {
return const Center(child: CircularProgressIndicator());
}
if (state is ActivitySearchResults) {
return _buildActivityList(state.searchResults, isSearchResults: true);
}
if (state is ActivityLoaded) {
return _buildActivityList(state.filteredActivities);
}
// État initial - montrer les suggestions par défaut
return _buildInitialSuggestions();
},
);
}
Widget _buildVotedActivitiesTab() {
return BlocBuilder<ActivityBloc, ActivityState>(
builder: (context, state) {
if (state is ActivityLoading) {
return const Center(child: CircularProgressIndicator());
}
if (state is ActivityLoaded) {
// Filtrer les activités avec des votes
final votedActivities = state.activities
.where((activity) => activity.votes.isNotEmpty)
.toList();
// Trier par score de vote
votedActivities.sort((a, b) => b.totalVotes.compareTo(a.totalVotes));
return _buildActivityList(votedActivities);
}
return const Center(
child: Text('Aucune activité votée pour le moment'),
);
},
);
}
Widget _buildActivityList(List<Activity> activities, {bool isSearchResults = false}) {
if (activities.isEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.explore_off,
size: 64,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.3),
),
const SizedBox(height: 16),
Text(
isSearchResults
? 'Aucun résultat trouvé'
: 'Aucune activité pour le moment',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.5),
),
),
const SizedBox(height: 8),
Text(
isSearchResults
? 'Essayez une autre recherche ou explorez les catégories'
: 'Utilisez le bouton "Découvrir des activités avec Google" pour commencer',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.5),
),
textAlign: TextAlign.center,
),
if (isSearchResults) ...[
const SizedBox(height: 16),
ElevatedButton.icon(
onPressed: () {
context.read<ActivityBloc>().add(LoadActivities(widget.trip.id!));
},
icon: const Icon(Icons.arrow_back),
label: const Text('Retour aux suggestions'),
),
] else ...[
const SizedBox(height: 16),
ElevatedButton.icon(
onPressed: _searchGoogleActivities,
icon: const Icon(Icons.place),
label: const Text('Découvrir des activités'),
),
],
],
),
);
}
return BlocBuilder<UserBloc, user_state.UserState>(
builder: (context, userState) {
final currentUserId = userState is user_state.UserLoaded
? userState.user.id
: '';
return ListView.builder(
padding: const EdgeInsets.all(16),
itemCount: activities.length,
itemBuilder: (context, index) {
final activity = activities[index];
return Padding(
padding: const EdgeInsets.only(bottom: 16),
child: ActivityCard(
activity: activity,
currentUserId: currentUserId,
onVote: (vote) => _handleVote(activity.id, currentUserId, vote),
onAddToTrip: isSearchResults
? () => _addActivityToTrip(activity)
: null,
),
);
},
);
},
);
}
Widget _buildInitialSuggestions() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.explore,
size: 64,
color: Theme.of(context).colorScheme.primary,
),
const SizedBox(height: 16),
Text(
'Découvrez ${widget.trip.location}',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Text(
'Utilisez le bouton "Découvrir des activités avec Google" ci-dessus\npour explorer les meilleures attractions de la région',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primaryContainer.withOpacity(0.3),
borderRadius: BorderRadius.circular(12),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.lightbulb_outline,
color: Theme.of(context).colorScheme.primary,
),
const SizedBox(width: 8),
Text(
'Conseil : Explorez par catégorie ci-dessous',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.primary,
),
),
],
),
),
const SizedBox(height: 16),
Wrap(
spacing: 8,
runSpacing: 8,
children: ActivityCategory.values.take(6).map((category) {
return ElevatedButton.icon(
onPressed: () => _searchByCategory(category),
icon: Icon(_getCategoryIcon(category), size: 18),
label: Text(category.displayName),
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).cardColor,
foregroundColor: Theme.of(context).colorScheme.onSurface,
elevation: 2,
),
);
}).toList(),
),
],
),
);
}
void _searchByCategory(ActivityCategory category) {
context.read<ActivityBloc>().add(
SearchActivities(
tripId: widget.trip.id!,
destination: widget.trip.location,
category: category,
),
);
}
void _handleVote(String activityId, String userId, int vote) {
if (userId.isEmpty) {
_errorService.showSnackbar(
message: 'Vous devez être connecté pour voter',
isError: true,
);
return;
}
context.read<ActivityBloc>().add(
VoteForActivity(
activityId: activityId,
userId: userId,
vote: vote,
),
);
}
void _addActivityToTrip(Activity activity) {
context.read<ActivityBloc>().add(AddActivity(activity));
}
void _searchGoogleActivities() {
// Rechercher toutes les catégories d'activités
context.read<ActivityBloc>().add(
SearchActivities(
tripId: widget.trip.id!,
destination: widget.trip.location,
category: null, // Null pour rechercher toutes les catégories
),
);
}
Widget _buildCategoryButton(ActivityCategory category, String label) {
return ElevatedButton.icon(
onPressed: () => _searchByCategory(category),
icon: Icon(_getCategoryIcon(category), size: 18),
label: Text(label),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
);
}
void _showAddActivitySheet() {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (context) => AddActivityBottomSheet(
trip: widget.trip,
),
);
}
void _showCategoryFilter() {
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) => _buildCategoryFilterSheet(),
);
}
void _showPriceFilter() {
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) => _buildPriceFilterSheet(),
);
}
Widget _buildCategoryFilterSheet() {
final theme = Theme.of(context);
return Container(
margin: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: theme.cardColor,
borderRadius: BorderRadius.circular(16),
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 40,
height: 4,
margin: const EdgeInsets.symmetric(vertical: 8),
decoration: BoxDecoration(
color: theme.colorScheme.onSurface.withOpacity(0.3),
borderRadius: BorderRadius.circular(2),
),
),
Padding(
padding: const EdgeInsets.all(16),
child: Text(
'Filtrer par catégorie',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
...ActivityCategory.values.map((category) {
final isSelected = _selectedCategory == category.displayName;
return ListTile(
leading: Icon(_getCategoryIcon(category)),
title: Text(category.displayName),
trailing: isSelected ? const Icon(Icons.check, color: Colors.blue) : null,
onTap: () {
setState(() {
_selectedCategory = isSelected ? null : category.displayName;
});
context.read<ActivityBloc>().add(
FilterActivities(category: _selectedCategory),
);
Navigator.pop(context);
},
);
}).toList(),
const SizedBox(height: 16),
],
),
),
);
}
Widget _buildPriceFilterSheet() {
final theme = Theme.of(context);
return Container(
margin: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: theme.cardColor,
borderRadius: BorderRadius.circular(16),
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 40,
height: 4,
margin: const EdgeInsets.symmetric(vertical: 8),
decoration: BoxDecoration(
color: theme.colorScheme.onSurface.withOpacity(0.3),
borderRadius: BorderRadius.circular(2),
),
),
Padding(
padding: const EdgeInsets.all(16),
child: Text(
'Filtrer par prix',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
...PriceLevel.values.map((priceLevel) {
return ListTile(
leading: Icon(Icons.euro),
title: Text(priceLevel.displayName),
onTap: () {
// TODO: Implémenter le filtre par prix
Navigator.pop(context);
},
);
}).toList(),
const SizedBox(height: 16),
],
),
),
);
}
IconData _getCategoryIcon(ActivityCategory category) {
switch (category) {
case ActivityCategory.museum:
return Icons.museum;
case ActivityCategory.restaurant:
return Icons.restaurant;
case ActivityCategory.attraction:
return Icons.place;
case ActivityCategory.entertainment:
return Icons.sports_esports;
case ActivityCategory.shopping:
return Icons.shopping_bag;
case ActivityCategory.nature:
return Icons.nature;
case ActivityCategory.culture:
return Icons.palette;
case ActivityCategory.nightlife:
return Icons.nightlife;
case ActivityCategory.sports:
return Icons.sports;
case ActivityCategory.relaxation:
return Icons.spa;
}
}
}

View File

@@ -0,0 +1,374 @@
import 'package:flutter/material.dart';
import '../../models/activity.dart';
/// Widget représentant une carte d'activité avec système de vote
class ActivityCard extends StatelessWidget {
final Activity activity;
final String currentUserId;
final Function(int) onVote;
final VoidCallback? onAddToTrip;
const ActivityCard({
Key? key,
required this.activity,
required this.currentUserId,
required this.onVote,
this.onAddToTrip,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final isDarkMode = theme.brightness == Brightness.dark;
final userVote = activity.getUserVote(currentUserId);
return Container(
decoration: BoxDecoration(
color: theme.cardColor,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(isDarkMode ? 0.3 : 0.1),
blurRadius: 10,
offset: const Offset(0, 5),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Image de l'activité
if (activity.imageUrl != null) ...[
ClipRRect(
borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
child: Stack(
children: [
Image.network(
activity.imageUrl!,
height: 200,
width: double.infinity,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return Container(
height: 200,
width: double.infinity,
decoration: BoxDecoration(
color: theme.colorScheme.surfaceVariant,
borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
),
child: Icon(
Icons.image_not_supported,
size: 48,
color: theme.colorScheme.onSurfaceVariant,
),
);
},
),
// Badge catégorie
if (activity.category.isNotEmpty)
Positioned(
top: 12,
right: 12,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: _getCategoryColor(activity.category),
borderRadius: BorderRadius.circular(12),
),
child: Text(
activity.category,
style: theme.textTheme.bodySmall?.copyWith(
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
),
),
],
),
),
],
// Contenu de la carte
Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Titre et rating
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Text(
activity.name,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.onSurface,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
if (activity.rating != null) ...[
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: Colors.amber.withOpacity(0.2),
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.star, size: 14, color: Colors.amber),
const SizedBox(width: 2),
Text(
activity.rating!.toStringAsFixed(1),
style: theme.textTheme.bodySmall?.copyWith(
fontWeight: FontWeight.w500,
color: Colors.amber[800],
),
),
],
),
),
],
],
),
const SizedBox(height: 8),
// Description
Text(
activity.description,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.7),
),
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 12),
// Informations supplémentaires
if (activity.priceLevel != null || activity.address != null) ...[
Row(
children: [
if (activity.priceLevel != null) ...[
Icon(
Icons.euro,
size: 16,
color: theme.colorScheme.onSurface.withOpacity(0.5),
),
const SizedBox(width: 4),
Text(
activity.priceLevel!,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.7),
),
),
if (activity.address != null) ...[
const SizedBox(width: 16),
Icon(
Icons.location_on,
size: 16,
color: theme.colorScheme.onSurface.withOpacity(0.5),
),
const SizedBox(width: 4),
Expanded(
child: Text(
activity.address!,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.7),
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
] else if (activity.address != null) ...[
Icon(
Icons.location_on,
size: 16,
color: theme.colorScheme.onSurface.withOpacity(0.5),
),
const SizedBox(width: 4),
Expanded(
child: Text(
activity.address!,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.7),
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
],
),
const SizedBox(height: 12),
],
// Section vote et actions
Row(
children: [
// Boutons de vote
Container(
decoration: BoxDecoration(
color: theme.colorScheme.surfaceVariant.withOpacity(0.5),
borderRadius: BorderRadius.circular(20),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
// Vote positif
_buildVoteButton(
icon: Icons.thumb_up,
count: activity.positiveVotes,
isActive: userVote == 1,
onTap: () => onVote(userVote == 1 ? 0 : 1),
activeColor: Colors.blue,
),
Container(
width: 1,
height: 24,
color: theme.colorScheme.onSurface.withOpacity(0.2),
),
// Vote négatif
_buildVoteButton(
icon: Icons.thumb_down,
count: activity.negativeVotes,
isActive: userVote == -1,
onTap: () => onVote(userVote == -1 ? 0 : -1),
activeColor: Colors.red,
),
],
),
),
const Spacer(),
// Bouton d'action
if (onAddToTrip != null)
ElevatedButton(
onPressed: onAddToTrip,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
child: const Text('Voter'),
)
else
// Score total
Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: _getScoreColor(activity.totalVotes).withOpacity(0.2),
borderRadius: BorderRadius.circular(12),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'${activity.totalVotes > 0 ? '+' : ''}${activity.totalVotes}',
style: theme.textTheme.bodySmall?.copyWith(
fontWeight: FontWeight.bold,
color: _getScoreColor(activity.totalVotes),
),
),
const SizedBox(width: 4),
Text(
'vote${activity.votes.length > 1 ? 's' : ''}',
style: theme.textTheme.bodySmall?.copyWith(
color: _getScoreColor(activity.totalVotes),
),
),
],
),
),
],
),
],
),
),
],
),
);
}
Widget _buildVoteButton({
required IconData icon,
required int count,
required bool isActive,
required VoidCallback onTap,
required Color activeColor,
}) {
return GestureDetector(
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
icon,
size: 18,
color: isActive ? activeColor : Colors.grey,
),
if (count > 0) ...[
const SizedBox(width: 4),
Text(
count.toString(),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: isActive ? activeColor : Colors.grey,
),
),
],
],
),
),
);
}
Color _getCategoryColor(String category) {
switch (category.toLowerCase()) {
case 'musée':
return Colors.purple;
case 'restaurant':
return Colors.orange;
case 'attraction':
return Colors.blue;
case 'divertissement':
return Colors.pink;
case 'shopping':
return Colors.green;
case 'nature':
return Colors.teal;
case 'culture':
return Colors.indigo;
case 'vie nocturne':
return Colors.deepPurple;
case 'sports':
return Colors.red;
case 'détente':
return Colors.cyan;
default:
return Colors.grey;
}
}
Color _getScoreColor(int score) {
if (score > 0) return Colors.green;
if (score < 0) return Colors.red;
return Colors.grey;
}
}

View File

@@ -0,0 +1,402 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../blocs/activity/activity_bloc.dart';
import '../../blocs/activity/activity_event.dart';
import '../../models/activity.dart';
import '../../models/trip.dart';
import '../../services/error_service.dart';
/// Bottom sheet pour ajouter une activité personnalisée
class AddActivityBottomSheet extends StatefulWidget {
final Trip trip;
const AddActivityBottomSheet({
Key? key,
required this.trip,
}) : super(key: key);
@override
State<AddActivityBottomSheet> createState() => _AddActivityBottomSheetState();
}
class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
final _formKey = GlobalKey<FormState>();
final _nameController = TextEditingController();
final _descriptionController = TextEditingController();
final _addressController = TextEditingController();
final ErrorService _errorService = ErrorService();
ActivityCategory _selectedCategory = ActivityCategory.attraction;
bool _isLoading = false;
@override
void dispose() {
_nameController.dispose();
_descriptionController.dispose();
_addressController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final mediaQuery = MediaQuery.of(context);
return Container(
height: mediaQuery.size.height * 0.85,
margin: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: theme.cardColor,
borderRadius: BorderRadius.circular(20),
),
child: Column(
children: [
// Handle bar
Container(
width: 40,
height: 4,
margin: const EdgeInsets.symmetric(vertical: 12),
decoration: BoxDecoration(
color: theme.colorScheme.onSurface.withOpacity(0.3),
borderRadius: BorderRadius.circular(2),
),
),
// Header
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
children: [
Text(
'Ajouter une activité',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
const Spacer(),
IconButton(
onPressed: () => Navigator.pop(context),
icon: const Icon(Icons.close),
),
],
),
),
const Divider(),
// Formulaire
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.all(20),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Nom de l'activité
_buildSectionTitle('Nom de l\'activité'),
const SizedBox(height: 8),
_buildTextField(
controller: _nameController,
hintText: 'Ex: Visite du Louvre',
icon: Icons.event,
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Nom requis';
}
return null;
},
),
const SizedBox(height: 20),
// Description
_buildSectionTitle('Description'),
const SizedBox(height: 8),
_buildTextField(
controller: _descriptionController,
hintText: 'Décrivez cette activité...',
icon: Icons.description,
maxLines: 3,
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Description requise';
}
return null;
},
),
const SizedBox(height: 20),
// Catégorie
_buildSectionTitle('Catégorie'),
const SizedBox(height: 8),
_buildCategorySelector(),
const SizedBox(height: 20),
// Adresse (optionnel)
_buildSectionTitle('Adresse (optionnel)'),
const SizedBox(height: 8),
_buildTextField(
controller: _addressController,
hintText: 'Adresse ou lieu',
icon: Icons.location_on,
),
const SizedBox(height: 40),
// Boutons d'action
Row(
children: [
Expanded(
child: OutlinedButton(
onPressed: () => Navigator.pop(context),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 16),
side: BorderSide(color: theme.colorScheme.outline),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text('Annuler'),
),
),
const SizedBox(width: 16),
Expanded(
child: ElevatedButton(
onPressed: _isLoading ? null : _addActivity,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: _isLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: const Text('Ajouter'),
),
),
],
),
],
),
),
),
),
],
),
);
}
Widget _buildSectionTitle(String title) {
return Text(
title,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
),
);
}
Widget _buildTextField({
required TextEditingController controller,
required String hintText,
required IconData icon,
int maxLines = 1,
String? Function(String?)? validator,
}) {
final theme = Theme.of(context);
final isDarkMode = theme.brightness == Brightness.dark;
return TextFormField(
controller: controller,
maxLines: maxLines,
validator: validator,
decoration: InputDecoration(
hintText: hintText,
prefixIcon: Icon(icon),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: isDarkMode
? Colors.white.withOpacity(0.2)
: Colors.black.withOpacity(0.2),
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: isDarkMode
? Colors.white.withOpacity(0.2)
: Colors.black.withOpacity(0.2),
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: Colors.blue, width: 2),
),
filled: true,
fillColor: theme.colorScheme.surface,
),
);
}
Widget _buildCategorySelector() {
final theme = Theme.of(context);
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: theme.colorScheme.outline.withOpacity(0.5),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Sélectionnez une catégorie',
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.7),
),
),
const SizedBox(height: 12),
Wrap(
spacing: 8,
runSpacing: 8,
children: ActivityCategory.values.map((category) {
final isSelected = _selectedCategory == category;
return GestureDetector(
onTap: () {
setState(() {
_selectedCategory = category;
});
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: isSelected ? Colors.blue : Colors.transparent,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: isSelected ? Colors.blue : theme.colorScheme.outline,
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
_getCategoryIcon(category),
size: 16,
color: isSelected
? Colors.white
: theme.colorScheme.onSurface,
),
const SizedBox(width: 6),
Text(
category.displayName,
style: theme.textTheme.bodySmall?.copyWith(
color: isSelected
? Colors.white
: theme.colorScheme.onSurface,
fontWeight: FontWeight.w500,
),
),
],
),
),
);
}).toList(),
),
],
),
);
}
void _addActivity() async {
if (!_formKey.currentState!.validate()) {
return;
}
if (widget.trip.id == null) {
_errorService.showSnackbar(
message: 'Erreur: ID du voyage manquant',
isError: true,
);
return;
}
setState(() {
_isLoading = true;
});
try {
final activity = Activity(
id: '', // Sera généré par Firestore
tripId: widget.trip.id!,
name: _nameController.text.trim(),
description: _descriptionController.text.trim(),
category: _selectedCategory.displayName,
address: _addressController.text.trim().isNotEmpty
? _addressController.text.trim()
: null,
votes: {},
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
);
context.read<ActivityBloc>().add(AddActivity(activity));
// Fermer le bottom sheet
Navigator.pop(context);
} catch (e) {
_errorService.showSnackbar(
message: 'Erreur lors de l\'ajout de l\'activité',
isError: true,
);
} finally {
if (mounted) {
setState(() {
_isLoading = false;
});
}
}
}
IconData _getCategoryIcon(ActivityCategory category) {
switch (category) {
case ActivityCategory.museum:
return Icons.museum;
case ActivityCategory.restaurant:
return Icons.restaurant;
case ActivityCategory.attraction:
return Icons.place;
case ActivityCategory.entertainment:
return Icons.sports_esports;
case ActivityCategory.shopping:
return Icons.shopping_bag;
case ActivityCategory.nature:
return Icons.nature;
case ActivityCategory.culture:
return Icons.palette;
case ActivityCategory.nightlife:
return Icons.nightlife;
case ActivityCategory.sports:
return Icons.sports;
case ActivityCategory.relaxation:
return Icons.spa;
}
}
}

View File

@@ -6,6 +6,7 @@ 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/components/activities/activities_page.dart';
import 'package:url_launcher/url_launcher.dart';
class ShowTripDetailsContent extends StatefulWidget {
@@ -402,7 +403,7 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
icon: Icons.local_activity,
title: 'Activités',
color: Colors.green,
onTap: () => _showComingSoon('Activités'),
onTap: () => _navigateToActivities(),
),
_buildActionButton(
icon: Icons.account_balance_wallet,
@@ -624,4 +625,13 @@ class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
),
);
}
void _navigateToActivities() {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ActivitiesPage(trip: widget.trip),
),
);
}
}