iam 将 Riverpod 与 dartz 一起使用,nad iam 面临一个问题,即当使用带有我的函数的未来提供程序时,我也无法使用其中任何一个,我如何通过错误处理隔离我想要从函数中检索的内容!
我的提供商代码:
final activeCourseProvider =
FutureProvider.autoDispose.family<List<CourseModel>, int>((ref, yearId) {
final _courseRepository = ref.watch(coursesRepositoryProvider);
return _courseRepository.activeCourses(yearId);
});
我的功能代码:
Future<Either<ApiFailures, List<CourseModel>>> activeCourses(int yearId) async {
try{ final response = await http.post(
Uri.parse("http://msc-mu.com/api_verfication.php"),
body: {"flag": "selectcourses", "year": "$yearId"});
if (response.statusCode == 200) {
var l = json.decode(response.body) as List<dynamic>;
var courses = l.map((e) => CourseModel.fromJson(e)).toList();
return right(courses);
} else {
return left(ApiFailures.notFound());
}
} on SocketException {
return left(ApiFailures.noConnection());
} on HttpException {
return left(ApiFailures.notFound());
}
}
弹出的错误是:The return type 'Future<Either<ApiFailures, List<CourseModel>>>' isn't a 'Future<List<CourseModel>>', as required by the closure's context.