snakeCase static method

String snakeCase(
  1. String input
)

Convert a camelized string to snake_case e.g. aLongFieldName becomes a_long_field_name Taken from json_serializable

Implementation

static String snakeCase(String input) {
  return input.replaceAllMapped(RegExp('[A-Z]'), (match) {
    var lower = match.group(0)!.toLowerCase();

    if (match.start > 0) {
      lower = '_$lower';
    }

    return lower;
  });
}