A reminder of dart if statements:
in dart we can create an if statement with the following syntax:
if (condition) {
'your code here'}
else {
' if the condition fails do this'
}
ternary operators
var x = condition ? z : y
in the expression above x will be z if the condition is true, otherwise, it will be y.
we can use if statements and ternary operators in Flutter to render a widget based on a condition.
in the code above you can see I have a class MyApp, which has a method answerQuestion in the state class. this will increase the index of the question by 1, it is used to increase the index every time the user selects an answer for a question.
here is my questions object which is a list of Maps where each Map has keys question Text and question Answer:
I want my app to render questions and when the questions are finished, render a text to state the questions are done.
in the code above im using ternary operation and my condition is questionIndex < questions.length
if the questionIndex is within the length of questions object that means I still have question for that index, otherwise I'm out of questions and I can show my completion text.
you can see questions.dart and answer.dart in the previous tutorials.