invalid_literal_annotation
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.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。