我想使用dartz函数样式并执行如下操作:
Either<Failure, Response> result = await remoteDataSource.request() // Future<Response> request();
.then((response) => Right(response))
.catchError((failure) => Left(failure));但我似乎不能这么做
错误:类型'Right< dynamic,Response>‘的值不能分配给'Either< Failure,Response>’类型的变量。
那么,如何以这种方式将Either与Future结合使用呢?
发布于 2020-03-08 17:29:27
这都是关于<generics>的。
.then((response) => Right(response)) // this is of type Right<dynamic,User>您必须向编译器提供所有正确的信息:
.then((response) => Right<Failure, Response>(response))
// or
.then((response) => right(response)) // a helper function which returns an Eitherhttps://stackoverflow.com/questions/59808248
复制相似问题