humanizeField function

String humanizeField(
  1. String field
)

created_at → "Created at", category.name → "Category name": split on _/., capitalise only the first word. Deliberately not full title case — a table header reads as a phrase, not a heading.

Implementation

String humanizeField(String field) {
  final words = field
      .split(RegExp('[._]'))
      .where((word) => word.isNotEmpty)
      .toList();
  if (words.isEmpty) return field;

  final first = words.first;
  final capitalised = first[0].toUpperCase() + first.substring(1);
  return [capitalised, ...words.skip(1)].join(' ');
}