Skip to content

Instantly share code, notes, and snippets.

@amir00462
Created August 19, 2023 17:43
Show Gist options
  • Save amir00462/48c1a16f201da85b3db9bcfba3802b59 to your computer and use it in GitHub Desktop.
Save amir00462/48c1a16f201da85b3db9bcfba3802b59 to your computer and use it in GitHub Desktop.
code of creating a menu in dart using while and functions and switch case
// Example2 , yaghoot flutter , by AmirHosseinMohammadi
import 'dart:io';
welcome() {
print("Welcome to my app :) ");
print("this app helps you have a better life");
print("\nchoose an option below : ");
print("1. admin panel");
print("2. user panel");
print("3. guest");
print("4. exit\n");
}
adminPanel() {
print("\nAdmin Panel");
print("you can see product list");
print("you can add new product or remove a product");
stdout.write("Press any key to back to mainMenu...");
final fakeInput = stdin.readLineSync();
}
userPanel() {
print("\nUser Panel");
print("you can buy or send a feedback for a product");
stdout.write("Press any key to back to mainMenu...");
final fakeInput = stdin.readLineSync();
}
guestPanel() {
print("\nGuest Panel");
print("you can just see products and if interested, create an account");
stdout.write("Press any key to back to mainMenu...");
final fakeInput = stdin.readLineSync();
}
void main() {
String? userInput = "";
while (userInput != "4") {
print("\n");
welcome();
stdout.write("enter your desire code: ");
userInput = stdin.readLineSync();
switch (userInput!) {
case "1":
adminPanel();
break;
case "2":
userPanel();
break;
case "3":
guestPanel();
break;
case "4":
exit(0);
default:
print("wrong number entered...");
break;
}
}
print("\n\nsee you later...\n\n");
}
@OmidHaqi
Copy link

👌🏼

@iman1372
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment