簡體   English   中英

的意義是什么 ”!。” 在飛鏢? “!.”的等價代碼是什么? ? -撲

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

我想擴展 FileImage。

但我發現有一些代碼需要“不可為空”功能:

  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);
  }

“PaintingBinding.instance!.imageCache!.evict(key);”的等價代碼是什么? ?

說你有:

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

當你做這樣的事情時:

foo!.toString(); 

你告訴編譯器我知道foo不是null ,讓我繼續。 所以,它等價於:

(foo as int).toString();

這實際上稱為 bang 運算符,如果foonull ,則會出現錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM