fixFieldName function

String fixFieldName(
  1. String name, {
  2. required TypeDefinition typeDef,
  3. bool privateField = false,
})

Implementation

String fixFieldName(String name,
    {required TypeDefinition typeDef, bool privateField = false}) {
  var properName = name;
  if (name.startsWith('_') || name.startsWith(new RegExp(r'[0-9]'))) {
    final firstCharType = typeDef.name.substring(0, 1).toLowerCase();
    properName = '$firstCharType$name';
  }
  final fieldName = camelCaseFirstLower(properName);
  if (privateField) {
    return '_$fieldName';
  }
  return fieldName;
}