跳到主要內容

prefix_collides_with_top_level_member

名稱“{0}”已被用作匯入字首,不能用於命名頂級元素。

描述

#

當同一個庫中的名稱同時用作匯入字首和頂級宣告的名稱時,分析器會生成此診斷資訊。

示例

#

以下程式碼會產生此診斷資訊,因為 f 同時用作匯入字首和函式名稱

dart
import 'dart:math' as f;

int f() => f.min(0, 1);

常見修復

#

如果您想將該名稱用於匯入字首,請重新命名頂級宣告

dart
import 'dart:math' as f;

int g() => f.min(0, 1);

如果您想將該名稱用於頂級宣告,請重新命名匯入字首

dart
import 'dart:math' as math;

int f() => math.min(0, 1);