fluent2WordsWidth function

double fluent2WordsWidth(
  1. BuildContext context,
  2. Iterable<String> lines,
  3. TextStyle style
)

The widest of lines in style, at the text scale of context.

Implementation

double fluent2WordsWidth(
  BuildContext context,
  Iterable<String> lines,
  TextStyle style,
) {
  var widest = 0.0;
  final scaler = MediaQuery.textScalerOf(context);
  for (final line in lines) {
    final painter = TextPainter(
      text: TextSpan(text: line, style: style),
      textScaler: scaler,
      textDirection: TextDirection.ltr,
      maxLines: 1,
    )..layout();
    if (painter.width > widest) widest = painter.width;
    painter.dispose();
  }
  return widest.ceilToDouble();
}