getFittedWidth method

double getFittedWidth(
  1. String? key,
  2. dynamic value, {
  3. double? maxKeyWidth,
  4. double? maxValueWidth,
})

Implementation

double getFittedWidth(String? key, dynamic value,
    {double? maxKeyWidth, double? maxValueWidth}) {
  double width = 0;
  double? cached = cacheMain[key];
  if (cached == null) {
    cached = getMaxWidth(
        key?.characters ?? nullCharacters, avgMaxKeyLength, maxKeyWidth);
    cacheMain[key] = cached;
  }
  width += cached;
  if (isNotNullOrEmpty(value)) {
    Characters valueCharacters;
    cached = null;
    if (value is String) {
      valueCharacters = value.characters;
    } else if (value is num || value is bool || value == null) {
      valueCharacters = nullCharacters;
      cached = cacheMain[value];
    } else {
      valueCharacters = value.toString().characters;
    }
    cached ??= getMaxWidth(valueCharacters, avgMaxValueLength, maxValueWidth);
    width += cached;
  }
  return width;
}