setComponentState function Null safety

void setComponentState(
  1. String name,
  2. String stateName,
  3. [int index = 0,
  4. bool asDefault = false]
)

Sets Figma2Flutter component state by Figma name and stateName

Implementation

void setComponentState(String name, String stateName,
    [int index = 0, bool asDefault = false]) {
  var elems = getElementsByName(name, index + 1);

  if (index < elems.length) {
    elems[index].widget?.setState(() {
      elems[index].widget.componentState = stateName;
      if (asDefault) elems[index].widget.defaultState = stateName;
    });
  }
}