I've managed to make a dynamic questionnaire connecting flutter with Firestore.
My custom Question widgets are just a Text() holding the string of the question, and a Slider() so the user can give an answer from 1 to 5
Now that the questions are displayed, how should I get the values?
Here's my code:
var questions = <Widget>[];
//Async read to the DB
Future query() async {
var snap = await Firestore.instance
.collection("Forms")
.document(formID)
.get();
var arr = <Widget>[]; //just a temp holder of the widgets
for(String q in list){
arr.add(Question(min: 1.0, max: 5.0, question: q, value: 1.0,));
}
setState(() {
questions = arr;
});
}
And then in the build I'm rendering:
Scaffold(
body:Container(
child:Column(
children: <Widget>[
Text("Title"),
Column(
children: questions,
),
RaisedButton(
onPressed: () => sendFeedback(),
color: Colors.redAccent,
textColor: Colors.white,
child: Text("Send")
]
)
What would be the code for the sendFeedback() function? I would like to get the values for all the sliders in my children list and then write those to Firestore in only one call to the DB.