getDefaultValue function

String? getDefaultValue(
  1. Element elem
)

Implementation

String? getDefaultValue(Element elem) {
  if (elem is ParameterElement && elem.defaultValueCode != null) {
    return elem.defaultValueCode;
  }
  final argAnnot = argInfoFromElement(elem);
  if (argAnnot.defaultCode != null) {
    return argAnnot.defaultCode;
  }

  final annotDefault = const TypeChecker.fromRuntime(Default)
      .firstAnnotationOfExact(elem)
      ?.getField('defaultValue');
  final annotJsonKey = const TypeChecker.fromRuntime(JsonKey)
      .firstAnnotationOfExact(elem)
      ?.getField('defaultValue');

  final annot = annotDefault ?? annotJsonKey;
  if (annot != null) {
    return dartObjectToString(annot);
  }
  return null;
}