getComponentText function Null safety

String getComponentText(
  1. String name,
  2. [int index = 0]
)

Returns text string currently being displayed in the element referenced by it's Figma name

Implementation

String getComponentText(String name, [int index = 0]) {
  var elems = getElementsByName(name, index + 1);
  if (index < elems.length) {
    var type = elems[index].widget?.widget?.componentType;
    if(type == 'TextInput' || type == 'MultiTextInput'){
      return elems[index].widget?.controller?.text;
    }else{
      return elems[index].widget?.characters;
    }
  }
  return "";
}