![](/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.