My Flutter/Dart string utilities functions

As a brief note, these are some string utility functions that I’ve been using in a Flutter/Dart app. I keep them in a file named string_utils.dart:

// my StringUtils functions

String stripMargin(String s) {
  return s.splitMapJoin(
      RegExp(r'^', multiLine: true),
      onMatch: (_) => '\n',
      onNonMatch: (n) => n.trim(),
  );
}

String replaceAllNewlinesWithSpaces(String s) {
  return s.replaceAll('\n', ' ');
}

String reduceMultipleBlanksToOne(String s) {
  return s.replaceAll(RegExp(' +'), ' ');
}

/// This works well with a multiline string and a Text widget
/// in an AlertDialog.
String convertMultilineStringToOneParagraph(String multilineString) {
  return reduceMultipleBlanksToOne(
    stripMargin(
      replaceNewlineWithSpace(multilineString)
    )
  ).trim();
}

If you prefer, you can keep those in a StringUtils object, but that is not the current Dart/Flutter way (idiom).