get method
Implementation
TextPainter get(
String text,
TextStyle style, {
double maxWidth = double.infinity,
TextAlign align = TextAlign.left,
}) {
final safeMaxWidth = _safeTextLayoutMaxWidth(maxWidth);
final key =
'${text.length}:$text|${style.hashCode}|$safeMaxWidth|${align.index}';
// LRU: move hit entry to end.
if (_cache.containsKey(key)) {
_hits++;
final existing = _cache.remove(key)!;
_cache[key] = existing;
return existing;
}
_misses++;
// Evict LRU (first) entry when full.
if (_cache.length >= _maxSize) {
_cache.remove(_cache.keys.first);
_evictions++;
}
final painter = TextPainter(
text: TextSpan(text: text, style: style),
textDirection: TextDirection.ltr,
textAlign: align,
)..layout(maxWidth: safeMaxWidth);
_cache[key] = painter;
return painter;
}