import_deferred_library_with_load_function
The imported library defines a top-level function named 'loadLibrary' that is hidden by deferring this library.
Description
#The analyzer produces this diagnostic when a library that declares a
function named loadLibrary
is imported using a deferred import. A
deferred import introduces an implicit function named loadLibrary
. This
function is used to load the contents of the deferred library, and the
implicit function hides the explicit declaration in the deferred library.
For more information, check out Lazily loading a library.
Example
#Given a file a.dart
that defines a function named loadLibrary
:
void loadLibrary(Library library) {}
class Library {}
The following code produces this diagnostic because the implicit
declaration of a.loadLibrary
is hiding the explicit declaration of
loadLibrary
in a.dart
:
import 'a.dart' deferred as a;
void f() {
a.Library();
}
Common fixes
#If the imported library isn't required to be deferred, then remove the
keyword deferred
:
import 'a.dart' as a;
void f() {
a.Library();
}
If the imported library is required to be deferred and you need to reference the imported function, then rename the function in the imported library:
void populateLibrary(Library library) {}
class Library {}
If the imported library is required to be deferred and you don't need to
reference the imported function, then add a hide
clause:
import 'a.dart' deferred as a hide loadLibrary;
void f() {
a.Library();
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。