这是我的代码的一部分,我不断收到必须向文本小部件提供的非空字符串。 Flutter 还是新手,所以我不确定如何解决这个问题。我尝试将 ??"" 放在 child 上: Text(myQuiz[0][i.toString()] 但后来它给了我一个错误方法 '[]' was called on null. 接收器:空 尝试调用:
// Let's create a comment that we will link to a start element and an end element
$commentWithStartAndEnd = new \PhpOffice\PhpWord\Element\Comment('Foo Bar', new \DateTime());
$commentWithStartAndEnd->addText('A comment with a start and an end');
$phpWord->addComment($commentWithStartAndEnd);
$textrunWithEnd = $section->addTextRun();
$textrunWithEnd->addText('This ');
$textToStartOn = $textrunWithEnd->addText('is', array('bold' => true));
$textToStartOn->setCommentRangeStart($commentWithStartAndEnd);
$textrunWithEnd->addText(' another', array('italic' => true));
$textToEndOn = $textrunWithEnd->addText(' test');
$textToEndOn->setCommentRangeEnd($commentWithStartAndEnd);
答案 0 :(得分:0)
这是因为 null value
被提供给您的 Text
小部件
从您的代码中......以下一项或多项是null 并且不是字符串
myQuiz[1][i.toString()][k]
showTimer
试试
...
@override
Widget build(BuildContext context) {
print(myQuiz[1][i.toString()][k]);
print(showTimer);
找出哪个是空值
答案 1 :(得分:0)
试试这个。
Text(
myQuiz[1]?[i?.toString()]?[k] ?? "Default Value",
style: TextStyle(
color: Colors.black,
fontFamily: "Open Sans",
fontSize: 16.0,
),
maxLines: 1,
),
答案 2 :(得分:0)
感谢帮助,我找到了答案,它在getRandom中,因为json没有0,所以当测验运行并命中0时,它会导致错误