Atelier : Projet de Gestion de Restaurant en Dart
Objectif
Créer un programme de gestion de restaurant en Dart qui permet de :
• Afficher un menu interactif.
• Prendre des commandes.
• Calculer le total de la commande.
• Afficher un récapitulatif des commandes.
Étapes
1. Initialisation du projet
Créez un nouveau projet « restaurant_management » dans votre dossier de Formation :
2. Structure de base du fichier Dart
Créez un fichier main.dart et ajoutez le code suivant :
import 'dart:io';
void main() {
gestionRestaurant();
}
void gestionRestaurant() {
3. Déclaration des variables et des types
Ajoutez le contenu de la fonction pour stocker les informations des plats et des commandes :
void gestionRestaurant() {
// Déclaration des plats et leurs prix
const Map<String, double> plats = {
'Eru': 1800,
'Ndole': 1500,
'Salade': 1400,
'Boisson': 500,
};
// Liste pour stocker les commandes
List<Map<String, int>> commandes = [];
bool continuer = true;
1
[email protected] www.logonedigital.com (+237) 6 52 10 98 85 / 6 59 48 47 72
Adresse : TotalEnergie Nsimeyong
RC RC/YAO/2024/B/1127
NIU: M052416809892A
// Boucle pour le menu principal
do {
afficherMenu(plats);
print("Entrez votre choix : ");
String choix = stdin.readLineSync() ?? '';
switch (choix) {
case '1':
case '2':
case '3':
case '4':
ajouterCommande(plats, choix, commandes);
break;
case '5':
continuer = false;
break;
default:
print("Choix invalide, veuillez réessayer.");
}
} while (continuer);
// Affichage du récapitulatif des commandes
afficherRecap(commandes, plats);
}
4. Affichage du menu
Ajoutez une fonction pour afficher le menu :
void afficherMenu(Map<String, double> plats) {
print("\n=== Menu de Restaurant ===");
int i = 1;
plats.forEach((plat, prix) {
print("$i. $plat (\$$prix)");
i++;
});
print("5. Terminer la commande");
}
5. Ajouter une commande
Ajoutez une fonction pour ajouter une commande :
void ajouterCommande(Map<String, double> plats, String choix,
List<Map<String, int>> commandes) {
String platChoisi;
switch (choix) {
case '1':
platChoisi = Eru;
[email protected] www.logonedigital.com (+237) 6 52 10 98 85 / 6 59 48 47 72
Adresse : TotalEnergie Nsimeyong
RC RC/YAO/2024/B/1127
NIU: M052416809892A
break;
case '2':
platChoisi = 'Ndole';
break;
case '3':
platChoisi = 'Salade';
break;
case '4':
platChoisi = 'Boisson';
break;
default:
platChoisi = '';
}
print("Combien de $platChoisi voulez-vous commander ? ");
int quantite = int.parse(stdin.readLineSync() ?? '0');
commandes.add({platChoisi: quantite});
print("$quantite $platChoisi ajouté(s) à la commande.");
}
6. Afficher le récapitulatif des commandes
Ajoutez une fonction pour afficher le récapitulatif des commandes :
void afficherRecap(List<Map<String, int>> commandes, Map<String, double>
plats) {
double total = 0.0;
print("\n=== Récapitulatif des Commandes ===");
for (var commande in commandes) {
commande.forEach((plat, quantite) {
double prix = plats[plat]! * quantite;
total += prix;
print("$quantite x $plat - ${prix.toStringAsFixed(2)} FCFA");
});
}
print("Total à payer : ${total.toStringAsFixed(2)} FCFA");
print("Merci pour votre commande !");
}
7. Ajout de la documentation
Documentez chaque fonction pour expliquer son rôle :
/// Affiche le menu des plats disponibles.
void afficherMenu(Map<String, double> plats) {
print("\n=== Menu de Restaurant ===");
int i = 1;
plats.forEach((plat, prix) {
print("$i. $plat ($prix)FCFA");
[email protected] www.logonedigital.com (+237) 6 52 10 98 85 / 6 59 48 47 72
Adresse : TotalEnergie Nsimeyong
RC RC/YAO/2024/B/1127
NIU: M052416809892A
i++;
});
print("5. Terminer la commande");
}
/// Ajoute une commande à la liste des commandes.
void ajouterCommande(Map<String, double> plats, String choix,
List<Map<String, int>> commandes) {
String platChoisi;
switch (choix) {
case '1':
platChoisi = 'Eru';
break;
case '2':
platChoisi = 'Ndole';
break;
case '3':
platChoisi = 'Salade';
break;
case '4':
platChoisi = 'Boisson';
break;
default:
platChoisi = '';
}
print("Combien de $platChoisi voulez-vous commander ? ");
int quantite = int.parse(stdin.readLineSync() ?? '0');
commandes.add({platChoisi: quantite});
print("$quantite $platChoisi ajouté(s) à la commande.");
}
/// Affiche le récapitulatif des commandes et calcule le total à payer.
void afficherRecap(List<Map<String, int>> commandes, Map<String, double>
plats) {
double total = 0.0;
print("\n=== Récapitulatif des Commandes ===");
for (var commande in commandes) {
commande.forEach((plat, quantite) {
double prix = plats[plat]! * quantite;
total += prix;
print("$quantite x $plat - ${prix.toStringAsFixed(2)} FCFA");
});
}
print("Total à payer : ${total.toStringAsFixed(2)} FCFA");
print("Merci pour votre commande !");
}
8. Utilisation de Git et GitHub (Ouvrer le Terminal)
1. Initialiser un dépôt Git :
git init
[email protected] www.logonedigital.com (+237) 6 52 10 98 85 / 6 59 48 47 72
Adresse : TotalEnergie Nsimeyong
RC RC/YAO/2024/B/1127
NIU: M052416809892A
2. Ajouter les fichiers au dépôt :
git add .
3. Commiter les changements :
git commit -m "Initial commit with restaurant management program"
4. Créer un nouveau dépôt sur GitHub :
o Allez sur GitHub et créez un nouveau dépôt.
5. Lier le dépôt local au dépôt distant :
git remote add origin https://github.com/votre-utilisateur/votre-
depot.git
6. Pousser les changements vers GitHub :
git push -u origin main
[email protected] www.logonedigital.com (+237) 6 52 10 98 85 / 6 59 48 47 72
Adresse : TotalEnergie Nsimeyong
RC RC/YAO/2024/B/1127
NIU: M052416809892A