我需要在我的插件中从EventChannel创建一个新的Stream<Foo>
,我尝试这样做,但我有Stream<Foo?>
,我必须为过滤所有空值并返回为Stream<Foo>
做什么
Stream<Foo> get getStream {
return _eventChannel
.receiveBroadcastStream()
.map<Foo?>((dynamic status) {
assert(
status is int,
'status should be int, but it is ${status.runtimeType}',
);
if (status is int) {
return FooStatus.valueOf(status); // can be null
}
}).helpMeFiltredLikeThis<Foo>((Foo? value) => value != null); // how i can do some like this
}
您可以在结尾处使用cast
:
final nonNullableStream = nullableStream.cast<Foo>();