Created
July 18, 2021 22:51
-
-
Save YusufAbdelaziz/8954dc761b21de215635053d645beaf0 to your computer and use it in GitHub Desktop.
A method to know the width of a text before rendering it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Finds the width of a text before rendering it. | |
Size findTextSize( | |
{required String text, | |
TextStyle style = textStyle, | |
required BuildContext context, | |
TextDirection textDirection = TextDirection.rtl}) { | |
final Size size = (TextPainter( | |
text: TextSpan(text: text, style: style), | |
maxLines: 5, | |
textScaleFactor: MediaQuery.of(context).textScaleFactor, | |
textDirection: textDirection) | |
..layout(minWidth: 0, maxWidth: double.infinity)) | |
.size; | |
return size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment