computeCellHeight method

  1. @protected
double computeCellHeight(
  1. GridColumn column,
  2. DataGridRow row,
  3. Object? cellValue,
  4. TextStyle textStyle,
)

Calculates the height of the cell based on the DataGridCell.value. You can override this method to perform the custom calculation for hight.

If you want to calculate the width based on different TextStyle, you can override this method and call the super method with the required TextStyle. Set the custom ColumnSizer to SfDataGrid.columnSizer property.

class CustomColumnSizer extends ColumnSizer {
@override
 double computeCellHeight(GridColumn column, DataGridRow row, Object cellValue,
     TextStyle textStyle) {
  TextStyle style = textStyle;
  if (column.columnName == 'Name')
   style = TextStyle(fontSize: 20, fontStyle: FontStyle.italic);
 return super.computeCellWidth(column, row, cellValue, style);
}
}

The auto size is calculated based on default TextStyle of the datagrid.

Implementation

@protected
double computeCellHeight(GridColumn column, DataGridRow row,
    Object? cellValue, TextStyle textStyle) {
  final DataGridConfiguration dataGridConfiguration =
      _dataGridStateDetails!();
  final int rowIndex = grid_helper.resolveToRowIndex(dataGridConfiguration,
      effectiveRows(dataGridConfiguration.source).indexOf(row));
  return _measureCellHeight(column, rowIndex, cellValue, textStyle);
}