我制作了一個測驗應用程式,當按下按鈕時會移動到下一頁。但是,我想洗掉該按鈕并用手動輸入答案時評分后自動前進到下一頁的功能替換它。如何更改 press:() 代碼來執行此操作?
class Option extends StatelessWidget {
const Option({
Key? key,
required this.text,
required this.index,
required this.press,
}) : super(key: key);
final String text;
final int index;
final VoidCallback press;
class QuestionCard extends StatelessWidget {
const QuestionCard({
Key ?key,
required this.question,
}) : super(key: key);
final Question question;
@override
Widget build(BuildContext context) {
QuestionController _controller = Get.put(QuestionController());
return Container(
margin: EdgeInsets.symmetric(horizontal: 10),
child: Column(
children: [
SizedBox(height: 10),
...List.generate(
question.options.length,
(index) => Option(
index: index,
text: question.options[index],
press: () => _controller.checkAns(question, index),
),
),
],
),
);
}
}
void checkAns(Question question, String selectedIndex) {
_isAnswered = true;
_correctAns = question.options;
_selectedAns = selectedIndex;
if (_correctAns == _selectedAns) _numOfCorrectAns ;
update();
Future.delayed(Duration(seconds: 1), () {
if (_questionNumber.value != _questions.length) {
_isAnswered = false;
_pageController.nextPage(
duration: Duration(milliseconds: 100), curve: Curves.ease);
} else {
Get.off(ScoreScreen());
}
});
}
uj5u.com熱心網友回復:
我認為我們應該 - 首先 - 深化這個選擇背后的邏輯:你期望應用程式什么時候進入下一頁/問題?
假設您的用戶剛剛完成輸入,您如何識別他已完成回答?也許他只是停下來,說,想多一點。
我個人會選擇textInputAction: TextInputAction.done在當前頁面的最后一個表單上添加一個。盡管這不適用于 Web 或桌面。
uj5u.com熱心網友回復:
嘗試使用手勢檢測器(https://api.flutter.dev/flutter/widgets/GestureDetector-class.html)包裹它,或者您可以使用 navigator.push 到新螢屏(https://flutter.dev/ docs/cookbook/navigation/navigation-basics)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/350649.html
