unwatchElement function

void unwatchElement(
  1. BuildContext context, {
  2. bool watch = true,
  3. bool listen = true,
})

Remove all subscribers for a given context

Implementation

void unwatchElement(
  BuildContext context, {
  bool watch = true,
  bool listen = true,
}) {
  // Remove keys for element hashcode
  final items = [
    if (watch)
      ..._watchSubscribers.entries.where((e) => e.key.$1 == context.hashCode),
    if (listen)
      ..._listenSubscribers.entries.where((e) => e.key.$1 == context.hashCode),
  ];
  for (final item in items) {
    final (_, cleanup) = item.value;
    cleanup();
  }
  if (watch) {
    _watchSubscribers.removeWhere((key, value) => key.$1 == context.hashCode);
  }
  if (listen) {
    _listenSubscribers.removeWhere((key, value) => key.$1 == context.hashCode);
  }
}