[英]Getting “The Declaration Isn't Referenced” error in Flutter even though it is referenced in main.dart
I am completing the Angela Yu Flutter course, am working on the "Quizzler" project, and continue to get an error stating that the declaration in a dart file isn't referenced, however it appears (to me) to be.我正在完成 Angela Yu Flutter 课程,正在从事“Quizzler”项目,并继续收到错误消息,指出 dart 文件中的声明没有被引用,但它似乎(对我来说)是。 Both getQuestionText and getQuestionAnswer are resulting in the same error.
getQuestionText 和 getQuestionAnswer 都会导致相同的错误。 I have made sure to import quiz_brain.dart into main.dart.
我确保将 quiz_brain.dart 导入 main.dart。 Any help would be very much appreciated.
任何帮助将不胜感激。
excerpt from quiz_brain.dart:摘自 quiz_brain.dart:
void nextQuestion (){
if (_questionNumber < _questionBank.length){_questionNumber++;
}
String get() {
return _questionBank[_questionNumber].questionText;
}
String getQuestionText (){
return _questionBank[_questionNumber].questionText;
}
bool getQuestionAnswer () {
return _questionBank[_questionNumber].questionAnswer;
}
}
excerpt from main.dart:摘自 main.dart:
Expanded(
flex: 5,
child: Padding(
padding: EdgeInsets.all(10.0),
child: Center(
child: Text(
quizBrain.getQuestionText(),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 25.0,
color: Colors.white,
),
),
),
),
),
Have you checked if quizBrain has been initialized in main.dart?您是否检查过 quizBrain 是否已在 main.dart 中初始化? Make sure that quizBrain also has access to List _questionBank
确保 quizBrain 也可以访问 List _questionBank
With the quiz_brain.dart excerpt that you provided, please make sure you have your curly braces correct.使用您提供的 quiz_brain.dart 摘录,请确保您的花括号正确。 You missed the curly closing braces for your
nextQuestion()
function.您错过了
nextQuestion()
function 的大括号。 Because of that misplacement of that curly closing braces from the nextQuestion()
function, you had an extra curly closing brace at the bottom of your excerpt.由于
nextQuestion()
function 中的花括号错位,您的摘录底部有一个额外的花括号。
Corrected quiz_brain.dart更正了 quiz_brain.dart
void nextQuestion (){
if (_questionNumber < _questionBank.length){
_questionNumber++;
}
}
String get() {
return _questionBank[_questionNumber].questionText;
}
String getQuestionText () {
return _questionBank[_questionNumber].questionText;
}
bool getQuestionAnswer () {
return _questionBank[_questionNumber].questionAnswer;
}
Secondly, your get()
function and getQuestionText()
function does exactly the same thing, you may want to removing one of it.其次,你的
get()
function 和getQuestionText()
function 做同样的事情,你可能想删除其中一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.