fitFontSize static method
Calculates the optimal font size to fit text within bounds.
Implementation
static double fitFontSize(
String text,
TextStyle style,
Size bounds, {
double minFontSize = 8,
double maxFontSize = 24,
}) {
double fontSize = maxFontSize;
while (fontSize >= minFontSize) {
final size = measureText(text, style.copyWith(fontSize: fontSize));
if (size.width <= bounds.width && size.height <= bounds.height) {
return fontSize;
}
fontSize -= 1;
}
return minFontSize;
}