Skip to content

Commit

Permalink
Quiz Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Swaraj9 committed Jun 7, 2024
1 parent 0b22fcc commit df9b376
Showing 1 changed file with 46 additions and 10 deletions.
56 changes: 46 additions & 10 deletions lib/src/screens/quizPage.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:guardiancare/src/constants/colors.dart';
import 'package:guardiancare/src/features/quiz/screens/quiz_questions_page.dart';

class QuizPage extends StatefulWidget {
Expand All @@ -9,13 +10,32 @@ class QuizPage extends StatefulWidget {

class _QuizPageState extends State<QuizPage> {
List<Map<String, dynamic>> questions = [];
List<Map<String, dynamic>> quizes = [];

@override
void initState() {
super.initState();
getQuizes();
getQuestions();
}

Future<void> getQuizes() async {
QuerySnapshot querySnapshot =
await FirebaseFirestore.instance.collection('quizes').get();
List<Map<String, dynamic>> _quizes = [];
for (var doc in querySnapshot.docs) {
if (doc["name"] != null) {
_quizes.add({
"name": doc["name"],
"thumbnail": doc["thumbnail"],
});
}
}
setState(() {
quizes = _quizes;
});
}

Future<void> getQuestions() async {
QuerySnapshot querySnapshot =
await FirebaseFirestore.instance.collection('questions').get();
Expand All @@ -42,7 +62,7 @@ class _QuizPageState extends State<QuizPage> {
title: const Text('Quiz Page'),
),
body: ListView.builder(
itemCount: questions.length,
itemCount: quizes.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(8.0),
Expand All @@ -54,14 +74,14 @@ class _QuizPageState extends State<QuizPage> {
MaterialPageRoute(
builder: (context) => QuizQuestionsPage(
questions: questions
.where(
(question) => question["quiz"] == "child abuse")
.where((question) =>
question["quiz"] == quizes[index]["name"])
.toList(), // Modify filtering as per your requirement
),
),
);
},
child: QuizTile(question: questions[index]),
child: QuizTile(quiz: quizes[index]),
),
);
},
Expand All @@ -71,18 +91,34 @@ class _QuizPageState extends State<QuizPage> {
}

class QuizTile extends StatelessWidget {
final Map<String, dynamic> question;
final Map<String, dynamic> quiz;

const QuizTile({required this.question});
const QuizTile({required this.quiz});


@override
Widget build(BuildContext context) {
return Card(
elevation: 4,
child: ListTile(
title: Text(question['question']),
subtitle: Text('Quiz: ${question['quiz']}'),
),
child:
Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Image.network(
quiz["thumbnail"],
height: 200,
),
Container(
padding: EdgeInsets.all(8),
color: Color.fromRGBO(220, 220, 220, 1),
child: Text(
quiz["name"],
style: TextStyle(fontSize: 25, color: tPrimaryColor),
))
],
),
);
}
}

0 comments on commit df9b376

Please sign in to comment.