diff --git a/lib/page/forum/quiz.dart b/lib/page/forum/quiz.dart index 28729edd..6172d321 100644 --- a/lib/page/forum/quiz.dart +++ b/lib/page/forum/quiz.dart @@ -30,6 +30,7 @@ class OTQuizWidgetState extends State { int questionIndex = 0, prevQuestionIndex = 0; int displayIndex = 1, displayTotalIndex = 1; late List? questions; + late int version; late List? indexes; List? answers; OTQuizDisplayTypes displayType = OTQuizDisplayTypes.WELCOME_PAGE; @@ -71,8 +72,10 @@ class OTQuizWidgetState extends State { child: PlatformElevatedButton( padding: const EdgeInsets.all(20.0), onPressed: () async { - questions = await ForumRepository.getInstance() + final result = await ForumRepository.getInstance() .getPostRegisterQuestions(); + questions = result.$1; + version = result.$2; if (questions != null) { indexes = List.generate(questions!.length, (index) => index); @@ -182,7 +185,7 @@ class OTQuizWidgetState extends State { return; } else { final errorList = - await ForumRepository.getInstance().submitAnswers(answers!); + await ForumRepository.getInstance().submitAnswers(answers!, version); // Have trouble submitting if (errorList == null) { diff --git a/lib/repository/forum/forum_repository.dart b/lib/repository/forum/forum_repository.dart index b56afbe1..07e601f3 100644 --- a/lib/repository/forum/forum_repository.dart +++ b/lib/repository/forum/forum_repository.dart @@ -833,26 +833,26 @@ class ForumRepository extends BaseRepositoryWithDio { return resp.statusCode; } - Future?> getPostRegisterQuestions() async { + Future<(List?, int)> getPostRegisterQuestions() async { final Response> response = await dio.get( "$_BASE_AUTH_URL/register/questions", options: Options(headers: _tokenHeader)); - final questionList = response.data?["questions"] + final List? questionList = response.data?["questions"] .map((e) => QuizQuestion.fromJson(e)) - .toList(); - final length = response.data?["spec"]["number_of_questions"] as int; - - assert(questionList?.length == length); - return questionList.cast(); + .toList() + .cast(); + final int version = response.data?["version"]; + return (questionList, version); } // Empty list means all-correct - Future?> submitAnswers(List answers) async { + Future?> submitAnswers( + List answers, int version) async { final Response> response = await dio.post( "$_BASE_AUTH_URL/register/questions/_answer", data: { "answers": answers.map((e) => e.toJson()).toList(), - "version": 0 + "version": version }, options: Options(headers: _tokenHeader)); diff --git a/pubspec.yaml b/pubspec.yaml index 703314c4..7535b678 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,10 @@ name: dan_xi description: Maybe the best all-rounded service app for Fudan University students. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: "none" # Remove this line if you wish to publish to pub.dev version: 1.4.4+341 environment: - sdk: '>=3.0.0' + sdk: ">=3.0.0" dependencies: flutter: @@ -70,8 +70,8 @@ dependencies: file_picker: ^8.0.6 cached_network_image: ^3.2.1 flutter_typeahead: ^5.2.0 - collection: '>=1.15.0 <2.0.0' - meta: '>=1.3.0 <2.0.0' + collection: ">=1.15.0 <2.0.0" + meta: ">=1.3.0 <2.0.0" flutter_layout_grid: ^2.0.1 flutter_js: ^0.8.0 flutter_math_fork: ^0.7.2