flutter 错误:状态错误:未来已经完成

ia2d9nvy  于 2023-05-23  发布在  Flutter
关注(0)|答案(1)|浏览(156)

我试图使用dio调用API,然后遇到了这个错误。
“Future _getHomeData()async { try { var homeDataResponse = await HomeService().getHomeData());

final classList = (homeDataResponse.data['classes']) as List;
  classes = classList.map((i) => ClassModel.fromJson(i)).toList();
  _storageService
      .writeSecureData(StorageItem("user_classes", jsonEncode(classes)));

  final examList = (homeDataResponse.data['exams']) as List;
  exams = examList.map((i) => Exam.fromJson(i)).toList();
  _storageService
      .writeSecureData(StorageItem("user_exams", jsonEncode(exams)));

  final taskList = (homeDataResponse.data['tasks']) as List;
  tasks = taskList.map((i) => Task.fromJson(i)).toList();
  _storageService
      .writeSecureData(StorageItem("user_tasks", jsonEncode(exams)));

  // for (var subject in subjects) {
  //   print("SUBJECtS ${subject.subjectName}");
  // }
} catch (error) {
  if (error is DioError) {
    throw Result.error(error.response?.data['message']);
  } else {
    throw Result.error(error.toString());
  }
}

} `

svmlkihl

svmlkihl1#

既然你写了一个评论,你使用了版本4.0.6,我可以告诉你,版本有一个已知的问题。这是解决在一个更高的版本,所以更新到至少5. 0的dio和一切将是好的。
您可以阅读关于here的问题和它的修复here

相关问题