Refactor signup fields and update home page titles; add trip service and model
This commit is contained in:
@@ -0,0 +1,448 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import '../providers/user_provider.dart';
|
||||||
|
|
||||||
|
class CreateTripContent extends StatefulWidget {
|
||||||
|
const CreateTripContent({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<CreateTripContent> createState() => _CreateTripContentState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CreateTripContentState extends State<CreateTripContent> {
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
final _titleController = TextEditingController();
|
||||||
|
final _descriptionController = TextEditingController();
|
||||||
|
final _locationController = TextEditingController();
|
||||||
|
final _budgetController = TextEditingController();
|
||||||
|
|
||||||
|
DateTime? _startDate;
|
||||||
|
DateTime? _endDate;
|
||||||
|
bool _isLoading = false;
|
||||||
|
|
||||||
|
// Liste des participants (emails)
|
||||||
|
final List<String> _participants = [];
|
||||||
|
final _participantController = TextEditingController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_titleController.dispose();
|
||||||
|
_descriptionController.dispose();
|
||||||
|
_locationController.dispose();
|
||||||
|
_budgetController.dispose();
|
||||||
|
_participantController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text('Créer un voyage'),
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: _isLoading ? null : _saveTrip,
|
||||||
|
child: Text(
|
||||||
|
'Sauvegarder',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: SingleChildScrollView(
|
||||||
|
padding: EdgeInsets.all(16),
|
||||||
|
child: Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
// Titre du voyage
|
||||||
|
_buildSectionTitle('Informations générales'),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
|
||||||
|
TextFormField(
|
||||||
|
controller: _titleController,
|
||||||
|
validator: (value) {
|
||||||
|
if (value == null || value.trim().isEmpty) {
|
||||||
|
return 'Titre requis';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Titre du voyage *',
|
||||||
|
hintText: 'ex: Voyage à Paris',
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
prefixIcon: Icon(Icons.travel_explore),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: 16),
|
||||||
|
|
||||||
|
// Description
|
||||||
|
TextFormField(
|
||||||
|
controller: _descriptionController,
|
||||||
|
maxLines: 3,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Description',
|
||||||
|
hintText: 'Décrivez votre voyage...',
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
prefixIcon: Icon(Icons.description),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: 16),
|
||||||
|
|
||||||
|
// Destination
|
||||||
|
TextFormField(
|
||||||
|
controller: _locationController,
|
||||||
|
validator: (value) {
|
||||||
|
if (value == null || value.trim().isEmpty) {
|
||||||
|
return 'Destination requise';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Destination *',
|
||||||
|
hintText: 'ex: Paris, France',
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
prefixIcon: Icon(Icons.location_on),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: 24),
|
||||||
|
|
||||||
|
// Dates
|
||||||
|
_buildSectionTitle('Dates du voyage'),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: _buildDateField(
|
||||||
|
label: 'Date de début *',
|
||||||
|
date: _startDate,
|
||||||
|
onTap: () => _selectStartDate(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 16),
|
||||||
|
Expanded(
|
||||||
|
child: _buildDateField(
|
||||||
|
label: 'Date de fin *',
|
||||||
|
date: _endDate,
|
||||||
|
onTap: () => _selectEndDate(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: 24),
|
||||||
|
|
||||||
|
// Budget
|
||||||
|
_buildSectionTitle('Budget'),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
|
||||||
|
TextFormField(
|
||||||
|
controller: _budgetController,
|
||||||
|
keyboardType: TextInputType.numberWithOptions(decimal: true),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Budget estimé',
|
||||||
|
hintText: 'ex: 1200.50',
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
prefixIcon: Icon(Icons.euro),
|
||||||
|
suffixText: '€',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: 24),
|
||||||
|
|
||||||
|
// Participants
|
||||||
|
_buildSectionTitle('Participants'),
|
||||||
|
SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
'Ajoutez les emails des personnes que vous souhaitez inviter',
|
||||||
|
style: TextStyle(color: Colors.grey[600], fontSize: 14),
|
||||||
|
),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
|
||||||
|
// Champ d'ajout de participant
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: TextFormField(
|
||||||
|
controller: _participantController,
|
||||||
|
keyboardType: TextInputType.emailAddress,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Email du participant',
|
||||||
|
hintText: 'ex: ami@email.com',
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
prefixIcon: Icon(Icons.person_add),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 8),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: _addParticipant,
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
padding: EdgeInsets.all(16),
|
||||||
|
),
|
||||||
|
child: Icon(Icons.add),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: 16),
|
||||||
|
|
||||||
|
// Liste des participants ajoutés
|
||||||
|
if (_participants.isNotEmpty) ...[
|
||||||
|
Text(
|
||||||
|
'Participants ajoutés (${_participants.length})',
|
||||||
|
style: TextStyle(fontWeight: FontWeight.w500),
|
||||||
|
),
|
||||||
|
SizedBox(height: 8),
|
||||||
|
Container(
|
||||||
|
width: double.infinity,
|
||||||
|
padding: EdgeInsets.all(12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(color: Colors.grey[300]!),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 8,
|
||||||
|
children: _participants
|
||||||
|
.map(
|
||||||
|
(email) => Chip(
|
||||||
|
label: Text(email, style: TextStyle(fontSize: 12)),
|
||||||
|
deleteIcon: Icon(Icons.close, size: 18),
|
||||||
|
onDeleted: () => _removeParticipant(email),
|
||||||
|
backgroundColor: Theme.of(
|
||||||
|
context,
|
||||||
|
).colorScheme.primary.withAlpha(25),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
|
||||||
|
SizedBox(height: 32),
|
||||||
|
|
||||||
|
// Bouton de création
|
||||||
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 50,
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: _isLoading ? null : _saveTrip,
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: _isLoading
|
||||||
|
? CircularProgressIndicator(color: Colors.white)
|
||||||
|
: Text(
|
||||||
|
'Créer le voyage',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: 20),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildSectionTitle(String title) {
|
||||||
|
return Text(
|
||||||
|
title,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.grey[700],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildDateField({
|
||||||
|
required String label,
|
||||||
|
required DateTime? date,
|
||||||
|
required VoidCallback onTap,
|
||||||
|
}) {
|
||||||
|
return InkWell(
|
||||||
|
onTap: onTap,
|
||||||
|
child: Container(
|
||||||
|
padding: EdgeInsets.all(16),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(color: Colors.grey[400]!),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
label,
|
||||||
|
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
|
||||||
|
),
|
||||||
|
SizedBox(height: 8),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.calendar_today, size: 16, color: Colors.grey[600]),
|
||||||
|
SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
date != null
|
||||||
|
? '${date.day}/${date.month}/${date.year}'
|
||||||
|
: 'Sélectionner',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
color: date != null ? Colors.black : Colors.grey[500],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _selectStartDate(BuildContext context) async {
|
||||||
|
final DateTime? picked = await showDatePicker(
|
||||||
|
context: context,
|
||||||
|
initialDate: _startDate ?? DateTime.now(),
|
||||||
|
firstDate: DateTime.now(),
|
||||||
|
lastDate: DateTime.now().add(Duration(days: 365 * 2)),
|
||||||
|
);
|
||||||
|
if (picked != null) {
|
||||||
|
setState(() {
|
||||||
|
_startDate = picked;
|
||||||
|
if (_endDate != null && _endDate!.isBefore(picked)) {
|
||||||
|
_endDate = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _selectEndDate(BuildContext context) async {
|
||||||
|
if (_startDate == null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Veuillez d\'abord sélectionner la date de début'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final DateTime? picked = await showDatePicker(
|
||||||
|
context: context,
|
||||||
|
initialDate: _endDate ?? _startDate!.add(Duration(days: 1)),
|
||||||
|
firstDate: _startDate!,
|
||||||
|
lastDate: DateTime.now().add(Duration(days: 365 * 2)),
|
||||||
|
);
|
||||||
|
if (picked != null) {
|
||||||
|
setState(() {
|
||||||
|
_endDate = picked;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _addParticipant() {
|
||||||
|
final email = _participantController.text.trim();
|
||||||
|
if (email.isEmpty) return;
|
||||||
|
|
||||||
|
// Validation email simple
|
||||||
|
final emailRegex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
|
||||||
|
if (!emailRegex.hasMatch(email)) {
|
||||||
|
ScaffoldMessenger.of(
|
||||||
|
context,
|
||||||
|
).showSnackBar(SnackBar(content: Text('Email invalide')));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier si l'email existe déjà
|
||||||
|
if (_participants.contains(email)) {
|
||||||
|
ScaffoldMessenger.of(
|
||||||
|
context,
|
||||||
|
).showSnackBar(SnackBar(content: Text('Ce participant est déjà ajouté')));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_participants.add(email);
|
||||||
|
_participantController.clear();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _removeParticipant(String email) {
|
||||||
|
setState(() {
|
||||||
|
_participants.remove(email);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _saveTrip() async {
|
||||||
|
if (!_formKey.currentState!.validate()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_startDate == null || _endDate == null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('Veuillez sélectionner les dates')),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
// TODO: Implémenter la sauvegarde du voyage
|
||||||
|
await Future.delayed(Duration(seconds: 2)); // Simulation
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Voyage créé avec succès !'),
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Navigator.pop(context);
|
||||||
|
} catch (e) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Erreur lors de la création: $e'),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:travel_mate/components/create_trip_content.dart';
|
||||||
import '../../providers/user_provider.dart';
|
import '../../providers/user_provider.dart';
|
||||||
|
|
||||||
class HomeContent extends StatelessWidget {
|
class HomeContent extends StatelessWidget {
|
||||||
@@ -7,73 +8,83 @@ class HomeContent extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Consumer<UserProvider>(
|
return Scaffold(
|
||||||
builder: (context, userProvider, child) {
|
body: Consumer<UserProvider>(
|
||||||
final user = userProvider.currentUser;
|
builder: (context, userProvider, child) {
|
||||||
|
final user = userProvider.currentUser;
|
||||||
|
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
// Ajout du scroll
|
padding: const EdgeInsets.all(16.0),
|
||||||
padding: const EdgeInsets.all(16.0),
|
child: Column(
|
||||||
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
||||||
children: [
|
// Header de bienvenue
|
||||||
// Header de bienvenue
|
Text(
|
||||||
Text(
|
'Bonjour ${user?.prenom ?? 'Voyageur'} !',
|
||||||
'Bonjour ${user?.prenom ?? 'Voyageur'} !',
|
style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
|
||||||
style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
|
),
|
||||||
),
|
SizedBox(height: 8),
|
||||||
SizedBox(height: 8),
|
Text(
|
||||||
Text(
|
'Vos voyages en cours',
|
||||||
'Vos voyages en cours',
|
style: TextStyle(fontSize: 16, color: Colors.grey[600]),
|
||||||
style: TextStyle(fontSize: 16, color: Colors.grey[600]),
|
),
|
||||||
),
|
SizedBox(height: 20),
|
||||||
SizedBox(height: 20),
|
|
||||||
|
|
||||||
// Liste des groupes/voyages
|
// Liste des groupes/voyages
|
||||||
_buildTravelCard(
|
_buildTravelCard(
|
||||||
context,
|
context,
|
||||||
title: 'Voyage à Paris',
|
title: 'Voyage à Paris',
|
||||||
location: 'Paris, France',
|
location: 'Paris, France',
|
||||||
dates: '15-20 Juin 2024',
|
dates: '15-20 Juin 2024',
|
||||||
participants: ['Alice', 'Bob', 'Charlie'],
|
participants: ['Alice', 'Bob', 'Charlie'],
|
||||||
budget: 1200.50,
|
budget: 1200.50,
|
||||||
imageUrl:
|
imageUrl:
|
||||||
'https://images.unsplash.com/photo-1502602898536-47ad22581b52',
|
'https://images.unsplash.com/photo-1502602898536-47ad22581b52',
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
),
|
),
|
||||||
|
|
||||||
_buildTravelCard(
|
_buildTravelCard(
|
||||||
context,
|
context,
|
||||||
title: 'Road Trip Espagne',
|
title: 'Road Trip Espagne',
|
||||||
location: 'Madrid, Espagne',
|
location: 'Madrid, Espagne',
|
||||||
dates: '10-18 Août 2024',
|
dates: '10-18 Août 2024',
|
||||||
participants: ['Marie', 'Paul', 'Sophie', 'Thomas'],
|
participants: ['Marie', 'Paul', 'Sophie', 'Thomas'],
|
||||||
budget: 850.75,
|
budget: 850.75,
|
||||||
imageUrl:
|
imageUrl:
|
||||||
'https://images.unsplash.com/photo-1539037116277-4db20889f2d4',
|
'https://images.unsplash.com/photo-1539037116277-4db20889f2d4',
|
||||||
color: Colors.orange,
|
color: Colors.orange,
|
||||||
),
|
),
|
||||||
|
|
||||||
_buildTravelCard(
|
_buildTravelCard(
|
||||||
context,
|
context,
|
||||||
title: 'Weekend à Amsterdam',
|
title: 'Weekend à Amsterdam',
|
||||||
location: 'Amsterdam, Pays-Bas',
|
location: 'Amsterdam, Pays-Bas',
|
||||||
dates: '3-5 Septembre 2024',
|
dates: '3-5 Septembre 2024',
|
||||||
participants: ['Emma', 'Lucas'],
|
participants: ['Emma', 'Lucas'],
|
||||||
budget: 450.25,
|
budget: 450.25,
|
||||||
imageUrl:
|
imageUrl:
|
||||||
'https://images.unsplash.com/photo-1534351450181-ea9f78427fe8',
|
'https://images.unsplash.com/photo-1534351450181-ea9f78427fe8',
|
||||||
color: Colors.green,
|
color: Colors.green,
|
||||||
),
|
),
|
||||||
|
|
||||||
SizedBox(height: 20),
|
// Espacement en bas pour éviter que le FAB cache le contenu
|
||||||
|
SizedBox(height: 80),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
// Bouton pour créer un nouveau voyage
|
// FloatingActionButton intégré directement dans HomeContent
|
||||||
_buildCreateTravelCard(context),
|
floatingActionButton: FloatingActionButton(
|
||||||
],
|
onPressed: () {
|
||||||
),
|
_showCreateTravelDialog(context);
|
||||||
);
|
},
|
||||||
},
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
child: Icon(Icons.add),
|
||||||
|
),
|
||||||
|
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,49 +312,6 @@ class HomeContent extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildCreateTravelCard(BuildContext context) {
|
|
||||||
return Card(
|
|
||||||
elevation: 2,
|
|
||||||
margin: EdgeInsets.only(bottom: 16),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
side: BorderSide(
|
|
||||||
color: Colors.grey[300]!,
|
|
||||||
width: 2,
|
|
||||||
style: BorderStyle.solid,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: InkWell(
|
|
||||||
onTap: () {
|
|
||||||
_showCreateTravelDialog(context);
|
|
||||||
},
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
child: Container(
|
|
||||||
padding: EdgeInsets.all(24),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.add_circle_outline, size: 48, color: Colors.grey[400]),
|
|
||||||
SizedBox(height: 12),
|
|
||||||
Text(
|
|
||||||
'Créer un nouveau voyage',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Colors.grey[600],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(height: 4),
|
|
||||||
Text(
|
|
||||||
'Organisez votre prochaine aventure',
|
|
||||||
style: TextStyle(fontSize: 14, color: Colors.grey[500]),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _showTravelDetails(BuildContext context, String title) {
|
void _showTravelDetails(BuildContext context, String title) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
@@ -359,29 +327,9 @@ class HomeContent extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _showCreateTravelDialog(BuildContext context) {
|
void _showCreateTravelDialog(BuildContext context) {
|
||||||
showDialog(
|
Navigator.push(
|
||||||
context: context,
|
context,
|
||||||
builder: (BuildContext context) {
|
MaterialPageRoute(builder: (context) => CreateTripContent()),
|
||||||
return AlertDialog(
|
|
||||||
title: Text('Créer un voyage'),
|
|
||||||
content: Text(
|
|
||||||
'Fonctionnalité à implémenter pour créer un nouveau voyage.',
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
|
||||||
child: Text('Fermer'),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
// TODO: Naviguer vers le formulaire de création
|
|
||||||
},
|
|
||||||
child: Text('Créer'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
181
lib/models/trip.dart
Normal file
181
lib/models/trip.dart
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
class Trip {
|
||||||
|
final String? id;
|
||||||
|
final String title;
|
||||||
|
final String description;
|
||||||
|
final String location;
|
||||||
|
final DateTime startDate;
|
||||||
|
final DateTime endDate;
|
||||||
|
final double? budget;
|
||||||
|
final List<String> participants;
|
||||||
|
final String createdBy; // ID de l'utilisateur créateur
|
||||||
|
final DateTime createdAt;
|
||||||
|
final DateTime updatedAt;
|
||||||
|
final String status; // 'draft', 'active', 'completed', 'cancelled'
|
||||||
|
|
||||||
|
Trip({
|
||||||
|
this.id,
|
||||||
|
required this.title,
|
||||||
|
required this.description,
|
||||||
|
required this.location,
|
||||||
|
required this.startDate,
|
||||||
|
required this.endDate,
|
||||||
|
this.budget,
|
||||||
|
required this.participants,
|
||||||
|
required this.createdBy,
|
||||||
|
required this.createdAt,
|
||||||
|
required this.updatedAt,
|
||||||
|
this.status = 'draft',
|
||||||
|
});
|
||||||
|
|
||||||
|
// Constructeur pour créer un Trip depuis un Map (utile pour Firebase)
|
||||||
|
factory Trip.fromMap(Map<String, dynamic> map) {
|
||||||
|
return Trip(
|
||||||
|
id: map['id'],
|
||||||
|
title: map['title'] ?? '',
|
||||||
|
description: map['description'] ?? '',
|
||||||
|
location: map['location'] ?? '',
|
||||||
|
startDate: DateTime.fromMillisecondsSinceEpoch(map['startDate']),
|
||||||
|
endDate: DateTime.fromMillisecondsSinceEpoch(map['endDate']),
|
||||||
|
budget: map['budget']?.toDouble(),
|
||||||
|
participants: List<String>.from(map['participants'] ?? []),
|
||||||
|
createdBy: map['createdBy'] ?? '',
|
||||||
|
createdAt: DateTime.fromMillisecondsSinceEpoch(map['createdAt']),
|
||||||
|
updatedAt: DateTime.fromMillisecondsSinceEpoch(map['updatedAt']),
|
||||||
|
status: map['status'] ?? 'draft',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructeur pour créer un Trip depuis JSON
|
||||||
|
factory Trip.fromJson(String jsonStr) {
|
||||||
|
Map<String, dynamic> map = json.decode(jsonStr);
|
||||||
|
return Trip.fromMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour convertir un Trip en Map (utile pour Firebase)
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'id': id,
|
||||||
|
'title': title,
|
||||||
|
'description': description,
|
||||||
|
'location': location,
|
||||||
|
'startDate': startDate.millisecondsSinceEpoch,
|
||||||
|
'endDate': endDate.millisecondsSinceEpoch,
|
||||||
|
'budget': budget,
|
||||||
|
'participants': participants,
|
||||||
|
'createdBy': createdBy,
|
||||||
|
'createdAt': createdAt.millisecondsSinceEpoch,
|
||||||
|
'updatedAt': updatedAt.millisecondsSinceEpoch,
|
||||||
|
'status': status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour convertir un Trip en JSON
|
||||||
|
String toJson() {
|
||||||
|
return json.encode(toMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour créer une copie avec des modifications
|
||||||
|
Trip copyWith({
|
||||||
|
String? id,
|
||||||
|
String? title,
|
||||||
|
String? description,
|
||||||
|
String? location,
|
||||||
|
DateTime? startDate,
|
||||||
|
DateTime? endDate,
|
||||||
|
double? budget,
|
||||||
|
List<String>? participants,
|
||||||
|
String? createdBy,
|
||||||
|
DateTime? createdAt,
|
||||||
|
DateTime? updatedAt,
|
||||||
|
String? status,
|
||||||
|
}) {
|
||||||
|
return Trip(
|
||||||
|
id: id ?? this.id,
|
||||||
|
title: title ?? this.title,
|
||||||
|
description: description ?? this.description,
|
||||||
|
location: location ?? this.location,
|
||||||
|
startDate: startDate ?? this.startDate,
|
||||||
|
endDate: endDate ?? this.endDate,
|
||||||
|
budget: budget ?? this.budget,
|
||||||
|
participants: participants ?? this.participants,
|
||||||
|
createdBy: createdBy ?? this.createdBy,
|
||||||
|
createdAt: createdAt ?? this.createdAt,
|
||||||
|
updatedAt: updatedAt ?? this.updatedAt,
|
||||||
|
status: status ?? this.status,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour obtenir la durée du voyage en jours
|
||||||
|
int get durationInDays {
|
||||||
|
return endDate.difference(startDate).inDays + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour vérifier si le voyage est en cours
|
||||||
|
bool get isActive {
|
||||||
|
final now = DateTime.now();
|
||||||
|
return status == 'active' &&
|
||||||
|
now.isAfter(startDate) &&
|
||||||
|
now.isBefore(endDate.add(Duration(days: 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour vérifier si le voyage est à venir
|
||||||
|
bool get isUpcoming {
|
||||||
|
final now = DateTime.now();
|
||||||
|
return status == 'active' && now.isBefore(startDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour vérifier si le voyage est terminé
|
||||||
|
bool get isCompleted {
|
||||||
|
final now = DateTime.now();
|
||||||
|
return status == 'completed' ||
|
||||||
|
(status == 'active' && now.isAfter(endDate));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour obtenir le budget par participant
|
||||||
|
double? get budgetPerParticipant {
|
||||||
|
if (budget == null || participants.isEmpty) return null;
|
||||||
|
return budget! / (participants.length + 1); // +1 pour le créateur
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour obtenir le nombre total de participants (incluant le créateur)
|
||||||
|
int get totalParticipants {
|
||||||
|
return participants.length + 1; // +1 pour le créateur
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour formater les dates
|
||||||
|
String get formattedDates {
|
||||||
|
return '${startDate.day}/${startDate.month}/${startDate.year} - ${endDate.day}/${endDate.month}/${endDate.year}';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour obtenir le statut formaté
|
||||||
|
String get formattedStatus {
|
||||||
|
switch (status) {
|
||||||
|
case 'draft':
|
||||||
|
return 'Brouillon';
|
||||||
|
case 'active':
|
||||||
|
return 'Actif';
|
||||||
|
case 'completed':
|
||||||
|
return 'Terminé';
|
||||||
|
case 'cancelled':
|
||||||
|
return 'Annulé';
|
||||||
|
default:
|
||||||
|
return 'Inconnu';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'Trip(id: $id, title: $title, location: $location, dates: $formattedDates, participants: ${participants.length})';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
return other is Trip && other.id == id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => id.hashCode;
|
||||||
|
}
|
||||||
@@ -27,10 +27,10 @@ class _HomePageState extends State<HomePage> {
|
|||||||
];
|
];
|
||||||
|
|
||||||
final List<String> titles = [
|
final List<String> titles = [
|
||||||
'Accueil', // 0
|
'Mes voyages', // 0
|
||||||
'Paramètres', // 1
|
'Paramètres', // 1
|
||||||
'Carte', // 2
|
'Carte', // 2
|
||||||
'Mes groupes', // 3
|
'Mes chats', // 3
|
||||||
'Comptes', // 4
|
'Comptes', // 4
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -55,10 +55,9 @@ class _HomePageState extends State<HomePage> {
|
|||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: Icon(Icons.home),
|
leading: Icon(Icons.home),
|
||||||
title: Text("Accueil"),
|
title: Text("Mes voyages"),
|
||||||
selected: _currentIndex == 0,
|
selected: _currentIndex == 0,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
print('Clicked Accueil - Setting index to 0'); // Debug
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_currentIndex = 0;
|
_currentIndex = 0;
|
||||||
});
|
});
|
||||||
@@ -70,7 +69,6 @@ class _HomePageState extends State<HomePage> {
|
|||||||
title: Text("Paramètres"),
|
title: Text("Paramètres"),
|
||||||
selected: _currentIndex == 1,
|
selected: _currentIndex == 1,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
print('Clicked Paramètres - Setting index to 1'); // Debug
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_currentIndex = 1;
|
_currentIndex = 1;
|
||||||
});
|
});
|
||||||
@@ -82,7 +80,6 @@ class _HomePageState extends State<HomePage> {
|
|||||||
title: Text("Carte"),
|
title: Text("Carte"),
|
||||||
selected: _currentIndex == 2,
|
selected: _currentIndex == 2,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
print('Clicked Carte - Setting index to 2'); // Debug
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_currentIndex = 2;
|
_currentIndex = 2;
|
||||||
});
|
});
|
||||||
@@ -94,7 +91,6 @@ class _HomePageState extends State<HomePage> {
|
|||||||
title: Text("Mes groupes"),
|
title: Text("Mes groupes"),
|
||||||
selected: _currentIndex == 3,
|
selected: _currentIndex == 3,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
print('Clicked Groupes - Setting index to 3'); // Debug
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_currentIndex = 3;
|
_currentIndex = 3;
|
||||||
});
|
});
|
||||||
@@ -106,7 +102,6 @@ class _HomePageState extends State<HomePage> {
|
|||||||
title: Text("Comptes"),
|
title: Text("Comptes"),
|
||||||
selected: _currentIndex == 4,
|
selected: _currentIndex == 4,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
print('Clicked Comptes - Setting index to 4'); // Debug
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_currentIndex = 4;
|
_currentIndex = 4;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -202,21 +202,6 @@ class _SignUpPageState extends State<SignUpPage> {
|
|||||||
|
|
||||||
const SizedBox(height: 40),
|
const SizedBox(height: 40),
|
||||||
|
|
||||||
// Champ Nom
|
|
||||||
TextFormField(
|
|
||||||
controller: _nomController,
|
|
||||||
validator: (value) => _validateField(value, 'Nom'),
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: 'Nom',
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.all(Radius.circular(12)),
|
|
||||||
),
|
|
||||||
prefixIcon: Icon(Icons.person),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
|
|
||||||
// Champ Prénom
|
// Champ Prénom
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _prenomController,
|
controller: _prenomController,
|
||||||
@@ -232,6 +217,21 @@ class _SignUpPageState extends State<SignUpPage> {
|
|||||||
|
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
|
||||||
|
// Champ Nom
|
||||||
|
TextFormField(
|
||||||
|
controller: _nomController,
|
||||||
|
validator: (value) => _validateField(value, 'Nom'),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Nom',
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.all(Radius.circular(12)),
|
||||||
|
),
|
||||||
|
prefixIcon: Icon(Icons.person),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
|
||||||
// Champ Email
|
// Champ Email
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _emailController,
|
controller: _emailController,
|
||||||
|
|||||||
108
lib/services/trip_service.dart
Normal file
108
lib/services/trip_service.dart
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import '../models/trip.dart';
|
||||||
|
|
||||||
|
class TripService {
|
||||||
|
static const String _tripsKey = 'trips_data';
|
||||||
|
|
||||||
|
// Charger tous les voyages
|
||||||
|
Future<List<Trip>> loadTrips() async {
|
||||||
|
try {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
final tripsJson = prefs.getString(_tripsKey);
|
||||||
|
|
||||||
|
if (tripsJson == null || tripsJson.isEmpty) return [];
|
||||||
|
|
||||||
|
final List<dynamic> jsonList = json.decode(tripsJson);
|
||||||
|
return jsonList.map((json) => Trip.fromMap(json)).toList();
|
||||||
|
} catch (e) {
|
||||||
|
print('Erreur lors du chargement des voyages: $e');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sauvegarder tous les voyages
|
||||||
|
Future<void> saveTrips(List<Trip> trips) async {
|
||||||
|
try {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
final jsonList = trips.map((trip) => trip.toMap()).toList();
|
||||||
|
await prefs.setString(_tripsKey, json.encode(jsonList));
|
||||||
|
} catch (e) {
|
||||||
|
print('Erreur lors de la sauvegarde des voyages: $e');
|
||||||
|
throw Exception('Erreur de sauvegarde');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajouter un nouveau voyage
|
||||||
|
Future<bool> addTrip(Trip trip) async {
|
||||||
|
try {
|
||||||
|
final trips = await loadTrips();
|
||||||
|
|
||||||
|
// Générer un ID unique
|
||||||
|
final newTrip = trip.copyWith(
|
||||||
|
id: DateTime.now().millisecondsSinceEpoch.toString(),
|
||||||
|
createdAt: DateTime.now(),
|
||||||
|
updatedAt: DateTime.now(),
|
||||||
|
);
|
||||||
|
|
||||||
|
trips.add(newTrip);
|
||||||
|
await saveTrips(trips);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
print('Erreur lors de l\'ajout du voyage: $e');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtenir les voyages d'un utilisateur
|
||||||
|
Future<List<Trip>> getTripsByUser(String userId) async {
|
||||||
|
try {
|
||||||
|
final trips = await loadTrips();
|
||||||
|
return trips
|
||||||
|
.where(
|
||||||
|
(trip) =>
|
||||||
|
trip.createdBy == userId || trip.participants.contains(userId),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
} catch (e) {
|
||||||
|
print('Erreur lors de la récupération des voyages: $e');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mettre à jour un voyage
|
||||||
|
Future<bool> updateTrip(Trip updatedTrip) async {
|
||||||
|
try {
|
||||||
|
final trips = await loadTrips();
|
||||||
|
final index = trips.indexWhere((trip) => trip.id == updatedTrip.id);
|
||||||
|
|
||||||
|
if (index != -1) {
|
||||||
|
trips[index] = updatedTrip.copyWith(updatedAt: DateTime.now());
|
||||||
|
await saveTrips(trips);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (e) {
|
||||||
|
print('Erreur lors de la mise à jour du voyage: $e');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Supprimer un voyage
|
||||||
|
Future<bool> deleteTrip(String tripId) async {
|
||||||
|
try {
|
||||||
|
final trips = await loadTrips();
|
||||||
|
final initialLength = trips.length;
|
||||||
|
trips.removeWhere((trip) => trip.id == tripId);
|
||||||
|
|
||||||
|
if (trips.length < initialLength) {
|
||||||
|
await saveTrips(trips);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (e) {
|
||||||
|
print('Erreur lors de la suppression du voyage: $e');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user