【发布时间】:2021-12-23 22:09:41
【问题描述】:
我收到关于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();
}
}
基本的无状态格式有一个这样的键:
class TeaTile extends StatelessWidget {
const TeaTile({ Key? key }) : super(key: key); //this one
@override
Widget build(BuildContext context) {
return Container();
}
}
我知道如何禁用密钥规则use_key_in_widget_constructors: false。但我不想这样做。那么,我如何在
key
final TheTea? tea;
const TeaTile({this.tea});
解决警告通知?
【问题讨论】:
标签: flutter dart constructor flutter-widget