Dart & Flutter

[Flutter] Get Text Size

ju_young 2023. 5. 4. 19:18
728x90
Size getTextSize(String text, TextStyle style) {
      final TextPainter textPainter = TextPainter(
          text: TextSpan(text: text, style: style),
          maxLines: 1,
          textDirection: TextDirection.ltr)
        ..layout(minWidth: 0, maxWidth: double.infinity);
      return textPainter.size;
    }

 

[reference]

https://stackoverflow.com/questions/52659759/how-can-i-get-the-size-of-the-text-widget-in-flutter

728x90