[英]TweenAnimationBuilder reset animation to the starting point onEnd and start again when an event is triggered
嘗試構建一個考試應用程序,我一次只能從 API 的每次點擊中得到一個問題。我想要做的是構建問題並在顯示問題時啟動計時器 (90-0)。 定時器為 0 或按下提交按鈕后,新問題開始構建(從 API 獲取數據后),定時器從 90 秒重新開始。 目前,計時器從 90 變為 0 並在setState
后停止並且不啟動
我已經看到並嘗試過其他解決方案,例如創建startTimer()
function,但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')
)
為 TweenAnimationBuilder 提供密鑰
key: ValueKey(questionId)
這將強制釋放之前的 TweenAnimationBuilder 並創建並附加新的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.