目录

prefer_inlined_adds

Inline list item declarations where possible.

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

_规则集:recommended , flutter _

此规则提供 快速修复

详情

#

Declare elements in list literals inline, rather than using add and addAll methods where possible.

BAD:

dart
var l = ['a']..add('b')..add('c');
var l2 = ['a']..addAll(['b', 'c']);

GOOD:

dart
var l = ['a', 'b', 'c'];
var l2 = ['a', 'b', 'c'];

使用方法

#

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

analysis_options.yaml
yaml
linter:
  rules:
    - prefer_inlined_adds