Add launch configuration, update API keys, and refactor UI components for better structure and performance
This commit is contained in:
@@ -14,29 +14,63 @@ class HomePage extends StatefulWidget {
|
||||
|
||||
class _HomePageState extends State<HomePage> {
|
||||
int _currentIndex = 0;
|
||||
|
||||
// Cache pour les pages créées
|
||||
final Map<int, Widget> _pageCache = {};
|
||||
|
||||
final List<String> titles = [
|
||||
'Mes voyages', // 0
|
||||
'Paramètres', // 1
|
||||
'Carte', // 2
|
||||
'Chat de groupe', // 3
|
||||
'Comptes', // 4
|
||||
];
|
||||
|
||||
Widget _buildPage(int index) {
|
||||
// Vérifier si la page est déjà en cache
|
||||
if (_pageCache.containsKey(index)) {
|
||||
return _pageCache[index]!;
|
||||
}
|
||||
|
||||
// Créer la page seulement quand elle est demandée
|
||||
Widget page;
|
||||
switch (index) {
|
||||
case 0:
|
||||
page = const HomeContent();
|
||||
break;
|
||||
case 1:
|
||||
page = const SettingsContent();
|
||||
break;
|
||||
case 2:
|
||||
page = const MapContent();
|
||||
break;
|
||||
case 3:
|
||||
page = const GroupContent();
|
||||
break;
|
||||
case 4:
|
||||
page = const CountContent();
|
||||
break;
|
||||
default:
|
||||
page = const HomeContent();
|
||||
}
|
||||
|
||||
// Mettre en cache la page créée
|
||||
_pageCache[index] = page;
|
||||
return page;
|
||||
}
|
||||
|
||||
void _onNavigationTap(int index) {
|
||||
setState(() {
|
||||
_currentIndex = index;
|
||||
});
|
||||
Navigator.pop(context); // Fermer le drawer
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Définir les pages directement dans le build pour éviter les erreurs
|
||||
final List<Widget> pages = [
|
||||
HomeContent(), // 0
|
||||
SettingsContent(), // 1
|
||||
MapContent(), // 2
|
||||
GroupContent(), // 3
|
||||
CountContent(), // 4
|
||||
];
|
||||
|
||||
final List<String> titles = [
|
||||
'Mes voyages', // 0
|
||||
'Paramètres', // 1
|
||||
'Carte', // 2
|
||||
'Chat de groupe', // 3
|
||||
'Comptes', // 4
|
||||
];
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(titles[_currentIndex]), // Debug
|
||||
title: Text(titles[_currentIndex]),
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
@@ -48,70 +82,40 @@ class _HomePageState extends State<HomePage> {
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.inversePrimary,
|
||||
),
|
||||
child: Text(
|
||||
child: const Text(
|
||||
"Travel Mate",
|
||||
style: TextStyle(color: Colors.white, fontSize: 24),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.home),
|
||||
title: Text("Mes voyages"),
|
||||
selected: _currentIndex == 0,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_currentIndex = 0;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
_buildDrawerItem(
|
||||
icon: Icons.home,
|
||||
title: "Mes voyages",
|
||||
index: 0,
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.settings),
|
||||
title: Text("Paramètres"),
|
||||
selected: _currentIndex == 1,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_currentIndex = 1;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
_buildDrawerItem(
|
||||
icon: Icons.settings,
|
||||
title: "Paramètres",
|
||||
index: 1,
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.map),
|
||||
title: Text("Carte"),
|
||||
selected: _currentIndex == 2,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_currentIndex = 2;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
_buildDrawerItem(
|
||||
icon: Icons.map,
|
||||
title: "Carte",
|
||||
index: 2,
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.group),
|
||||
title: Text("Chat de groupe"),
|
||||
selected: _currentIndex == 3,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_currentIndex = 3;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
_buildDrawerItem(
|
||||
icon: Icons.group,
|
||||
title: "Chat de groupe",
|
||||
index: 3,
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.account_balance_wallet),
|
||||
title: Text("Comptes"),
|
||||
selected: _currentIndex == 4,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_currentIndex = 4;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
_buildDrawerItem(
|
||||
icon: Icons.account_balance_wallet,
|
||||
title: "Comptes",
|
||||
index: 4,
|
||||
),
|
||||
Divider(),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
leading: Icon(Icons.logout, color: Colors.red),
|
||||
title: Text("Déconnexion", style: TextStyle(color: Colors.red)),
|
||||
leading: const Icon(Icons.logout, color: Colors.red),
|
||||
title: const Text("Déconnexion", style: TextStyle(color: Colors.red)),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
@@ -124,7 +128,38 @@ class _HomePageState extends State<HomePage> {
|
||||
],
|
||||
),
|
||||
),
|
||||
body: pages[_currentIndex],
|
||||
body: IndexedStack(
|
||||
index: _currentIndex,
|
||||
children: [
|
||||
// Créer les pages seulement si elles sont sélectionnées
|
||||
for (int i = 0; i < titles.length; i++)
|
||||
if (_currentIndex == i || _pageCache.containsKey(i))
|
||||
_buildPage(i)
|
||||
else
|
||||
Container(), // Placeholder vide
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDrawerItem({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required int index,
|
||||
}) {
|
||||
return ListTile(
|
||||
leading: Icon(icon),
|
||||
title: Text(title),
|
||||
selected: _currentIndex == index,
|
||||
selectedTileColor: Theme.of(context).colorScheme.primary.withValues(alpha: 0.1),
|
||||
onTap: () => _onNavigationTap(index),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// Nettoyer le cache si nécessaire
|
||||
_pageCache.clear();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,31 +62,39 @@ class _LoginPageState extends State<LoginPage> {
|
||||
_passwordController.text,
|
||||
);
|
||||
|
||||
if (user != null) {
|
||||
// Naviguer vers la page d'accueil
|
||||
Provider.of<UserProvider>(context, listen: false).setCurrentUser(user);
|
||||
Navigator.pushReplacementNamed(context, '/home');
|
||||
} else {
|
||||
// Échec de la connexion
|
||||
_showErrorMessage('Email ou mot de passe incorrect');
|
||||
if (mounted) {
|
||||
if (user != null) {
|
||||
// Naviguer vers la page d'accueil
|
||||
Provider.of<UserProvider>(context, listen: false).setCurrentUser(user);
|
||||
Navigator.pushReplacementNamed(context, '/home');
|
||||
} else {
|
||||
// Échec de la connexion
|
||||
_showErrorMessage('Email ou mot de passe incorrect');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
_showErrorMessage('Erreur lors de la connexion: ${e.toString()}');
|
||||
if (mounted) {
|
||||
_showErrorMessage('Erreur lors de la connexion: ${e.toString()}');
|
||||
}
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _showErrorMessage(String message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
backgroundColor: Colors.red,
|
||||
duration: Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
backgroundColor: Colors.red,
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user