我收到通知警告(不是错误),假设Use key in widget constructors.我有这样的无状态类:
class TeaTile extends StatelessWidget {
final TheTea? tea;
const TeaTile({this.tea}); //the warning in hire!
@override
Widget build(BuildContext context) {
return Container();
}
}
Run Code Online (Sandbox Code Playgroud)
基本的无状态格式有一个像这样的键:
class TeaTile extends StatelessWidget {
const TeaTile({ Key? key }) : super(key: key); //this one
@override
Widget build(BuildContext context) {
return Container();
}
}
Run Code Online (Sandbox Code Playgroud)
我知道如何禁用关键规则use_key_in_widget_constructors: false。但我不想这样做。那么,我如何key添加
final TheTea? tea;
const TeaTile({this.tea});
Run Code Online (Sandbox Code Playgroud)
解决警告通知?