setstate

error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree | flutter

memory leak error/warning

This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().

Just add this line of code before calling the setstate.

if (!mounted) {
  return;
}
// your setState here