popScope static method

void popScope()

Removes the current scope from the stack of scopes.

This resets all pots in the current scope, triggers the disposer of each of them, and decrements the index number of the current scope.

final counterPot1 = Pot(() => Counter(0));
final counterPot2 = Pot(() => Counter(0));

void main() {
  // A new scope is added, and the `currentScope` turns 1.
  // The objects are not bound to the scope yet because
  // they haven't created.
  Pot.pushScope();

  // Object are created and set in the current scope 1.
  final counter1 = counterPot1();
  final counter2 = counterPot2();

  // The scope 1 is removed, and the objects in both
  // of the two pots are discarded.
  Pot.popScope();
}

If this is used in the root scope, the index number remains 0 although every pot in the scope is reset and its disposer is called.

Implementation

static void popScope() {
  StaticPot.scopes.clearScope(StaticPot.currentScope, keepScope: false);
}