跳到主要内容

sort_child_properties_last

稳定
Flutter
可修复

在 widget 实例创建中将子属性排在最后。

详情

#

在 widget 实例创建中将子属性排在最后。这提高了可读性,并且与支持 UI 即代码指南的 IDE (例如 IntelliJ) 中的 UI 即代码可视化效果最佳,在这些 IDE 中,按正确顺序排列的属性会清晰地与构造函数调用关联并与子属性分开。

dart
return Scaffold(
  appBar: AppBar(
    title: Text(widget.title),
  ),
  body: Center(
    child: Column(
      children: <Widget>[
        Text(
          'You have pushed the button this many times:',
         ),
        Text(
          '$_counter',
          style: Theme.of(context).textTheme.display1,
         ),
      ],
      mainAxisAlignment: MainAxisAlignment.center,
    ),
    widthFactor: 0.5,
  ),
  floatingActionButton: FloatingActionButton(
    child: Icon(Icons.add),
    onPressed: _incrementCounter,
    tooltip: 'Increment',
  ),
);

dart
return Scaffold(
  appBar: AppBar(
    title: Text(widget.title),
  ),
  body: Center(
    widthFactor: 0.5,
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Text(
          'You have pushed the button this many times:',
         ),
        Text(
          '$_counter',
          style: Theme.of(context).textTheme.display1,
         ),
      ],
    ),
  ),
  floatingActionButton: FloatingActionButton(
    onPressed: _incrementCounter,
    tooltip: 'Increment',
    child: Icon(Icons.add),
  ),
);

例外:允许在 child 属性之后添加包含函数表达式的参数。

启用

#

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

analysis_options.yaml
yaml
linter:
  rules:
    - sort_child_properties_last

如果您改为使用 YAML 映射语法配置 Linter 规则,请在 linter > rules 下添加 sort_child_properties_last: true

analysis_options.yaml
yaml
linter:
  rules:
    sort_child_properties_last: true