我正在使用这个存储库(https://github.com/londonappbrewery/destini-challenge-completed)中完成的项目。
我在Text()小部件和后续调用中出错。
storyBrain.getStory();
storyBrain.getChoice1();
storyBrain.getChoice2();错误:
A non-null String must be provided to a Text widget.
'package:flutter/src/widgets/text.dart':
Failed assertion: line 285 pos 10: 'data != null'

WorkAround --我尝试使用.toString()将其转换为string,但仍然会出现相同的错误。
颤振博士-
E:\Temp\flutter\destini-challenge-starting>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
> Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.18363.778], locale en-IN)
> Android toolchain - develop for Android devices (Android SDK version 29.0.2)
> Android Studio (version 3.6)
> VS Code, 64-bit edition (version 1.44.2)
> Connected device (1 available)
• No issues found!发布于 2020-06-14 11:16:35
这是因为您的对象还没有初始化,为了解决这个问题,我们需要更多的代码,但是为了避免出现空异常,请像这样使用??,它将检查它之前的值是否为空,然后它将在??之后显示值。
storyBrain.getStory() ?? 'default value';
storyBrain.getChoice1() ?? 'default value';
storyBrain.getChoice2() ?? 'default value';https://stackoverflow.com/questions/62371215
复制相似问题