setVariables function

void setVariables(
  1. bool mounted,
  2. StateSetter setState,
  3. VoidCallback function
)

execute the function based on mounted call setState if mounted otherwise execute the function normally

Implementation

void setVariables(bool mounted, StateSetter setState, VoidCallback function){
  if(mounted){
    setState(function);
  }else{
    function();
  }
}