Flutter workshop to learn basics and create a first mobile application. The App you will create will be a Quizz Game app.
You will learn different Flutter widgets and their usage.
This Workshop is organized for Epitech Innovation Hub.
First, go to Flutter Official Documentation and do the setup in the order below.
- Get the Flutter SDK
- Update Your Path
- Run
flutter doctor(Be sure that it's working ...)
- Install Android Studio
- Setup the Android Emulator
- Agree to Android License
Do the next steps Set up an Editor and Test Drive.
Now, the setup is done. Let's start our Quizz App.
You can find all the project's resources in the directory quizz-assets.
First, we will create our first page:
Take a look at theses widgets:
Your first page is created, you can launch the game by pressing button. So now, let's navigate to a new page !
- Create a new page named PageQuizz which is a Statefull Widget. (Do it in a new Dart file and don't forget to import it)
- Navigate from your first page to your PageQuizz page.
You should be interested in:
- Now, your are going to create a new class named Question in a new dart file. This class will contain these attributes:
String questionbool answerString explicationString imagePath
- import your file in the PageQuizz page.
- Create an instance of Question in the PageQuizz page.
- Create a list of Question called
questionListas in the example below:
Question("Belgium's motto is \"L'union fait la force\".", true, '', 'belgium.jpg'),
Question("The moon will eventually fall to Earth because of gravity", false, "On the contrary, the moon is moving away", 'moon.jpg'),
Question("Russia is larger in area than Pluto", true, '', 'russia.jpg'),
Question("Nyctalope is a dwarf breed of antelope", false, "It is an ability to see in the dark", 'nyctalope.jpg'),
Question("The Commodore 64 is the best selling desktop computer", true, '', 'commodore.jpg'),
Question("The name of the pirate flag is Black Skull", false, "It is called Jolly Roger", 'pirate.png'),
Question("Haddock is the name of Tintin's dog", false, "It is Milou", 'tintin.jpg'),
Question("The beard of the pharaohs was false", true, "Already at that time they used hairpieces", 'pharao.jpg'),
Question("In Quebec, \"tire toi une buche\" means come and sit down", true, "The log, the famous lumberjack's chair", 'log.jpg'),
Question("The lunar module Eagle had 4Kb of RAM", true, "I can't believe I'm complaining with my 8GB of ram on my pc", 'eagle.jpg')
- Create two variables
int index = 0andint score = 0 - Create an initState method: It is the method first called when the page is created.
- Add
question = questionList[index]in the initState to set the instance of Question in the QuizzPqge at the first question of the list.
At this time, you have your first page to launch the game, you be able to navigate between different pages and you got your class Question. So now, you are going to create the UI of a question.
Use your questionList to fill informations
Now, you will create a popup when you press on True or False buttons.
You have to check if the button pressed is the same as the bool attribute of the question in the questionList at current index.
If the answer is right, your popup might look like this:
And if the answer is wrong:
- Take a look at onPressed method.
- Take a look at SimpleDialog widget.
- Don't forget to increment the score if the answer is right.
Now, you are going to move on the next question.
- First, you have to call
Navigator.pop(context)method to make disappear the SimpleDialog when you press the "Next Question" button. - Create a function
nextQuestionwhich check if the current question is lower thanquestionList.lengthand if it's right, increment the index to move on the next question. - Take a look at setState method which allows to refresh the page and come back in the
initStateto change the current question.
if (index < questionList.length - 1) {
index++;
setState(() {
question = questionList[index]
});
} else
// Call an AlertDialog to inform the player that the game is over and display he's score.
// You can add a button to allow player to come back at the first page.
Congratulations! You have successfully created your first mobile app in Flutter.
We hope you enjoyed this workshop and we encourage you to continue learning Flutter.
- Ilan BENARROCHE (ilan.benarroche@epitech.eu)
- Arsene MATHIEU (arsene.mathieu@epitech.eu)



