getFieldLabel method

  1. @override
Future<String?> getFieldLabel({
  1. required String doctype,
  2. required String fieldName,
})
override

Returns the label of a field in Frappé.

If the field exists withing the doctype, the title case equivalent is returned.

For example, full_name of User doctype will return 'Full Name'.

If the doctype or the field doesn't exist, fieldName is returned.

Implementation

@override
Future<String?> getFieldLabel(
    {required String doctype, required String fieldName}) async {
  final response = await getDocMeta(doctype: doctype);
  dynamic label = fieldName;
  final standardFields = <String, String>{
    'name': 'Name',
    'docStatus': 'DocStatus'
  };
  if (standardFields.containsKey(fieldName)) {
    label = standardFields[fieldName];
  }
  if (!response.isSuccess) {
    config.logger.e('getFieldLabel: Failed to read docmeta');
  } else {
    final docMeta = response.data!;
    var field =
        docMeta.fields!.singleWhereOrNull((f) => f.fieldName == fieldName);

    field ??= docMeta.disabledFields!
        .singleWhereOrNull((f) => f.fieldName == fieldName);
    if (field != null) {
      label = field.label;
    } else {
      label = toTitleCase(label);
    }
  }
  return config.coreInstance.translate.getMessage(txt: label);
}