labelWidth static method
Implementation
static double labelWidth(String text, TextStyle style) {
final key =
'${style.fontSize ?? 14}_${style.fontWeight?.value ?? 400}_$text';
final cached = _labelWidthCache[key];
if (cached != null) return cached;
final painter = TextPainter(
text: TextSpan(text: text, style: style),
maxLines: 1,
textDirection: TextDirection.ltr,
)..layout(maxWidth: double.infinity);
final w = painter.width;
if (_labelWidthCache.length >= _maxCacheSize) {
_labelWidthCache.clear();
}
_labelWidthCache[key] = w;
return w;
}