Created
August 19, 2023 17:43
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👌🏼