Use Either with Future
1,453
It's all about <generics>
.
.then((response) => Right(response)) // this is of type Right<dynamic,User>
You got to give the compiler all the proper information:
.then((response) => Right<Failure, Response>(response))
// or
.then((response) => right(response)) // a helper function which returns an Either
Comments
-
konstantin_doncov over 1 year
I want to use
dartz
functional style and do something like this:Either<Failure, Response> result = await remoteDataSource.request() // Future<Response> request(); .then((response) => Right(response)) .catchError((failure) => Left(failure));
But it seems that I can't do this:
error: A value of type 'Right< dynamic, Response>' can't be assigned to a variable of type 'Either< Failure, Response>'.
So, how can I use
Either
withFuture
this way? -
Reiko Dev about 3 yearsHelped a lot bro, ty