invalid_literal_annotation
Details about the 'invalid_literal_annotation' diagnostic produced by the Dart analyzer.
Only const constructors can have the @literal annotation.
Description
#
The analyzer produces this diagnostic when the literal
annotation is applied to anything other than a const constructor.
Examples
#
The following code produces this diagnostic because the constructor isn't
a const constructor:
import 'package:meta/meta.dart';
class C {
@literal
C();
}
The following code produces this diagnostic because x isn't a
constructor:
import 'package:meta/meta.dart';
@literal
var x;
Common fixes
#
If the annotation is on a constructor and the constructor should always be
invoked with const, when possible, then mark the constructor with the
const keyword:
import 'package:meta/meta.dart';
class C {
@literal
const C();
}
If the constructor can't be marked as const, then remove the annotation.
If the annotation is on anything other than a constructor, then remove the annotation:
var x;
除非另有说明,文档之所提及适用于 Dart 3.10.3 版本报告页面问题.