invalid_factory_method_decl
Factory method '{0}' must have a return type.
Description
#The analyzer produces this diagnostic when a method that is annotated with
the factory
annotation has a return type of void
.
Example
#The following code produces this diagnostic because the method createC
is annotated with the factory
annotation but doesn't
return any value:
dart
import 'package:meta/meta.dart';
class Factory {
@factory
void createC() {}
}
class C {}
Common fixes
#Change the return type to something other than void
:
dart
import 'package:meta/meta.dart';
class Factory {
@factory
C createC() => C();
}
class C {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。