setComponentText function Null safety

void setComponentText(
  1. String name,
  2. String text,
  3. [int index = 0]
)

Sets text to be displayed in the element referenced by it's Figma name Only works on TEXT Figma nodes

Implementation

void setComponentText(String name, String text, [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'){
      elems[index].widget?.setState(() {
        elems[index].widget?.controller?.text = text;
      });
    }else{
      elems[index].widget?.setState(() {
        elems[index].widget?.characters = text;
      });
    }
  }
}