Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int idx = 0;
- Future<int> getValueExceptionOnEnd() async {
- if (idx < 4) {
- return idx++;
- } else {
- throw RangeError("no more ints for you!");
- }
- }
- Stream<int> onlyWorksOnDesktop() async* {
- try {
- while (true) {
- yield await getValueExceptionOnEnd();
- }
- } on RangeError {
- print("all done! dart should close the stream after this.");
- return;
- }
- }
- Future<int?> _allPlatformsHelper() async {
- try {
- return await getValueExceptionOnEnd();
- } on RangeError {
- return null;
- }
- }
- Stream<int> worksOnAllPlatforms() async* {
- while (true) {
- final value = await _allPlatformsHelper();
- if (value == null) break;
- yield value;
- }
- print("all done! dart should close the stream after this.");
- }
- void bugDemo() async {
- idx = 0;
- await for (var value in worksOnAllPlatforms()) {
- print(value);
- }
- print("worksOnAllPlatforms()'s stream closed.");
- idx = 0;
- await for (var value in onlyWorksOnDesktop()) {
- print(value);
- }
- //This never runs when developing for the web with flutter
- //(though, interestingly, it does work with dart2js.)
- print("onlyWorksOnDesktop()'s stream closed.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement