flutter-template icon indicating copy to clipboard operation
flutter-template copied to clipboard

Introduce getSize String extension

Open nivisi opened this issue 3 years ago • 0 comments

  Size getSize(
    TextStyle style, {
    int maxLines = 1,
    double minWidth = .0,
    double maxWidth = double.infinity,
  }) {
    if (isNullOrBlank) {
      return Size.zero;
    }

    final text = TextSpan(text: this, style: style);
    final textPainter = TextPainter(
      maxLines: maxLines,
      textAlign: TextAlign.left,
      textDirection: TextDirection.ltr,
      text: text,
    );

    textPainter.layout(minWidth: minWidth, maxWidth: maxWidth);

    return textPainter.size;
  }

nivisi avatar Oct 12 '22 10:10 nivisi