![](/img/trans.png)
[英]The parameter 'text', 'onPressed', 'outlineBtn' can't have a value of 'null' because of its type, but the implicit default value is 'null'
[英]The parameter 'answerQuestion' can't have a value of 'null' because of its type 'Function', but the implicit default value is 'null'
import 'package:flutter/material.dart';
import './question.dart';
import './answer.dart';
class Quiz extends StatelessWidget {
final List<Map<String, dynamic>> questions;
final int questionIndex;
final Function answerQuestion;
Quiz({
@required this.answerQuestion,
@required this.questions,
@required this.questionIndex,
});
@override
Widget build(BuildContext context) {
return Column(
children: [
Question(
questions[questionIndex]['question'],
),
...(questions[questionIndex]['answers'] as List<Map<String, dynamic>>)
.map((answer) =>
Answer(() => answerQuestion(answer['score']), answer['text']))
.toList()
],
);
}
}
終端顯示這個
lib/quiz.dart:12:20:錯誤:參數“answerQuestion”的值不能為“null”,因為它的類型為“Function”,但隱含的默認值為“null”。
@required
注釋現在已經過時了,我們通過required
關鍵字獲得了實際的編譯器支持:
Quiz({
required this.answerQuestion,
required this.questions,
required this.questionIndex,
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.