TTableHeader<T, K>.toggle constructor

TTableHeader<T, K>.toggle(
  1. String text,
  2. bool? get(
    1. T
    ),
  3. void set(
    1. T,
    2. bool
    )?, {
  4. int? flex,
  5. double? minWidth,
  6. double? maxWidth,
  7. Alignment? alignment = Alignment.center,
  8. bool disabled = false,
  9. bool isDisabled(
    1. T data
    )?,
  10. String? key,
  11. TFilterType? filterType = TFilterType.boolean,
  12. bool filterable = true,
  13. List<TFilterOperator>? filterOperators,
  14. List? filterItems,
  15. TFilterDef<T>? filterDef,
  16. Color? color,
  17. Color? inactiveColor,
  18. double widthEstimator(
    1. T data
    )?,
  19. bool flattenOnMobile = false,
  20. String mobileKeyPrefixBuilder(
    1. String headerText,
    2. String childKey
    )?,
  21. List<TKeyValue> keyValuesBuilder(
    1. T data
    )?,
})

Creates a header for displaying and editing boolean values using TSwitch.

Implementation

TTableHeader.toggle(
  this.text,
  bool? Function(T) get,
  void Function(T, bool)? set, {
  this.flex,
  this.minWidth,
  this.maxWidth,
  this.alignment = Alignment.center,
  bool disabled = false,
  bool Function(T data)? isDisabled,
  this.key,
  this.filterType = TFilterType.boolean,
  this.filterable = true,
  this.filterOperators,
  this.filterItems,
  this.filterDef,
  Color? color,
  Color? inactiveColor,
  double Function(T data)? widthEstimator,
  this.flattenOnMobile = false,
  this.mobileKeyPrefixBuilder,
  this.keyValuesBuilder,
})  : map = get,
      widthEstimator = widthEstimator ?? ((_) => 48.0),
      builder = ((ctx, item, __) {
        final isDense = TTableScope.maybeOf(ctx)?.dense ?? false;
        final val = get(item.data) ?? false;
        final isOff = disabled || (isDisabled?.call(item.data) ?? false);

        return TSwitch(
          value: val,
          disabled: isOff,
          size: isDense ? TInputSize.xs : TInputSize.sm,
          color: color,
          inactiveColor: inactiveColor,
          onValueChanged: isOff || set == null ? null : (newVal) => set(item.data, newVal ?? false),
        );
      });