import_ deferred_ library_ with_ load_ function
Details about the 'import_deferred_library_with_load_function' diagnostic produced by the Dart analyzer.
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.12.2 版本报告页面问题.