getElementValue function

String? getElementValue(
  1. Element element, [
  2. String? def
])

Gets the element value depending of identified type.

If the resolved value is null or empty, and def is not null, it will return def.

Implementation

String? getElementValue(Element element, [String? def]) {
  String? value;

  if (element is InputElement) {
    value = element.value;
  } else if (element is CanvasImageSource) {
    value = getElementSRC(element);
  } else if (element is CheckboxInputElement) {
    value = element.checked! ? 'true' : 'false';
  } else if (element is TextAreaElement) {
    value = element.value;
  } else if (isElementWithSRC(element)) {
    value = getElementSRC(element);
  } else if (isElementWithHREF(element)) {
    value = getElementHREF(element);
  } else {
    value = element.text;
  }

  return def != null && isEmptyObject(value) ? def : value;
}