sort_child_properties_last
Sort child properties last in widget instance creations.
Details
#Sort child properties last in widget instance creations. This improves readability and plays nicest with UI as Code visualization in IDEs with UI as Code Guides in editors (such as IntelliJ) where Properties in the correct order appear clearly associated with the constructor call and separated from the children.
BAD:
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',
),
);
GOOD:
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),
),
);
Exception: It's allowed to have parameter with a function expression after the
child
property.
Enable
#To enable the sort_child_properties_last
rule,
add sort_child_properties_last
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- sort_child_properties_last
If you're instead using the YAML map syntax to configure linter rules,
add sort_child_properties_last: true
under linter > rules:
analysis_options.yaml
yaml
linter:
rules:
sort_child_properties_last: true