unnecessary_import
The import of '{0}' is unnecessary because all of the used elements are also provided by the import of '{1}'.
Description
#The analyzer produces this diagnostic when an import isn't needed because all of the names that are imported and referenced within the importing library are also visible through another import.
Example
#Given a file a.dart
that contains the following:
class A {}
And, given a file b.dart
that contains the following:
export 'a.dart';
class B {}
The following code produces this diagnostic because the class A
, which is
imported from a.dart
, is also imported from b.dart
. Removing the import
of a.dart
leaves the semantics unchanged:
import 'a.dart';
import 'b.dart';
void f(A a, B b) {}
Common fixes
#If the import isn't needed, then remove it.
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。