copyWith method

GridColumn<T> copyWith({
  1. String? field,
  2. String? title,
  3. ValueGetter<T>? value,
  4. ColumnType? type,
  5. double? width,
  6. double? minWidth,
  7. double? maxWidth,
  8. ColumnAlign? align,
  9. bool clearAlign = false,
  10. ColumnPin? pin,
  11. bool? visible,
  12. bool? sortable,
  13. bool? filterable,
  14. bool? resizable,
  15. bool? groupable,
  16. ValueFormatter? format,
  17. bool clearFormat = false,
  18. Comparator<Object?>? comparator,
  19. bool clearComparator = false,
  20. ValueSetter<T>? setValue,
  21. bool clearSetValue = false,
  22. ValueValidator? validator,
  23. bool clearValidator = false,
  24. String? tooltip,
  25. bool clearTooltip = false,
  26. CellRule? rule,
  27. bool clearRule = false,
  28. Object? sortKey(
    1. T row
    )?,
  29. bool clearSortKey = false,
})

A copy of this column with the given fields replaced.

A null argument means "keep what is there", which is why every nullable field has a clear flag beside it: without one there was no way to remove a callback, so a column with a setValue could never be made read-only and a rule could never be taken off a column.

Changing field also regenerates the default Map accessor, so a column declared without a value: reads the new field rather than quietly keeping the old one.

Implementation

GridColumn<T> copyWith({
  String? field,
  String? title,
  ValueGetter<T>? value,
  ColumnType? type,
  double? width,
  double? minWidth,
  double? maxWidth,
  ColumnAlign? align,
  bool clearAlign = false,
  ColumnPin? pin,
  bool? visible,
  bool? sortable,
  bool? filterable,
  bool? resizable,
  bool? groupable,
  ValueFormatter? format,
  bool clearFormat = false,
  Comparator<Object?>? comparator,
  bool clearComparator = false,
  ValueSetter<T>? setValue,
  bool clearSetValue = false,
  ValueValidator? validator,
  bool clearValidator = false,
  String? tooltip,
  bool clearTooltip = false,
  CellRule? rule,
  bool clearRule = false,
  Object? Function(T row)? sortKey,
  bool clearSortKey = false,
}) {
  final nextField = field ?? this.field;
  // A column that never had an accessor of its own reads whichever field it
  // now names; one that was given an accessor keeps it.
  final nextValue = value ??
      (_usesDefaultValue && nextField != this.field ? null : this.value);
  return GridColumn<T>(
    field: nextField,
    title: title ?? this.title,
    value: nextValue,
    type: type ?? this.type,
    width: width ?? this.width,
    minWidth: minWidth ?? this.minWidth,
    maxWidth: maxWidth ?? this.maxWidth,
    align: clearAlign ? null : (align ?? this.align),
    pin: pin ?? this.pin,
    visible: visible ?? this.visible,
    sortable: sortable ?? this.sortable,
    filterable: filterable ?? this.filterable,
    resizable: resizable ?? this.resizable,
    groupable: groupable ?? this.groupable,
    format: clearFormat ? null : (format ?? this.format),
    comparator: clearComparator ? null : (comparator ?? this.comparator),
    setValue: clearSetValue ? null : (setValue ?? this.setValue),
    validator: clearValidator ? null : (validator ?? this.validator),
    tooltip: clearTooltip ? null : (tooltip ?? this.tooltip),
    rule: clearRule ? null : (rule ?? this.rule),
    sortKey: clearSortKey ? null : (sortKey ?? this.sortKey),
  );
}