trash method

  1. @nonVirtual
void trash(
  1. Cleanup cleanup
)
inherited

Defers cleanup until this build stops being current.

The trash is emptied right before every rebuild and once at unmount, so each build cleans up after the one it replaced:

painter = TextPainter(text: span);
trash(painter.dispose);

Emptied most-recent-first, so a teardown that emits must be trashed after the handlers it will notify. Only valid inside this node's own build.

Implementation

@nonVirtual
void trash(Cleanup cleanup) {
  assert(
    identical(_building, this),
    'trash() is only available inside this node\'s own build.',
  );

  (_cleanups ??= []).add(cleanup);
}