【发布时间】:2021-12-27 11:30:06
【问题描述】:
我正在尝试构建和问答应用程序。 在我的问题页面中,我正在通过一种方法构建我的答案。 这就是方法;
SizedBox buildAnswerBox(var questionsOfSports,int answers) {
String? answerT;
return SizedBox(
height: 40,
width: 350,
child: StreamBuilder(stream: questionsOfSports.snapshots(),
builder: (BuildContext context, AsyncSnapshot asyncsnapshot) {
List<dynamic> question1 = asyncsnapshot.data.data()['q1']['q1Answers'];
switch (answers) {
case 1 :{ answerT=question1[0];}
break;
case 2 : {answerT=question1[1];}
break;
case 3 : {answerT=question1[2];}
break;
case 4 : {answerT=question1[3];}
}
return TextButton(
onPressed: () {},
child: Text('$answerT'),
style: TextButton.styleFrom(
backgroundColor: Colors.black,
),
);
},),
);
String answerT 持有来自 statefull 小部件的参数
buildAnswerBox(questionsOfSports,4),
现在我想为每个问题和这些问题的答案循环我的数据,但我不知道如何。
【问题讨论】:
标签: firebase flutter loops dart