-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquiz.dart
51 lines (42 loc) · 1.22 KB
/
quiz.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import 'package:cloud_firestore/cloud_firestore.dart';
class Quiz{
String questionString;
String choice1String;
String choice2String;
String choice3String;
String choice4String;
String commentaryString;
int correctAnswerNum;
int userAnswerNum;
Quiz(QueryDocumentSnapshot queryDocumentSnapshot){
var data = queryDocumentSnapshot.data();
questionString = data['question'];
choice1String = data['choice1'];
choice2String = data['choice2'];
choice3String = data['choice3'];
choice4String = data['choice4'];
correctAnswerNum = data['answer'];
userAnswerNum = 0;
commentaryString = data['commentary'];
}
void inputAnswer(int answerNum){
userAnswerNum = answerNum;
}
bool IsCorrectAnswer(){
return correctAnswerNum == userAnswerNum;
}
}
class QuizList{
static List<Quiz> quizList = List<Quiz>();
static void PrepareQuizList(String quizEventDocumentId) async {
quizList.clear();
CollectionReference ref = FirebaseFirestore.instance
.collection('quiz-test')
.doc(quizEventDocumentId)
.collection('quiz_1');
var querySnapshot = await ref.get();
querySnapshot.docs.forEach((element) {
quizList.add(Quiz(element));
});
}
}