performLayout method
Override this method to lay out and position all children given this widget's size.
This method must call layoutChild for each child. It should also specify the final position of each child with positionChild.
Implementation
@override
void performLayout(Size size) {
bool isLTR = _stateManager.isLTR;
double bodyRowsTopOffset = 0;
double bodyRowsBottomOffset = 0;
double columnsTopOffset = 0;
double bodyLeftOffset = 0;
double bodyRightOffset = 0;
// first layout header and footer and see what remains for the scrolling part
if (hasChild(_StackName.header)) {
// maximum 40% of the height
var s = layoutChild(
_StackName.header,
BoxConstraints.loose(Size(size.width, _safe(size.height / 100 * 40))),
);
_stateManager.headerHeight = s.height;
bodyRowsTopOffset += s.height;
columnsTopOffset += s.height;
}
if (hasChild(_StackName.headerDivider)) {
layoutChild(
_StackName.headerDivider,
BoxConstraints.tight(
Size(size.width, PlutoGridSettings.gridBorderWidth),
),
);
positionChild(
_StackName.headerDivider,
Offset(0, columnsTopOffset),
);
}
if (hasChild(_StackName.footer)) {
// maximum 40% of the height
var s = layoutChild(
_StackName.footer,
BoxConstraints.loose(Size(size.width, _safe(size.height / 100 * 40))),
);
_stateManager.footerHeight = s.height;
bodyRowsBottomOffset += s.height;
positionChild(
_StackName.footer,
Offset(0, size.height - bodyRowsBottomOffset),
);
}
if (hasChild(_StackName.footerDivider)) {
layoutChild(
_StackName.footerDivider,
BoxConstraints.tight(
Size(size.width, PlutoGridSettings.gridBorderWidth),
),
);
positionChild(
_StackName.footerDivider,
Offset(0, size.height - bodyRowsBottomOffset),
);
}
// now layout columns of frozen sides and see what remains for the body width
if (hasChild(_StackName.leftFrozenColumns)) {
var s = layoutChild(
_StackName.leftFrozenColumns,
BoxConstraints.loose(size),
);
final double posX = isLTR ? 0 : size.width - s.width;
positionChild(
_StackName.leftFrozenColumns,
Offset(posX, columnsTopOffset),
);
if (isLTR) {
bodyLeftOffset = s.width;
} else {
bodyRightOffset = s.width;
}
}
if (hasChild(_StackName.leftFrozenDivider)) {
var s = layoutChild(
_StackName.leftFrozenDivider,
BoxConstraints.tight(
Size(
PlutoGridSettings.gridBorderWidth,
_safe(size.height - columnsTopOffset - bodyRowsBottomOffset),
),
),
);
final double posX = isLTR
? bodyLeftOffset
: size.width - bodyRightOffset - PlutoGridSettings.gridBorderWidth;
positionChild(
_StackName.leftFrozenDivider,
Offset(posX, columnsTopOffset),
);
if (isLTR) {
bodyLeftOffset += s.width;
} else {
bodyRightOffset += s.width;
}
}
if (hasChild(_StackName.rightFrozenColumns)) {
var s = layoutChild(
_StackName.rightFrozenColumns,
BoxConstraints.loose(size),
);
final double posX =
isLTR ? size.width - s.width + PlutoGridSettings.gridBorderWidth : 0;
positionChild(
_StackName.rightFrozenColumns,
Offset(posX, columnsTopOffset),
);
if (isLTR) {
bodyRightOffset = s.width;
} else {
bodyLeftOffset = s.width;
}
}
if (hasChild(_StackName.rightFrozenDivider)) {
var s = layoutChild(
_StackName.rightFrozenDivider,
BoxConstraints.tight(
Size(
PlutoGridSettings.gridBorderWidth,
_safe(size.height - columnsTopOffset - bodyRowsBottomOffset),
),
),
);
final double posX = isLTR
? size.width - bodyRightOffset - PlutoGridSettings.gridBorderWidth
: bodyLeftOffset;
positionChild(
_StackName.rightFrozenDivider,
Offset(posX, columnsTopOffset),
);
if (isLTR) {
bodyRightOffset += s.width;
} else {
bodyLeftOffset += s.width;
}
}
if (hasChild(_StackName.bodyColumns)) {
var s = layoutChild(
_StackName.bodyColumns,
BoxConstraints.loose(
Size(
_safe(size.width - bodyLeftOffset - bodyRightOffset),
size.height,
),
),
);
final double posX =
isLTR ? bodyLeftOffset : size.width - s.width - bodyRightOffset;
positionChild(
_StackName.bodyColumns,
Offset(posX, columnsTopOffset),
);
bodyRowsTopOffset += s.height;
}
if (hasChild(_StackName.bodyColumnFooters)) {
var s = layoutChild(
_StackName.bodyColumnFooters,
BoxConstraints.loose(
Size(
_safe(size.width - bodyLeftOffset - bodyRightOffset),
size.height,
),
),
);
_stateManager.columnFooterHeight = s.height;
final double posX =
isLTR ? bodyLeftOffset : size.width - s.width - bodyRightOffset;
positionChild(
_StackName.bodyColumnFooters,
Offset(posX, size.height - bodyRowsBottomOffset - s.height),
);
bodyRowsBottomOffset += s.height;
}
if (hasChild(_StackName.columnFooterDivider)) {
var s = layoutChild(
_StackName.columnFooterDivider,
BoxConstraints.tight(
Size(size.width, PlutoGridSettings.gridBorderWidth),
),
);
positionChild(
_StackName.columnFooterDivider,
Offset(0, size.height - bodyRowsBottomOffset - s.height),
);
}
// layout rows
if (hasChild(_StackName.columnRowDivider)) {
var s = layoutChild(
_StackName.columnRowDivider,
BoxConstraints.tight(
Size(size.width, PlutoGridSettings.gridBorderWidth),
),
);
positionChild(
_StackName.columnRowDivider,
Offset(0, bodyRowsTopOffset),
);
bodyRowsTopOffset += s.height;
} else {
bodyRowsTopOffset += PlutoGridSettings.gridBorderWidth;
}
if (hasChild(_StackName.leftFrozenRows)) {
final double offset = isLTR ? bodyLeftOffset : bodyRightOffset;
final double posX = isLTR
? 0
: size.width - bodyRightOffset + PlutoGridSettings.gridBorderWidth;
layoutChild(
_StackName.leftFrozenRows,
BoxConstraints.loose(
Size(
offset,
_safe(size.height - bodyRowsTopOffset - bodyRowsBottomOffset),
),
),
);
positionChild(
_StackName.leftFrozenRows,
Offset(posX, bodyRowsTopOffset),
);
}
if (hasChild(_StackName.leftFrozenColumnFooters)) {
final double offset = isLTR ? bodyLeftOffset : bodyRightOffset;
final double posX = isLTR
? 0
: size.width - bodyRightOffset + PlutoGridSettings.gridBorderWidth;
layoutChild(
_StackName.leftFrozenColumnFooters,
BoxConstraints.loose(
Size(offset, _safe(size.height - bodyRowsBottomOffset)),
),
);
positionChild(
_StackName.leftFrozenColumnFooters,
Offset(posX, size.height - bodyRowsBottomOffset),
);
}
if (hasChild(_StackName.rightFrozenRows)) {
final double offset = isLTR ? bodyRightOffset : bodyLeftOffset;
final double posX = isLTR
? size.width - bodyRightOffset + PlutoGridSettings.gridBorderWidth
: 0;
layoutChild(
_StackName.rightFrozenRows,
BoxConstraints.loose(
Size(
offset,
_safe(size.height - bodyRowsTopOffset - bodyRowsBottomOffset),
),
),
);
positionChild(
_StackName.rightFrozenRows,
Offset(posX, bodyRowsTopOffset),
);
}
if (hasChild(_StackName.rightFrozenColumnFooters)) {
final double offset = isLTR ? bodyRightOffset : bodyLeftOffset;
var s = layoutChild(
_StackName.rightFrozenColumnFooters,
BoxConstraints.loose(Size(offset, size.height)),
);
final double posX =
isLTR ? size.width - s.width + PlutoGridSettings.gridBorderWidth : 0;
positionChild(
_StackName.rightFrozenColumnFooters,
Offset(posX, size.height - bodyRowsBottomOffset),
);
}
if (hasChild(_StackName.bodyRows)) {
layoutChild(
_StackName.bodyRows,
BoxConstraints.tight(Size(
_safe(size.width - bodyLeftOffset - bodyRightOffset),
_safe(
size.height - bodyRowsTopOffset - bodyRowsBottomOffset,
),
)),
);
positionChild(
_StackName.bodyRows,
Offset(bodyLeftOffset, bodyRowsTopOffset),
);
}
if (hasChild(_StackName.loading)) {
Size loadingSize;
switch (_stateManager.loadingLevel) {
case PlutoGridLoadingLevel.grid:
loadingSize = size;
break;
case PlutoGridLoadingLevel.rows:
loadingSize = Size(size.width, 3);
positionChild(
_StackName.loading,
Offset(0, bodyRowsTopOffset),
);
break;
case PlutoGridLoadingLevel.rowsBottomCircular:
loadingSize = const Size(30, 30);
positionChild(
_StackName.loading,
Offset(
(size.width / 2) + 15,
size.height - bodyRowsBottomOffset - 45,
),
);
break;
}
layoutChild(
_StackName.loading,
BoxConstraints.tight(loadingSize),
);
}
if (hasChild(_StackName.noRows)) {
layoutChild(
_StackName.noRows,
BoxConstraints.loose(
Size(
size.width,
_safe(size.height - bodyRowsTopOffset - bodyRowsBottomOffset),
),
),
);
positionChild(
_StackName.noRows,
Offset(0, bodyRowsTopOffset),
);
}
}