Collapse runs of whitespace into single spaces and trim.
String normalizeWhitespace(String text) { return text.replaceAll(RegExp(r'\s+'), ' ').trim(); }