跳到主要內容

asset_not_string_or_map

asset 值必須是檔案路徑 (字串) 或 map。

描述

#

當 asset 值不是字串或 map 時,分析器會產生此診斷訊息。

示例

#

以下程式碼會產生此診斷訊息,因為 asset 值是一個列表

yaml
name: example
flutter:
  assets:
    - [one, two, three]

常見修復

#

如果需要指定除 asset 路徑之外的更多資訊,請將該值替換為一個包含 path 鍵 (有效的 POSIX 風格檔案路徑) 的 map

yaml
name: example
flutter:
  assets:
    - path: assets/image.gif
      flavors:
      - premium

如果只需要指定路徑,請將該值替換為 asset 的路徑 (有效的 POSIX 風格檔案路徑)

yaml
name: example
flutter:
  assets:
    - assets/image.gif