Rules / Style / sort-child-properties-last
sort-child-properties-last
Flags a child or children argument that is not the last named argument in a widget constructor call.
In a Flutter widget tree the child is usually the largest and most deeply
nested argument, so keeping it last lets the eye follow the configuration
(padding, color, alignment) before descending into the subtree, and keeps the
closing ) visually adjacent to the child's own closing bracket. This rule
flags any child:/children: named argument that appears before another
named argument. To avoid firing on ordinary function calls that happen to take
a child parameter, it only considers constructions whose callee is
PascalCase — implicit Foo(...) calls and explicit new/const Foo(...).
Invalid
example.dartdart
// Bad: the child/children argument is not last in a widget constructor call.
import 'package:flutter/material.dart';
Widget b0() => Center(child: Text('a'), key: Key('k'));
Widget b1() => Column(children: [Text('a'), Text('b')], key: Key('k'));
Widget b2() => Padding(child: Text('a'), padding: EdgeInsets.zero);
Widget b3() => Container(child: Text('a'), width: 10);
Widget b4() => SizedBox(child: Text('a'), width: 10, height: 10);
The child/children argument should be last in a widget constructor call.
3
4Widget b0() => Center(child: Text('a'), key: Key('k'));
∙
The child/children argument should be last in a widget constructor call.
5
6Widget b1() => Column(children: [Text('a'), Text('b')], key: Key('k'));
∙
The child/children argument should be last in a widget constructor call.
7
8Widget b2() => Padding(child: Text('a'), padding: EdgeInsets.zero);
∙
The child/children argument should be last in a widget constructor call.
9
10Widget b3() => Container(child: Text('a'), width: 10);
∙
The child/children argument should be last in a widget constructor call.
11
12Widget b4() => SizedBox(child: Text('a'), width: 10, height: 10);
∙
Valid
example.dartdart
// Good: child/children is last, absent, or the call is not a widget constructor.
import 'package:flutter/material.dart';
Widget g0() => Center(key: Key('k'), child: Text('a'));
Widget g1() => Column(key: Key('k'), children: [Text('a'), Text('b')]);
Widget g2() => Padding(padding: EdgeInsets.zero, child: Text('a'));
Widget g3() => Text('no child');
Widget g4() => SizedBox(width: 10, height: 10, child: Text('a'));
Widget g5() => Center(child: Text('a'));
int g6() => doWork(child: 5, other: 6);
How to configure
Set the severity of sort-child-properties-last in your falcon.json:
falcon.jsonjson
{
"linter": {
"rules": {
"style": {
"sort-child-properties-last": "error"
}
}
}
}