toCamelCase function

String toCamelCase(
  1. String str
)

Implementation

String toCamelCase(String str) {
  // Split the string by underscores.
  List<String> parts = str.split('_');

  // Capitalize the first letter of each part except the first one,
  // and concatenate them back into a single string.
  String camelCase = parts[0].toLowerCase();
  for (int i = 1; i < parts.length; i++) {
    // Capitalize the first letter of the current part and add it to the result.
    camelCase += parts[i].substring(0, 1).toUpperCase() +
        parts[i].substring(1).toLowerCase();
  }

  return camelCase;
}