Flutter开发报错:getQuestionText()缺少必需的位置参数
解决Flutter中
Too few positional arguments: 1 required, 0 given报错 问题原因
你调用quizBrain.getQuestionText()时未传入该方法要求的1个位置参数,该方法的定义应该包含至少1个必填的位置参数(比如问题索引、ID等)。
解决方案
- 查看
quizBrain类中getQuestionText的方法定义,确认它需要的参数类型和用途(通常是当前问题的索引)。 - 在调用时传入对应的必填参数。
修改后的代码示例
假设你维护了一个记录当前问题序号的变量(比如_questionNumber),修改调用代码如下:
Expanded( flex: 5, child: Padding( padding: EdgeInsets.all(10.0), child: Center( child: Text( quizBrain.getQuestionText(_questionNumber), // 传入必填参数 textAlign: TextAlign.center, style: TextStyle( fontSize: 25.0, color: Colors.white, ), ), ), ), ),
如果getQuestionText要求的参数不是索引,而是其他类型(比如问题ID),只需替换为对应的值即可。
内容的提问来源于stack exchange,提问作者Joseph Mills
相关产品推荐
相关产品推荐

