In my bloc state I have this:
Option<Either<T, Stream<T>>> optionFailureOrStream,
It' can be empty (Option
) or have an error
or a stream
.
In my bloc
I yielding this with optionOf
like this:
yield state.copyWith(optionFailureOrStream: optionOf(failureOrStream));
Now in my Widget I want to know if it has a value and if it has a value, I want to fold them to return two different screens:
if (state.optionFailureOrStream.isSome()) {
final optionFailureOrStream = state.optionFailureOrStream;
optionFailureOrStream.map((a) => a.fold(
(failure) => FailureWidget(failure: failure),
(stream) => buildSaved(stream, context)));
}
But somehow I can't get rid of the Option<T>
type. It complains about the wrong type.
The return type 'Option<Widget>' isn't a 'Widget', as required by the closure's context.dart(return_of_invalid_type_from_closure)
I assume there is a really easy way to do this. I am having a real hard time finding any dart/flutter related manuals and the source code of dartz
isn't that self-explaining, if you are new to these concepts.