![](/img/trans.png)
[英]CarouselSlider nextPage _CastError (Null check operator used on a null value) Error
[英]I can't resolve null check operator used on a null value error
Uint8List? _file;
SizedBox(
height: 45,
width: 45,
child: AspectRatio(
aspectRatio: 487 / 451,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: MemoryImage(_file!),
fit: BoxFit.fill,
alignment: FractionalOffset.topCenter)),
),
),
),
Null 检查运算符用于 null 值。 我知道这个错误的原因,但我不知道如何解决它。
使用 Uint8List? 我使用 _file 定义为“此值可能为空”的值。 我试图用“这个值不为空”来调用它。 这是错误的原因,但我不知道如何解决它。
最好先进行 null 检查。
if (_file != null)
SizedBox(
height: 45,
width: 45,
child: AspectRatio(
aspectRatio: 487 / 451,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: MemoryImage(_file!),
fit: BoxFit.fill,
alignment: FractionalOffset.topCenter)),
),
),
),
或者
image: _file != null
? DecorationImage(
image: MemoryImage(_file),
fit: BoxFit.fill,
alignment: FractionalOffset.topCenter,
)
: null,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.