Add launch configuration, update API keys, and refactor UI components for better structure and performance
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../providers/user_provider.dart';
|
||||
|
||||
|
||||
class CreateTripContent extends StatefulWidget {
|
||||
const CreateTripContent({super.key});
|
||||
@@ -350,11 +349,13 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
|
||||
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'),
|
||||
),
|
||||
);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Veuillez d\'abord sélectionner la date de début'),
|
||||
),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -364,7 +365,7 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
firstDate: _startDate!,
|
||||
lastDate: DateTime.now().add(Duration(days: 365 * 2)),
|
||||
);
|
||||
if (picked != null) {
|
||||
if (picked != null && mounted) {
|
||||
setState(() {
|
||||
_endDate = picked;
|
||||
});
|
||||
@@ -378,17 +379,21 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
// 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')));
|
||||
if (mounted) {
|
||||
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é')));
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Ce participant est déjà ajouté'))
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -410,9 +415,11 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
}
|
||||
|
||||
if (_startDate == null || _endDate == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Veuillez sélectionner les dates')),
|
||||
);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Veuillez sélectionner les dates')),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -424,25 +431,31 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
// 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,
|
||||
),
|
||||
);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Voyage créé avec succès !'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Erreur lors de la création: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Erreur lors de la création: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user