sort_child_properties_last
ウィジェットインスタンスの作成において、子プロパティを最後にソートします。
この規則は Dart 2.4 から利用可能です。
ルールセット: flutter
この規則には、利用可能な クイックフィックス があります。
詳細
#ウィジェットインスタンスの作成において、子プロパティを最後にソートします。これにより、可読性が向上し、エディター(IntelliJなど)のUI as Codeガイド付きIDEで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.5.3 を反映しています。ページの最終更新日は 2024-07-03 です。 ソースを表示 または 問題を報告。