Skip to main content

sort_child_properties_last

The '{0}' argument should be last in widget constructor invocations.

Description

#

The analyzer produces this diagnostic when the child or children argument isn't the last argument in an invocation of a widget class' constructor. An exception is made if all of the arguments after the child or children argument are function expressions.

Example

#

The following code produces this diagnostic because the child argument isn't the last argument in the invocation of the Center constructor:

dart
import 'package:flutter/material.dart';

Widget createWidget() {
  return Center(
    child: Text('...'),
    widthFactor: 0.5,
  );
}

Common fixes

#

Move the child or children argument to be last:

dart
import 'package:flutter/material.dart';

Widget createWidget() {
  return Center(
    widthFactor: 0.5,
    child: Text('...'),
  );
}