dispose method

  1. @protected
  2. @override
  3. @mustCallSuper
void dispose()
inherited

The framework calls this method when this StateX object will never build again and will be disposed of with garbage collection.

Implementation

@protected
@override
@mustCallSuper
void dispose() {
  /// The State object's lifecycle is terminated.
  /// **IMPORTANT** You will not know when this will run
  /// It's to the Flutter engines discretion. deactivate() is more reliable.
  /// Subclasses should override deactivate() method instead
  /// to release any resources  (e.g., stop any active animations).

  /// Indicate this State object is terminated.
  disposed = true;

  // No 'setState()' functions are allowed to fully function at this point.
  _setStateAllowed = false;

  for (final con in _controllerList) {
    con.dispose();
  }

  // Remove any 'StateXController' reference
  _controller = null;

  // Clear the list of Controllers.
  _mapControllerByType.clear();

  // // In some cases, the setState() will be called again! gp
  _setStateAllowed = true;

  // In some cases, if then reinserted back in another part of the tree
  // the build is called, and so setState() is not necessary.
  _setStateRequested = false;

  super.dispose();
}