TTableHeader<T, K>.tile constructor

TTableHeader<T, K>.tile(
  1. String text,
  2. String? title(
    1. T
    ), {
  3. String? subtitle(
    1. T
    )?,
  4. dynamic icon(
    1. T
    )?,
  5. dynamic leading(
    1. T
    )?,
  6. Color? iconColor(
    1. T
    )?,
  7. Color? iconBackgroundColor(
    1. T
    )?,
  8. TextStyle? titleStyle,
  9. TextStyle? subtitleStyle,
  10. double? iconSize,
  11. EdgeInsetsGeometry? iconPadding,
  12. BorderRadius? iconBorderRadius,
  13. double spacing = 10.0,
  14. CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
  15. Widget trailing(
    1. T
    )?,
  16. int? flex,
  17. double? minWidth,
  18. double? maxWidth,
  19. Alignment? alignment,
  20. String? key,
  21. TFilterType? filterType = TFilterType.text,
  22. bool filterable = true,
  23. List<TFilterOperator>? filterOperators,
  24. List? filterItems,
  25. TFilterDef<T>? filterDef,
  26. double widthEstimator(
    1. T data
    )?,
  27. bool flattenOnMobile = false,
  28. String mobileKeyPrefixBuilder(
    1. String headerText,
    2. String childKey
    )?,
  29. List<TKeyValue> keyValuesBuilder(
    1. T data
    )?,
})

Creates a header for displaying a title and optional subtitle with leading icon using TTile.

Implementation

TTableHeader.tile(
  this.text,
  String? Function(T) title, {
  String? Function(T)? subtitle,
  dynamic Function(T)? icon,
  dynamic Function(T)? leading,
  Color? Function(T)? iconColor,
  Color? Function(T)? iconBackgroundColor,
  TextStyle? titleStyle,
  TextStyle? subtitleStyle,
  double? iconSize,
  EdgeInsetsGeometry? iconPadding,
  BorderRadius? iconBorderRadius,
  double spacing = 10.0,
  CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
  Widget Function(T)? trailing,
  this.flex,
  this.minWidth,
  this.maxWidth,
  this.alignment,
  this.key,
  this.filterType = TFilterType.text,
  this.filterable = true,
  this.filterOperators,
  this.filterItems,
  this.filterDef,
  double Function(T data)? widthEstimator,
  this.flattenOnMobile = false,
  this.mobileKeyPrefixBuilder,
  this.keyValuesBuilder,
})  : map = title,
      widthEstimator = widthEstimator ??
          ((data) {
            final t = title(data);
            final sub = subtitle?.call(data);
            final tWidth = t != null ? TTableTheme.measureTextWidth(t) : 0.0;
            final sWidth = sub != null ? TTableTheme.measureTextWidth(sub) * 0.85 : 0.0;
            final textWidth = math.max(tWidth, sWidth);
            final lead = leading?.call(data) ?? icon?.call(data);
            final hasIcon = lead != null;
            final iconWidth = hasIcon ? ((iconSize ?? (lead is Widget ? 80.0 : 20.0)) + 12.0 + spacing) : 0.0;
            final trailingWidth = trailing != null ? 30.0 : 0.0;
            return iconWidth + textWidth + trailingWidth;
          }),
      builder = ((ctx, item, __) {
        final scope = TTableScope.maybeOf(ctx);
        final isDense = scope?.dense ?? false;
        final t = title(item.data);
        final sub = subtitle?.call(item.data);
        final lead = leading?.call(item.data) ?? icon?.call(item.data);
        final icColor = iconColor?.call(item.data);
        final icBgColor = iconBackgroundColor?.call(item.data);
        final tr = trailing?.call(item.data);

        final contentStyle = scope?.contentTextStyle ?? ctx.theme.tableTheme.rowCardTheme.contentTextStyle;
        final defaultTitleStyle = contentStyle?.adjust(
          sizeMultiplier: 1.015,
        );
        final defaultSubtitleStyle = contentStyle?.adjust(
          color: contentStyle.color?.adaptiveContrast(ctx, -0.5),
          sizeMultiplier: 0.85,
        );

        return TTile(
          title: t,
          subtitle: sub,
          icon: lead,
          iconColor: icColor,
          iconBackgroundColor: icBgColor,
          iconSize: isDense ? (iconSize != null ? iconSize * 0.8 : 16.0) : (iconSize ?? 20.0),
          iconPadding: isDense ? const EdgeInsets.all(6) : iconPadding,
          iconBorderRadius: iconBorderRadius,
          spacing: isDense ? spacing * 0.75 : spacing,
          crossAxisAlignment: crossAxisAlignment,
          titleStyle: titleStyle ?? defaultTitleStyle,
          subtitleStyle: subtitleStyle ?? defaultSubtitleStyle,
          trailing: tr,
        );
      });