getRows method
Implementation
List<Row> getRows(BuildContext context, double maxWidth) {
print(maxWidth);
print(minWidthPerChild);
var numberPerRow = max((maxWidth / minWidthPerChild).floor(), 1);
if (numberPerRow > maxChildrenPerRow) numberPerRow = maxChildrenPerRow;
print(numberPerRow);
var rows = <Row>[];
var countForRow = 0;
var currentRowChildren = <Widget>[];
for (var child in children!) {
currentRowChildren.add(
Expanded(
child: Container(
child: child,
margin: EdgeInsets.only(
top: 8.0,
right: 8.0,
),
),
),
);
countForRow++;
if (countForRow == numberPerRow) {
rows.add(
Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: currentRowChildren,
),
);
currentRowChildren = [];
countForRow = 0;
}
}
if (currentRowChildren.isNotEmpty) {
while (countForRow < numberPerRow) {
currentRowChildren.add(
Expanded(child: Container()),
);
countForRow++;
}
rows.add(
Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: currentRowChildren,
),
);
}
return rows;
}