dio
dio copied to clipboard
Stream.fromIterable(things).asyncMap(convert) Skipping elements of the list.
New Issue Checklist
- [x] I have searched for a similar issue in the project and found none
Issue Info
| Info | Value | |
|---|---|---|
| Platform Name | flutter | |
| Platform Version | 3.0.5 | |
| Xcode Version | Xcode 13.2.1 | |
| Repro rate | all the time (100%) | |
| Repro with our demo prj | I don't think this has been used there | |
| Demo project link | link to the demo project that highlights the issue |
Issue Description and Steps
I am trying to use a Stream.fromIterable(things).asyncMap(convert);
Future<TouchPoints?> convert(TouchPoints? thing) async {
await Future.delayed(const Duration(milliseconds: 2));
// changing the delay for function does affect the
// accuracy of painter results.
// set this to 5 milliseconds and then there will be a smooth line, which is not required here.
// set this to 25 milliseconds, or more, and then there will be a dotted line of x = y.
return thing;
}
Stream<TouchPoints?> doStuff(List<TouchPoints?> things) {
return Stream.fromIterable(things).asyncMap(convert);
// This asyncMap seems to be the culprit here, My Guess!...
}
This returned stream is used to stream points, used along with a custom painter.
The issue here is that with Future.delayed(const Duration(milliseconds: 2));, stream snapshot.data doesn't returns the complete array thus we see results like:
but when used with Future.delayed(const Duration(milliseconds: 25));, or greater than 25 milliseconds, the results are as expected. See picture below:
Note*: not looking for alternatives to draw a dotted line here, i am curious to find out why does asyncMap skips the elements of the array here, or might some other issue.