Created
June 3, 2022 14:10
-
-
Save PlugFox/d35b4beb298e62819152cd259d4f44ca to your computer and use it in GitHub Desktop.
Providing data using zones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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