Zone class
A zone represents an environment that remains stable across asynchronous calls.
Code is always executed in the context of a zone, available as Zone.current. The initial main function runs in the context of the default zone (Zone.root). Code can be run in a different zone using either runZoned, to create a new zone, or Zone.run to run code in the context of an existing zone which was created earlier using Zone.fork.
Developers can create a new zone that overrides some of the functionality of an existing zone. For example, custom zones can replace of modify the behavior of print, timers, microtasks or how uncaught errors are handled.
The Zone class is not subclassable, but users can provide custom zones by forking an existing zone (usually Zone.current) with a ZoneSpecification. This is similar to creating a new class that extends the base Zone class and that overrides some methods, except without actually creating a new class. Instead the overriding methods are provided as functions that explicitly take the equivalent of their own class, the "super" class and the this object as parameters.
Asynchronous callbacks always run in the context of the zone where they were scheduled. This is implemented using two steps:
- the callback is first registered using one of registerCallback, registerUnaryCallback, or registerBinaryCallback. This allows the zone to record that a callback exists and potentially modify it (by returning a different callback). The code doing the registration (e.g., 
Future.then) also remembers the current zone so that it can later run the callback in that zone. - At a later point the registered callback is run in the remembered zone, using one of run, runUnary or runBinary.
 
This is all handled internally by the platform code and most users don't need to worry about it. However, developers of new asynchronous operations, provided by the underlying system or through native extensions, must follow the protocol to be zone compatible.
For convenience, zones provide bindCallback (and the corresponding bindUnaryCallback and bindBinaryCallback) to make it easier to respect the zone contract: these functions first invoke the corresponding register functions and then wrap the returned function so that it runs in the current zone when it is later asynchronously invoked.
Similarly, zones provide bindCallbackGuarded (and the corresponding bindUnaryCallbackGuarded and bindBinaryCallbackGuarded), when the callback should be invoked through Zone.runGuarded.
Properties
-  errorZone → Zone read-only
 - The error zone is responsible for dealing with uncaught errors. [...]
 -  hashCode → int read-only, inherited
 - The hash code for this object. [...]
 -  parent → Zone? read-only
 - The parent zone of the this zone. [...]
 -  runtimeType → Type read-only, inherited
 - A representation of the runtime type of the object.
 
Methods
-  bindBinaryCallback<
R, T1, T2> (R callback(T1 argument1, T2 argument2)) → ZoneBinaryCallback< R, T1, T2>  -  Registers the provided 
callbackand returns a function that will execute in this zone. [...] -  bindBinaryCallbackGuarded<
T1, T2> (void callback(T1 argument1, T2 argument2)) → void Function(T1, T2)  -  Registers the provided 
callbackand returns a function that will execute in this zone. [...] -  bindCallback<
R> (R callback()) → ZoneCallback< R>  -  Registers the provided 
callbackand returns a function that will execute in this zone. [...] -  bindCallbackGuarded(
void callback()) → void Function()  -  Registers the provided 
callbackand returns a function that will execute in this zone. [...] -  bindUnaryCallback<
R, T> (R callback(T argument)) → ZoneUnaryCallback< R, T>  -  Registers the provided 
callbackand returns a function that will execute in this zone. [...] -  bindUnaryCallbackGuarded<
T> (void callback(T argument)) → void Function(T)  -  Registers the provided 
callbackand returns a function that will execute in this zone. [...] -  createPeriodicTimer(
Duration period, void callback(Timer timer)) → Timer  - Creates a periodic Timer where the callback is executed in this zone.
 -  createTimer(
Duration duration, void callback()) → Timer  - Creates a Timer where the callback is executed in this zone.
 -  errorCallback(
Object error, StackTrace? stackTrace) → AsyncError?  - Intercepts errors when added programmatically to a Future or Stream. [...]
 -  fork(
{ZoneSpecification? specification, Map< Object?, Object?> ? zoneValues}) → Zone - Creates a new zone as a child zone of this zone. [...]
 -  handleUncaughtError(
Object error, StackTrace stackTrace) → void  - Handles uncaught asynchronous errors. [...]
 -  inSameErrorZone(
Zone otherZone) → bool  -  Whether this zone and 
otherZoneare in the same error zone. [...] -  noSuchMethod(
Invocation invocation) → dynamic inherited - Invoked when a non-existent method or property is accessed. [...]
 -  print(
String line) → void  -  Prints the given 
line. [...] -  registerBinaryCallback<
R, T1, T2> (R callback(T1 arg1, T2 arg2)) → ZoneBinaryCallback< R, T1, T2>  - Registers the given callback in this zone. [...]
 -  registerCallback<
R> (R callback()) → ZoneCallback< R>  - Registers the given callback in this zone. [...]
 -  registerUnaryCallback<
R, T> (R callback(T arg)) → ZoneUnaryCallback< R, T>  - Registers the given callback in this zone. [...]
 -  run<
R> (R action()) → R  -  Executes 
actionin this zone. [...] -  runBinary<
R, T1, T2> (R action(T1 argument1, T2 argument2), T1 argument1, T2 argument2) → R  -  Executes the given 
actionwithargument1andargument2in this zone. [...] -  runBinaryGuarded<
T1, T2> (void action(T1 argument1, T2 argument2), T1 argument1, T2 argument2) → void  -  Executes the given 
actionwithargument1andargument2in this zone and catches synchronous errors. [...] -  runGuarded(
void action()) → void  -  Executes the given 
actionin this zone and catches synchronous errors. [...] -  runUnary<
R, T> (R action(T argument), T argument) → R  -  Executes the given 
actionwithargumentin this zone. [...] -  runUnaryGuarded<
T> (void action(T argument), T argument) → void  -  Executes the given 
actionwithargumentin this zone and catches synchronous errors. [...] -  scheduleMicrotask(
void callback()) → void  -  Runs 
callbackasynchronously in this zone. [...] -  toString(
) → String inherited - A string representation of this object. [...]
 
Operators
-  operator ==(
Object other) → bool inherited - The equality operator. [...]
 -  operator [](
Object? key) → dynamic  -  Retrieves the zone-value associated with 
key. [...] 
Static Properties
Constants
    © 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
    https://api.dart.dev/stable/2.13.0/dart-async/Zone-class.html