estimateWidth method

double estimateWidth(
  1. BuildContext context
)

Estimates the natural single-line width of this tile (leading, title / subtitle text measured with their resolved styles, padding, trailing).

Used by TGrid to size tiles by content. Wrapping desc and values are ignored since they reflow to the available width.

Implementation

double estimateWidth(BuildContext context) {
  final colors = context.colors;
  final effectiveIcon = icon ?? leading;
  final effectiveIconSize = iconSize ?? size.icon;
  final effectiveIconPadding = iconPadding ?? (size.hPad > 0 || size.vPad > 0 ? size.padding : const EdgeInsets.all(8));
  final effectiveSpacing = spacing ?? size.spacing;

  final subtitleStyle = TextStyle(
    fontSize: size.resolveSubtitleFontSize(),
    fontWeight: FontWeight.w400,
    color: colors.onSurfaceVariant,
  ).merge(this.subtitleStyle);

  final text = math.max(
    title != null ? WidthHelper.measureText(context, title!, _resolveTitleStyle(colors)) : 0.0,
    subtitle != null ? WidthHelper.measureText(context, subtitle!, subtitleStyle) : 0.0,
  );

  final hasLeading = effectiveIcon != null || (imageUrl != null && imageUrl!.isNotEmpty);
  final leadingWidth = hasLeading
      ? _resolveLeadingDimensions(
          leading: effectiveIcon ?? imageUrl,
          defaultSize: effectiveIconSize,
          iconPadding: effectiveIconPadding,
        ).$1
      : 0.0;
  final trailingWidth = trailing != null ? 48.0 : 0.0;
  final body = iconOnTop
      ? math.max(text, leadingWidth + trailingWidth)
      : text + (hasLeading ? leadingWidth + effectiveSpacing : 0.0) + trailingWidth;
  return body + (padding?.horizontal ?? 0.0);
}