Skip to content

Instantly share code, notes, and snippets.

@PlugFox
Created June 3, 2022 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PlugFox/d35b4beb298e62819152cd259d4f44ca to your computer and use it in GitHub Desktop.
Save PlugFox/d35b4beb298e62819152cd259d4f44ca to your computer and use it in GitHub Desktop.
Providing data using zones
/*
* Providing data using zones
* https://gist.github.com/PlugFox/d35b4beb298e62819152cd259d4f44ca
* https://dartpad.dev/d35b4beb298e62819152cd259d4f44ca
* Matiunin Mikhail <plugfox@gmail.com>, 03 June 2022
*/
import 'dart:async';
void main() {
functionA(); // prints '<null>'
runZoned<void>(
() => functionA(), // prints 'Zone'
zoneValues: <Object?, Object?>{
#my.zone.key: 'Zone',
},
);
functionA(); // prints '<null>'
}
Future<void> functionA() async {
functionB();
}
Future<void> functionB() async {
print(Zone.current[#my.zone.key] ?? '<null>');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment