I am beginner in flutter. I am trying to make simple addition program which will generate random number to add with each other and also create 4 random options for answer out of which one will be correct answer. But the problem is sometimes similar options and I don't want to correct options for result.
Below is my code. can anybody help me out?
class _StartGameState extends State<StartGame> {
int inp1, inp2;
GenerateQuestion g = new GenerateQuestion();
int num1, num2, num3, num4;
int no1, no2, no3, no4;
int pos;
int res;
Map answers;
bool flag = true;
void getNum() {
num1 = g.generateNum();
num2 = g.generateNum();
num3 = g.generateNum();
num4 = g.generateNum();
inp1 = g.generateValue();
inp2 = g.generateValue();
// this method returns value from 0 to 3
pos = g.answerPosition();
res = inp1 + inp2;
switch (pos) {
case 0:
num1 = res;
break;
case 1:
num2 = res;
break;
case 2:
num3 = res;
break;
case 3:
num4 = res;
break;
}
if (res == num1 || res == num2 || res == num3 || res == num4) {
if (num1 != num2 &&
num1 != num3 &&
num1 != num4 &&
num2 != num3 &&
num2 != num4 &&
num3 != num4) {
setState(() {
no1 = num1;
no2 = num2;
no3 = num3;
no4 = num4;
});
}
}
}
}
GenerateQuestion is a separate class file. which has simple methods which creates random object with range and returns value;
My Interface is like enter image description here