autoFitColumn method
Implementation
@override
void autoFitColumn(BuildContext context, PlutoColumn column) {
final String maxValue = refRows.fold('', (previousValue, element) {
final value = column.formattedValueForDisplay(
element.cells.entries
.firstWhere((element) => element.key == column.field)
.value
.value,
);
if (previousValue.length < value.length) {
return value;
}
return previousValue;
});
// Get size after rendering virtually
// https://stackoverflow.com/questions/54351655/flutter-textfield-width-should-match-width-of-contained-text
TextSpan textSpan = TextSpan(
style: DefaultTextStyle.of(context).style,
text: maxValue,
);
TextPainter textPainter = TextPainter(
text: textSpan,
textDirection: TextDirection.ltr,
);
textPainter.layout();
// todo : Apply (popup type icon, checkbox, drag indicator, renderer)
EdgeInsets cellPadding =
column.cellPadding ?? configuration.style.defaultCellPadding;
resizeColumn(
column,
textPainter.width -
column.width +
(cellPadding.left + cellPadding.right) +
2,
);
}