目录

use_key_in_widget_constructors

Use key in widget constructors.

此规则自 Dart 2.8 版本起可用。

_规则集:flutter _

此规则提供 快速修复

详情

#

DO use key in widget constructors.

It's a good practice to expose the ability to provide a key when creating public widgets.

BAD:

dart
class MyPublicWidget extends StatelessWidget {
}

GOOD:

dart
class MyPublicWidget extends StatelessWidget {
  MyPublicWidget({super.key});
}

使用方法

#

要启用 use_key_in_widget_constructors 规则,请在你的 analysis_options.yaml 文件中,在 linter > rules 下添加 use_key_in_widget_constructors

analysis_options.yaml
yaml
linter:
  rules:
    - use_key_in_widget_constructors