I have a list of items that I want to present to the user one-by-one, this being controlled by awaiting user input before showing next item.
To give a contextual example this could be a list of questions that the user has to answer one-by-one. Each question will have question body and a list of options for user to select. They could be presented by a single Card to begin with and once they have selected one of the options the value is captured and the next Card is displayed below
So the super simplified version off what I have is something like this
import 'package:flutter/material.dart';
class QuestionScreen extends StatefulWidget {
QuestionScreen();
@override
_QuestionScreenState createState() => _QuestionScreenState();
}
class _QuestionScreenState extends State<QuestionScreen> {
@override
Widget build(BuildContext context) {
List<Question> listOfQuestions = [
new Question(),
new Question(),
new Question()
];
return Scaffold(
body: Column(
children: [
Text('List Of Questions'),
...listOfQuestions.map((eachQuestion) {
return Card(
elevation: 10,
margin: EdgeInsets.symmetric(
vertical: 5,
horizontal: 10,
),
child: ListTile(
title: Text(eachQuestion.questionText),
subtitle: Row(
children: [
...eachQuestion.listOfOptionsForTheUserToSelect
.map((eachOption) {
return ElevatedButton(
onPressed: () => {},
child: Text(eachOption),
);
}).toList()
],
),
),
);
}).toList()
],
),
);
}
}
class Question {
String questionText = "question";
List<String> listOfOptionsForTheUserToSelect = ["ans1", "ans2"];
}
