Я создаю приложение для викторины во флаттере. Я читаю данные из API как JSON и отображаю в RadioListTile.
У меня есть четыре кнопки RadioListTile, когда пользователь выбирает одну из кнопок, я хочу получить значение выбранного и сохранить его в массиве или списке и перейти на страницу результатов. как это можно идентифицировать?
RadioListTile:
List<Widget> createRadioList(){
List<Widget> widget = [];
widget.add(
RadioListTile(
value: "${questions[i].questionCorrectAnswer}",
groupValue: selectedRadio1,
title: Text(
"${questions[i].questionCorrectAnswer}"),
onChanged: (currentChoice) {
setState(() {
print(currentChoice);
setSelectedRadio(currentChoice);
checkAnswer(currentChoice.toString());
selectedQ(currentChoice);
});
},
activeColor: Colors.teal,
),
);
widget.add(
RadioListTile(
value: "${questions[i].questionAnswerTow}",
groupValue: selectedRadio2,
title: Text(
"${questions[i].questionAnswerTow}"),
onChanged: (currentChoice) {
setState(() {
print(currentChoice);
setSelectedRadio(currentChoice);
checkAnswer(currentChoice.toString());
selectedQ(currentChoice);
});
},
activeColor: Colors.red,
),
);
widget.add(
RadioListTile(
value: "${questions[i].questionAnswerThree}",
groupValue: selectedRadio3,
title: Text(
"${questions[i].questionAnswerThree}"),
onChanged: (currentChoice) {
setState(() {
print(currentChoice);
setSelectedRadio(currentChoice);
checkAnswer(currentChoice.toString());
selectedQ(currentChoice);
});
},
activeColor: Colors.red,
),
);
widget.add(
RadioListTile(
value: "${questions[i].questionAnswerFour}",
groupValue: selectedRadio4,
title: Text(
"${questions[i].questionAnswerFour}"),
onChanged: (currentChoice) {
setState(() {
print(currentChoice);
setSelectedRadio(currentChoice);
checkAnswer(currentChoice.toString());
selectedQ(currentChoice);
});
},
activeColor: Colors.red,
),
);
// widget.shuffle();
return widget;
}
Класс:
class Questions {
String questionId;
String questionQuestion;
String questionCorrectAnswer;
String subjectId;
String questionAnswerTow;
String questionAnswerThree;
String questionAnswerFour;
Questions(
{this.questionId,
this.questionQuestion,
this.questionCorrectAnswer,
this.subjectId,
this.questionAnswerTow,
this.questionAnswerThree,
this.questionAnswerFour});
factory Questions.fromJson(Map<String, dynamic> json) {
return Questions(
questionId: json['question_id'],
questionQuestion: json['question_question'],
questionCorrectAnswer: json['question_correct_answer'],
subjectId: json['subject_id'],
questionAnswerTow: json['question_answer_two'],
questionAnswerThree: json['question_answer_three'],
questionAnswerFour: json['question_answer_four']);
}
}
Пожалуйста, помогите.