calculateRowHeight static method

double calculateRowHeight(
  1. String text,
  2. double width,
  3. double fontSize
)

you can use this helper function to calculate / measure the height of a text with a given width (e.g. = colWidth) and fontSize but be aware, that the performance of this function is not really good because it has to measure the text and this is a quite complicated thing...

Implementation

static double calculateRowHeight(String text, double width, double fontSize) {
  final style = TextStyle(fontSize: fontSize);

  TextPainter textPainter = TextPainter()
    ..text = TextSpan(text: text, style: style)
    ..textDirection = TextDirection.ltr
    ..layout(minWidth: 0, maxWidth: width);

  var height = textPainter.height;
  textPainter.dispose();
  return height;
}