TTableHeader<T, K>.editable constructor
TTableHeader<T, K>.editable (
- String text, {
- required Object? get(
- T
- required Widget builder(
- BuildContext ctx,
- T data
- Widget displayBuilder(
- BuildContext ctx,
- T data
- String? error(
- T
- String? placeholder,
- int? flex,
- double? minWidth,
- double? maxWidth,
- Alignment? alignment,
- String? key,
- TFilterType? filterType,
- bool filterable = true,
- List<
TFilterOperator> ? filterOperators, - List? filterItems,
- TFilterDef<
T> ? filterDef, - double widthEstimator(
- T data
- bool flattenOnMobile = false,
- String mobileKeyPrefixBuilder()?,
- List<
TKeyValue> keyValuesBuilder(- T data
Creates an editable cell header.
Implementation
TTableHeader.editable(
this.text, {
required Object? Function(T) get,
required Widget Function(BuildContext ctx, T data) builder,
Widget Function(BuildContext ctx, T data)? displayBuilder,
String? Function(T data)? error,
String? placeholder,
this.flex,
this.minWidth,
this.maxWidth,
this.alignment,
this.key,
this.filterType,
this.filterable = true,
this.filterOperators,
this.filterItems,
this.filterDef,
this.widthEstimator,
this.flattenOnMobile = false,
this.mobileKeyPrefixBuilder,
this.keyValuesBuilder,
}) : map = get,
builder = ((ctx, item, index) {
final cellScope = TTableCellScope.maybeScopeOf(ctx);
final activeCursor = cellScope?.activeCellNotifier ?? TTableCellScope.maybeOf(ctx);
final data = item.data;
final cellKey = "${item.key}_$text";
final colors = ctx.colors;
final cellError = error?.call(data) ?? cellScope?.getError(data, text, cellKey);
final hasError = cellError != null && cellError.isNotEmpty;
final textStyle = TTableScope.maybeOf(ctx)?.contentTextStyle ?? ctx.theme.tableTheme.rowCardTheme.contentTextStyle;
Widget buildDisplay() {
if (displayBuilder != null) {
return displayBuilder(ctx, data);
}
final rawVal = get(data);
final displayStr = rawVal?.toString() ?? '';
final isEmpty = displayStr.trim().isEmpty;
if (hasError) {
return TTooltip(
message: cellError,
waitDuration: const Duration(milliseconds: 200),
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Flexible(
child: Text(
isEmpty ? (placeholder ?? '—') : displayStr,
style: textStyle?.copyWith(
color: colors.error,
fontWeight: FontWeight.w600,
) ??
TextStyle(
color: colors.error,
fontWeight: FontWeight.w600,
),
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 4),
TIcon.raw(
HugeIcons.strokeRoundedAlert02,
size: 14,
color: colors.error,
),
],
),
);
}
if (isEmpty && placeholder != null) {
return Text(
placeholder,
style: textStyle?.copyWith(
color: colors.onSurfaceVariant.withAlpha(100),
fontStyle: FontStyle.italic,
) ??
TextStyle(
color: colors.onSurfaceVariant.withAlpha(100),
fontStyle: FontStyle.italic,
),
overflow: TextOverflow.ellipsis,
);
}
return Text(
displayStr,
style: textStyle,
overflow: TextOverflow.ellipsis,
);
}
Widget buildEditor() {
final editorWidget = builder(ctx, data);
if (hasError) {
return TTooltip(
message: cellError,
waitDuration: const Duration(milliseconds: 200),
child: editorWidget,
);
}
return editorWidget;
}
if (activeCursor != null) {
return InkWell(
focusColor: Colors.transparent,
splashColor: Colors.transparent,
onTap: () => activeCursor.value = cellKey,
child: ValueListenableBuilder(
valueListenable: activeCursor,
builder: (ctx, active, _) => active == cellKey ? buildEditor() : buildDisplay(),
),
);
}
return buildDisplay();
});