Skip to content

Commit

Permalink
update: history page layout
Browse files Browse the repository at this point in the history
  • Loading branch information
uswebk committed Sep 10, 2023
1 parent 182455e commit 1ac571d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/feature/dashboard/provider/answer_stats_provider.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:coodig_mobile/model/answer_stats.dart';
import 'package:coodig_mobile/provider/answered_quiz.dart';
import 'package:coodig_mobile/service/quiz_service.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

final answerStatsProvider = FutureProvider<AnswerStats>((ref) async {
ref.watch(answeredQuizNotifierProvider);
final quizService = ref.watch(quizServiceProvider);
final stats = await quizService.answerStats();

Expand Down
13 changes: 4 additions & 9 deletions lib/feature/history/provider/history_provider.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import 'package:coodig_mobile/enum/screen.dart';
import 'package:coodig_mobile/model/quiz.dart';
import 'package:coodig_mobile/provider/page_index_provider.dart';
import 'package:coodig_mobile/provider/answered_quiz.dart';
import 'package:coodig_mobile/service/quiz_service.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

final historyFutureProvider = FutureProvider<List<QuizAnswer>>((ref) async {
ScreenItem screen = ref.watch(screenItemProvider);

if (screen == ScreenItem.history) {
return await ref.watch(quizServiceProvider).history();
}

return [];
ref.watch(answeredQuizNotifierProvider);
final history = await ref.watch(quizServiceProvider).history();
return history;
});
4 changes: 3 additions & 1 deletion lib/feature/learning/widgets/quiz_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:coodig_mobile/feature/learning/widgets/error_message.dart';
import 'package:coodig_mobile/feature/learning/widgets/floating_button.dart';
import 'package:coodig_mobile/feature/learning/widgets/question.dart';
import 'package:coodig_mobile/model/quiz.dart';
import 'package:coodig_mobile/provider/answered_quiz.dart';
import 'package:coodig_mobile/provider/quiz_provider.dart';
import 'package:coodig_mobile/service/quiz_service.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -119,8 +120,9 @@ class QuizPanel extends HookConsumerWidget {
List<int> answerIds = selectedChoices.value;
bool isCorrect = quizService.isCorrectQuiz(correctIds.value, answerIds);
QuizAnswer? result = await quizService.answer(quizId.value as int, answerIds, isCorrect);

isCorrectAnswer.value = result.isCorrect;
// store answered
ref.read(answeredQuizNotifierProvider.notifier).answer(data);
} catch (e) {
debugPrint(e.toString());
} finally {
Expand Down

0 comments on commit 1ac571d

Please sign in to comment.