尝试构建一个考试应用程序,在该应用程序中,每次从API中点击时,我只能得到一个问题。我尝试做的是构建问题并启动计时器(90-0)当问题显示时。在计时器为0或按下提交按钮后,构建新问题(从API获取数据后),定时器从90秒开始重新启动,此时定时器从90秒到0,setState
后停止,不启动
我看过并尝试过其他的解决方案,比如创建一个startTimer()
函数,但是TweenAnimationBuilder
看起来很适合这个任务。但是,我不知道用onEnd
重新启动它。
下面是我的TweenAnimationBuilder:
TweenAnimationBuilder(
tween: Tween(begin: 90.0, end: 0.0),
duration: Duration(seconds: 90),
builder: (context, value, child) {
num val = value;
num time = val.toInt();
return Stack(
alignment: Alignment.center,
children: [
normalText(
text: "$time",
size: 25,
color: color__orange),
SizedBox(
width: 60,
height: 60,
child: CircularProgressIndicator(
value: time /
90,
valueColor: const AlwaysStoppedAnimation(
color__orange),
),
),
]
);
},
onEnd: (){
var questionID = snapshot.data!.quizzesData!.first.questionID;
QuizQuestion(questionID);
setState(() {
});
},
),
这里是提交按钮:
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: color__orange ),
onPressed: (){
if (selectedOptionStatus == 'True') {
var questionID = snapshot.data!.quizzesData!.first.questionID;
var score = snapshot.data!.quizzesData!.first.question!.first.marks;
var answerID = snapshot.data!.quizzesData!.first.question!.first.answer![index].answerID;
QuizQuestion(questionID);
StudentQuestionAnswer(questionID, score, answerID);
// currentQuestionIndex = int.parse(widget.totalQuestions) - remainingQuestions;
currentQuestionIndex++;
if ( (currentQuestionIndex + 1) == int.parse(widget.totalQuestions)) {
updateStudentQuizLoginHistoryFinish();
}
setState(() {});
}
else {
if (selectedOptionStatus == 'False') {
var questionID = snapshot.data!.quizzesData!.first.questionID;
var score = '0';
var answerID = snapshot.data!.quizzesData!.first.question!.first.answer![index].answerID;
QuizQuestion(questionID);
StudentQuestionAnswer(questionID, score, answerID);
currentQuestionIndex++;
if (currentQuestionIndex + 1 == int.parse(widget.totalQuestions)) {
StudentQuiz();
}
setState(() {});
}
}
},
child: const Text('Save Answer')
)
1条答案
按热度按时间1l5u6lss1#
提供TweenAnimationBuilder的密钥
key: ValueKey(questionId)
这将强制释放以前的TweenAnimationBuilder,并创建和附加新的TweenAnimationBuilder。