私はdartzでriverpodを使用していますが、私の関数で将来のプロバイダーを使用するときに、どちらにも手が届かないという問題に直面しています.エラー処理で関数から取得したいものをどのように分離できますか!
私のプロバイダーコード:
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.