diff --git a/.gitignore b/.gitignore index 9004be2..fbf70cb 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ migrate_working_dir/ .pub-cache/ .pub/ /build/ +/pubspec.lock # Symbolication related app.*.symbols diff --git a/assets/explore/dot.svg b/assets/explore/dot.svg new file mode 100644 index 0000000..2c60daf --- /dev/null +++ b/assets/explore/dot.svg @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/assets/explore/notebook.svg b/assets/explore/notebook.svg new file mode 100644 index 0000000..40bfee6 --- /dev/null +++ b/assets/explore/notebook.svg @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/explore/quiz.dart b/lib/explore/quiz.dart new file mode 100644 index 0000000..be0516d --- /dev/null +++ b/lib/explore/quiz.dart @@ -0,0 +1,181 @@ +import 'package:flutter/material.dart'; +import 'dart:math'; +import 'package:flutter_svg/flutter_svg.dart'; +import 'package:learn/utils/constants.dart'; + +class QuizQuestion { + final String question; + final List options; + final int correctAnswerIndex; + + QuizQuestion({ + required this.question, + required this.options, + required this.correctAnswerIndex, + }); +} + +class QuizPage extends StatefulWidget { + const QuizPage({super.key}); + + @override + _QuizPageState createState() => _QuizPageState(); +} + +class _QuizPageState extends State { + late List _questions; + int _currentQuestionIndex = 0; + int _score = 0; + bool _quizCompleted = false; + String _feedbackMessage = ''; + Color _feedbackColor = Colors.transparent; + bool _answered = false; + + @override + void initState() { + super.initState(); + _questions = List.from(AppConstants.quizQuestions); + _questions.shuffle(); + if (_questions.length > 10) { + _questions = _questions.sublist(0, 10); + } + } + + void _answerQuestion(int selectedIndex) { + if (_answered) return; + + bool isCorrect = + selectedIndex == _questions[_currentQuestionIndex].correctAnswerIndex; + setState(() { + _answered = true; + if (isCorrect) { + _score++; + _feedbackMessage = 'Correct! Good job!'; + _feedbackColor = Colors.green; + } else { + _feedbackMessage = + 'Incorrect. The correct answer is: ${_questions[_currentQuestionIndex].options[_questions[_currentQuestionIndex].correctAnswerIndex]}'; + _feedbackColor = Colors.red; + } + }); + } + + void _nextQuestion() { + setState(() { + if (_currentQuestionIndex < _questions.length - 1) { + _currentQuestionIndex++; + _feedbackMessage = ''; + _feedbackColor = Colors.transparent; + _answered = false; + } else { + _quizCompleted = true; + } + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Quiz'), + ), + body: Padding( + padding: const EdgeInsets.all(16.0), + child: _quizCompleted + ? Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'Quiz Completed! Your score is $_score/${_questions.length}', + style: const TextStyle( + fontSize: 24, fontWeight: FontWeight.bold), + textAlign: TextAlign.center, + ), + const SizedBox(height: 20), + ElevatedButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('Back to Explore'), + ), + ], + ) + : Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Question ${_currentQuestionIndex + 1}/${_questions.length}', + style: const TextStyle( + fontSize: 22, fontWeight: FontWeight.bold), + ), + const SizedBox(height: 20), + Text( + _questions[_currentQuestionIndex].question, + style: const TextStyle(fontSize: 18), + ), + const SizedBox(height: 20), + Column( + children: List.generate( + _questions[_currentQuestionIndex].options.length, + (index) => GestureDetector( + onTap: () => _answerQuestion(index), + child: Container( + margin: const EdgeInsets.symmetric(vertical: 4.0), + padding: const EdgeInsets.all(8.0), + decoration: BoxDecoration( + border: Border.all(color: Colors.black, width: 1.0), + borderRadius: BorderRadius.circular(8.0), + color: Colors.blueAccent.withOpacity(0.2), + ), + child: Row( + children: [ + SizedBox( + width: 30, + height: 30, + child: + SvgPicture.asset('assets/explore/dot.svg'), + ), + const SizedBox(width: 12.0), + Expanded( + child: Text( + _questions[_currentQuestionIndex] + .options[index], + style: const TextStyle(fontSize: 16), + ), + ), + ], + ), + ), + ), + ), + ), + const SizedBox(height: 20), + if (_feedbackMessage.isNotEmpty) + Container( + padding: const EdgeInsets.all(12.0), + decoration: BoxDecoration( + color: _feedbackColor.withOpacity(0.2), + borderRadius: BorderRadius.circular(8.0), + border: Border.all(color: _feedbackColor, width: 1.0), + ), + child: Text( + _feedbackMessage, + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + color: _feedbackColor, + ), + ), + ), + const SizedBox(height: 20), + if (_answered && !_quizCompleted) + ElevatedButton( + onPressed: _nextQuestion, + child: const Text('Next Question'), + ), + ], + ), + ), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index 51f21ec..99b3ed4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -17,6 +17,7 @@ import 'package:learn/pages/modules/colours.dart'; import 'package:learn/widgets/navbar/navbar.dart'; import 'cubit/index_cubit.dart'; +import 'explore/quiz.dart'; import 'pages/home.dart'; DateTime? currentBackPressTime; @@ -69,6 +70,7 @@ class MyApp extends StatelessWidget { AllRoutes.flowerRoute: (context) => const FlowerPage(), AllRoutes.exploreRoute: (context) => const ExplorePage(), AllRoutes.favoriteRoute: (context) => const FavoritePage(), + AllRoutes.quizRoute: (context) => QuizPage(), AllRoutes.seasonRoute: (context) => SeasonsPage(), }, ); diff --git a/lib/pages/explore.dart b/lib/pages/explore.dart index 5017895..e8d0b0a 100644 --- a/lib/pages/explore.dart +++ b/lib/pages/explore.dart @@ -1,18 +1,53 @@ import 'package:flutter/material.dart'; - -// Explore Page -// All the modules will be placed here like alphabets, animals, etc... -// TODO: Implement the Explore Page +import 'package:flutter_svg/flutter_svg.dart'; +import 'package:learn/utils/constants.dart'; class ExplorePage extends StatelessWidget { const ExplorePage({super.key}); @override Widget build(BuildContext context) { - return const Scaffold( - body: Center( - child: Text("Explore Page"), - ) + return Scaffold( + appBar: AppBar( + title: const Text('Explore'), + ), + body: ListView( + children: [ + GestureDetector( + onTap: () { + Navigator.pushNamed(context, '/quiz'); + }, + child: Container( + margin: const EdgeInsets.all(5.0), + padding: const EdgeInsets.all(8.0), + decoration: BoxDecoration( + border: Border.all(color: Colors.black, width: 1.0), + borderRadius: BorderRadius.circular(8.0), + color: Colors.blueAccent, + ), + child: Row( + children: [ + SizedBox( + width: 50, + height: 50, + child: SvgPicture.asset('assets/explore/notebook.svg'), + ), + const SizedBox(width: 28.0), + const Text( + 'Quiz', + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 30.0, + fontFamily: 'Comic', + color: Colors.white, + ), + ), + ], + ), + ), + ), + ], + ), ); } -} \ No newline at end of file +} diff --git a/lib/utils/constants.dart b/lib/utils/constants.dart index 1ad9203..87b1fb4 100644 --- a/lib/utils/constants.dart +++ b/lib/utils/constants.dart @@ -1,7 +1,7 @@ import 'dart:ui'; +import '../explore/quiz.dart'; import 'package:flutter/material.dart'; - import '../pages/modules/animals.dart'; import '../pages/modules/atoz.dart'; import '../pages/modules/birds.dart'; @@ -452,6 +452,94 @@ class AppConstants { ), ]; + static List quizQuestions = [ + // Animal Questions + QuizQuestion( + question: "What sound does a cat make?", + options: ["Meow", "Woof", "Moo", "Roar"], + correctAnswerIndex: 0, + ), + QuizQuestion( + question: "Which animal is known as the king of the jungle?", + options: ["Elephant", "Lion", "Tiger", "Deer"], + correctAnswerIndex: 1, + ), + QuizQuestion( + question: "Which animal has a long neck and eats leaves?", + options: ["Giraffe", "Bear", "Monkey", "Rabbit"], + correctAnswerIndex: 0, + ), + QuizQuestion( + question: "Which animal says 'Moo'?", + options: ["Pig", "Dog", "Cow", "Cat"], + correctAnswerIndex: 2, + ), + QuizQuestion( + question: "What color are zebra's stripes?", + options: [ + "Black and White", + "Brown and White", + "Black and Yellow", + "Gray and White" + ], + correctAnswerIndex: 0, + ), + + // Bird Questions + QuizQuestion( + question: "Which bird is known for its beautiful singing?", + options: ["Crow", "Sparrow", "Duck", "Robin"], + correctAnswerIndex: 3, + ), + QuizQuestion( + question: "Which bird is known to peck wood?", + options: ["Eagle", "Owl", "Woodpecker", "Parrot"], + correctAnswerIndex: 2, + ), + QuizQuestion( + question: "Which bird can mimic human speech?", + options: ["Duck", "Parrot", "Swan", "Eagle"], + correctAnswerIndex: 1, + ), + QuizQuestion( + question: "Which bird is known for its colorful feathers?", + options: ["Penguin", "Crow", "Peacock", "Hummingbird"], + correctAnswerIndex: 3, + ), + QuizQuestion( + question: "Which bird is a common pet known for singing?", + options: ["Ostrich", "Canary", "Sparrow", "Eagle"], + correctAnswerIndex: 1, + ), + + // Season Questions + QuizQuestion( + question: "In which season do flowers bloom?", + options: ["Winter", "Spring", "Autumn", "Summer"], + correctAnswerIndex: 1, + ), + QuizQuestion( + question: "Which season is the hottest?", + options: ["Winter", "Spring", "Autumn", "Summer"], + correctAnswerIndex: 3, + ), + QuizQuestion( + question: "During which season do leaves fall from trees?", + options: ["Winter", "Spring", "Autumn", "Summer"], + correctAnswerIndex: 2, + ), + QuizQuestion( + question: "Which season is the coldest?", + options: ["Winter", "Spring", "Autumn", "Summer"], + correctAnswerIndex: 0, + ), + QuizQuestion( + question: "In which season do we often see snow?", + options: ["Winter", "Spring", "Autumn", "Summer"], + correctAnswerIndex: 0, + ), + ]; + static List seasons = [ Season( name: 'Spring', diff --git a/lib/utils/routes.dart b/lib/utils/routes.dart index 9765aa2..59435bd 100644 --- a/lib/utils/routes.dart +++ b/lib/utils/routes.dart @@ -12,5 +12,6 @@ class AllRoutes { static String aboutRoute = "/about"; static String colourRoute = "/colours"; static String flowerRoute = "/flowers"; + static String quizRoute = "/quiz"; static String seasonRoute = "/seasons"; } diff --git a/pubspec.yaml b/pubspec.yaml index b16c984..934ec28 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -77,6 +77,7 @@ flutter: - assets/solar/ - assets/images/colours/ - assets/images/flowers/ + - assets/explore/ - assets/seasons/