Closed Mike278 closed 2 years ago
I also had this issue
See also: https://github.com/dart-lang/web_socket_channel/pull/65, specifically
A recent change in the Dart SDK updated Socket to implement Stream
rather than Stream<List >. This forwards compatible change calls StreamTransformer.bind() rather than Stream.transform(), thus putting the stream in a covariant position and allowing for the transition to Uint8List.
Following this approach, the error goes away if I replace return stream.switchMap<R?>(f);
with return SwitchMapStreamTransformer<T?, R?>(f).bind(stream);
In mapNotNull
and whereNotNull
I have already used bind
instead of transform
. I will update others
Repro:
The error goes away if you swap the imports.
Reading up a bit on the issue indicates that this is due to Dart's covariant class generics. There are some sharp edges when it comes to classes that handle generics as both function arguments ("in" position) and return types ("out" position) or both - which is exactly what StreamTransformers do. Some relevant links: