attach static method

  1. @experimental
ContextToken attach(
  1. Context context, [
  2. Zone? zone
])

Attaches the given Context making it the active Context for the current Zone and all child Zones and returns a ContextToken that must be used to detach the Context.

When a Context is attached, it becomes active and overrides any Context that may otherwise be visible within that Zone. The Context will not be visible to any parent or sibling Zone. The Context will only be visible for the current Zone and any child Zone.

Implementation

@experimental
static ContextToken attach(Context context, [Zone? zone]) {
  final entry = ContextStackEntry(context);
  _stacks.update(zone ?? Zone.current, (stack) => stack..add(entry),
      ifAbsent: () => [entry]);
  return entry.token;
}