sort_child_properties_last
在 widget 實例建立中,將子屬性排序在最後。
此規則自 Dart 2.4 起可用。
規則集:flutter
此規則有可用的快速修復。
詳細資訊
#在 widget 實例建立中,將子屬性排序在最後。這能提升可讀性,並在 IDE 中使用 UI as Code 可視化,以及在編輯器(例如 IntelliJ)中使用 UI as Code 指南時,能將正確順序的屬性與建構子呼叫清楚地關聯,並與子項分隔開來。
錯誤範例
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
除非另有說明,否則本網站上的文件反映 Dart 3.6.0。頁面上次更新時間為 2024-07-03。 檢視原始碼 或 回報問題。