在我的pubspec中将linter升级到新版本(flutter_lints: 2.0.1
)之后
顺便说一句:我知道我可以禁用这个规则.
在我的pubspec中将linter升级到新版本(flutter_lints: 2.0.1
)之后
顺便说一句:我知道我可以禁用这个规则.
我遇到了同样的问题,现在当你生成一个StatefulWidget
而不是在createState
方法中返回_ExampleState
时,它现在返回State<Example>
,这避免了返回私有类型.我最终更新了我所有的小部件,使之适应这种方法.
所以
class Example extends StatefulWidget {
const Example({Key? key}) : super(key: key);
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
@override
Widget build(BuildContext context) {
return Container();
}
}
可以重写为
class Example extends StatefulWidget {
// you can al所以 now use a super initializer for key
// if you are using dart 2.17
const Example({super.key});
// now returning State<Example>
@override
State<Example> createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
@override
Widget build(BuildContext context) {
return Container();
}
}