简体   繁体   中英

What is the meaning of “!.” in Dart? What is the equivalent code of “!.” ? -Flutter

I want to extend FileImage.

But I found there are some code required "non-nullable" feature:

  Future<ui.Codec> _loadAsync(FileImage key, DecoderCallback decode) async {
    assert(key == this);

    final Uint8List bytes = await file.readAsBytes();

    if (bytes.lengthInBytes == 0) {
      // The file may become available later.
      PaintingBinding.instance!.imageCache!.evict(key);
      throw StateError('$file is empty and cannot be loaded as an image.');
    }

    return await decode(bytes);
  }

What is the equivalent code of "PaintingBinding.instance!.imageCache!.evict(key);" ?

Say you have:

int? foo = 1; // foo is nullable. 

And when you do something like this:

foo!.toString(); 

You're telling the compiler that I know foo isn't null , let me proceed. So, it is equivalent to:

(foo as int).toString();

This is actually called bang operator, and in case foo is null , you get an error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM