i am developing a flutter quiz. Error:
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ The following NoSuchMethodError was thrown building QuizPage (dirty, state: _QuizPageState # 307d6): The getter 'length' was called on null. Receiver: null Tried calling: length
error https://pastebin.com/8JCG7Ecj https://pastebin.com/s0kvXLr1
after a few seconds the application is executed
But I got an exception, where I know where the exception and what it means, but i do not have any clue how i could solve the problem. I hope some of you guys could help me.
Git: https://github.com/ivsongborges/app_g6pd.git
class QuizPage extends StatefulWidget {
@override
_QuizPageState createState() => _QuizPageState();
}
class _QuizPageState extends State<QuizPage> {
final _controller = QuizController();
List<Widget> _scoreKeeper = [];
bool _loading = true;
@override
void initState() {
super.initState();
_initialize();
}
Future<void> _initialize() async {
await _controller.initialize();
setState(() {
_loading = false;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text('QUIZ G6PD ( ${_scoreKeeper.length}/${_controller.questionsNumber} )'),
centerTitle: true,
elevation: 0.0,
),
backgroundColor: Colors.white,
body: SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: _buildQuiz(),
),
),
);
}
_buildQuiz() {
if (_loading) return CenteredCircularProgress();
if (_controller.questionsNumber == 0)
return CenteredMessage(
'Sem questões',
icon: Icons.warning,
);
return Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
_buildQuestion(_controller.getQuestion()),
_buildAnswerButton(_controller.getAnswer1()),
_buildAnswerButton(_controller.getAnswer2()),
_buildScoreKeeper(),
],
);
}
_buildQuestion(String question) {
return Expanded(
flex: 5,
child: Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: Center(
child: Text(
question,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 25.0,
color: Colors.black,
),
),
),
),
);
}
_buildAnswerButton(String answer) {
return Expanded(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: GestureDetector(
child: Container(
padding: EdgeInsets.all(4.0),
color: Colors.blue,
child: Center(
child: AutoSizeText(
answer,
maxLines: 2,
minFontSize: 10.0,
maxFontSize: 32.0,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
),
),
onTap: () {
bool correct = _controller.correctAnswer(answer);
ResultDialog.show(
context,
question: _controller.question,
correct: correct,
onNext: () {
setState(() {
_scoreKeeper.add(
Icon(
correct ? Icons.check : Icons.close,
color: correct ? Colors.green : Colors.red,
),
);
if (_scoreKeeper.length < _controller.questionsNumber) {
_controller.nextQuestion();
} else {
FinishDialog.show(
context,
hitNumber: _controller.hitNumber,
questionNumber: _controller.questionsNumber
);
}
});
},
);
},
),
),
);
}
_buildScoreKeeper() {
return Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: _scoreKeeper,
),
);
}
}