const_ deferred_ class
Details about the 'const_deferred_class' diagnostic produced by the Dart analyzer.
Deferred classes can't be created with 'const'.
Description
#
The analyzer produces this diagnostic when a class from a
library that is imported using a deferred import is used to
create a const object. Constants are evaluated at
compile time, and classes from deferred libraries aren't
available at compile time.
For more information, check out Lazily loading a library.
Example
#
The following code produces this diagnostic because it
attempts to create a
const instance of a class from a deferred
library:
import 'dart:convert' deferred as convert;
const json2 = convert.JsonCodec();
Common fixes
#If the object isn't required to be a constant, then change the code so that a non-constant instance is created:
import 'dart:convert' deferred as convert;
final json2 = convert.JsonCodec();
If the object must be a constant, then remove
deferred from the import directive:
import 'dart:convert' as convert;
const json2 = convert.JsonCodec();
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.