diff --git a/lib/browse.dart b/lib/browse.dart new file mode 100644 index 0000000..ede87e8 --- /dev/null +++ b/lib/browse.dart @@ -0,0 +1,102 @@ +import 'package:flutter/material.dart'; +import 'package:ju_learn/main.dart'; + +class QuizPageBrowse extends StatefulWidget { + Vault v; + QuizPageBrowse(this.v, {super.key}); + + @override + // ignore: no_logic_in_create_state, library_private_types_in_public_api + _QuizPageBrowseState createState() => _QuizPageBrowseState(v); +} + +class _QuizPageBrowseState extends State { + int qI = 0; + late Question _currentQuestion; + Vault v; + _QuizPageBrowseState(this.v) { + _currentQuestion = v.questions[0]; + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Testing: ${v.name}'), + ), + body: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Align( + alignment: Alignment.center, + child: Text("${qI+1}/${v.questions.length}"), + ), + Text( + _currentQuestion.quest, + style: const TextStyle( + fontSize: 20.0, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 20.0), + ..._currentQuestion.answers.map((option) => Container( + margin: const EdgeInsets.symmetric(vertical: 8.0), + child: FilledButton( + onPressed: () {}, + style: FilledButton.styleFrom( + padding: const EdgeInsets.all(16.0), + backgroundColor: _currentQuestion.correct == + _currentQuestion.answers.indexOf(option) + ? Colors.green + : Colors.red), + child: Text(option)))), + Text( + _currentQuestion.explanation, + style: const TextStyle( + fontSize: 15.0, + fontWeight: FontWeight.bold, + ), + ) + ], + ), + ), + floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, + floatingActionButton: Padding( + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 12), + child: Row( + children: [ + FloatingActionButton( + onPressed: () { + if (qI > 0) { + qI--; + } else { + qI = v.questions.length - 1; + } + setState(() { + _currentQuestion = v.questions[qI]; + }); + }, + child: const Icon(Icons.chevron_left), + ), + const Spacer(), + FloatingActionButton( + onPressed: () { + if (qI < v.questions.length - 1) { + qI++; + } else { + qI = 0; + } + setState(() { + _currentQuestion = v.questions[qI]; + }); + }, + child: const Icon(Icons.chevron_right), + ), + ], + ), + ), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index ef4893e..922bb29 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,7 +4,9 @@ import 'dart:io'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:ju_learn/browse.dart'; import 'package:ju_learn/learn.dart'; +import 'package:ju_learn/test.dart'; import 'package:shared_preferences/shared_preferences.dart'; void main() => runApp(const LearnApp()); @@ -91,6 +93,31 @@ class MainPageState extends State { fontWeight: FontWeight.bold, )) ])), + ListTile( + leading: const Icon(Icons.access_alarm), + title: const Text("Test"), + subtitle: const Text("Show you the awnsers in Test Mode!"), + trailing: const Icon(Icons.chevron_right), + onTap: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) => QuizPageTest(v)), + ); + }, + ), + ListTile( + leading: const Icon(Icons.book_online), + title: const Text("Browse"), + subtitle: const Text("Browse to all Questions!"), + trailing: const Icon(Icons.chevron_right), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => QuizPageBrowse(v)), + ); + }, + ), ListTile( leading: const Icon(Icons.restore), title: const Text("Reset Vault"), @@ -249,7 +276,9 @@ class Question { int correct; String explanation; int drawer = 0; + int lastInRun = 0; + int pickedAwnser = -1; Question(this.quest, this.answers, this.correct, this.explanation); @@ -306,15 +335,33 @@ class Vault { for (var q in questions) { q.drawer = 0; q.lastInRun = 0; + q.pickedAwnser = 0; } } void softReset() { for (var q in questions) { q.lastInRun = 0; + q.pickedAwnser = -1; } } + int pickedNum() { + int num = 0; + for (var q in questions) { + if (q.pickedAwnser != -1) num++; + } + return num; + } + + int rightNum() { + int num = 0; + for (var q in questions) { + if (q.pickedAwnser == q.correct) num++; + } + return num; + } + (int, double, int) vals() { int min = 0xffffff; int total = 0; diff --git a/lib/test.dart b/lib/test.dart new file mode 100644 index 0000000..ae33e85 --- /dev/null +++ b/lib/test.dart @@ -0,0 +1,162 @@ +import 'package:flutter/material.dart'; +import 'package:ju_learn/main.dart'; + +class QuizPageTest extends StatefulWidget { + Vault v; + QuizPageTest(this.v, {super.key}); + + @override + // ignore: no_logic_in_create_state, library_private_types_in_public_api + _QuizPageTestState createState() => _QuizPageTestState(v); +} + +class _QuizPageTestState extends State { + int qI = 0; + late Question _currentQuestion; + bool finished = false; + Vault v; + _QuizPageTestState(this.v) { + v.softReset(); + _currentQuestion = v.questions[0]; + } + + void _checkAnswer(int selectedIndex) { + setState(() { + _currentQuestion.pickedAwnser = selectedIndex; + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Testing: ${v.name}'), + ), + body: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Align( + alignment: Alignment.center, + child: finished + ? Text("${v.rightNum()}/${v.questions.length} awnsered") + : Text("${v.pickedNum()}/${v.questions.length} correct"), + ), + Text( + _currentQuestion.quest, + style: const TextStyle( + fontSize: 20.0, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 20.0), + ..._currentQuestion.answers.map((option) => Container( + margin: const EdgeInsets.symmetric(vertical: 8.0), + child: FilledButton( + onPressed: () { + if (!finished) { + _checkAnswer( + _currentQuestion.answers.indexOf(option), + ); + } + }, + style: FilledButton.styleFrom( + padding: const EdgeInsets.all(16.0), + backgroundColor: !finished + ? (_currentQuestion.answers.indexOf(option) == + _currentQuestion.pickedAwnser + ? Colors.amber + : null) + : (_currentQuestion.answers.indexOf(option) == + _currentQuestion.pickedAwnser + ? (_currentQuestion.correct == + _currentQuestion.answers.indexOf(option) + ? Colors.green[200] + : Colors.red[200]) + : (_currentQuestion.correct == + _currentQuestion.answers.indexOf(option) + ? Colors.green + : Colors.red))), + child: Text(option)))), + if (finished) + Text( + _currentQuestion.explanation, + style: const TextStyle( + fontSize: 15.0, + fontWeight: FontWeight.bold, + ), + ) + ], + ), + ), + floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, + floatingActionButton: Padding( + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 12), + child: Row( + children: [ + FloatingActionButton( + onPressed: () { + if (qI > 0) { + qI--; + } else { + qI = v.questions.length - 1; + } + setState(() { + _currentQuestion = v.questions[qI]; + }); + }, + child: const Icon(Icons.chevron_left), + ), + if (!finished) const Spacer(), + if (!finished) + FloatingActionButton( + onPressed: () { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Finish Test'), + content: const Text('Do you want to finish your Test?'), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('Cancel')), + FilledButton( + child: const Text('Finish'), + onPressed: () { + setState(() { + finished = true; + }); + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + }, + child: const Icon(Icons.check), + ), + const Spacer(), + FloatingActionButton( + onPressed: () { + if (qI < v.questions.length - 1) { + qI++; + } else { + qI = 0; + } + setState(() { + _currentQuestion = v.questions[qI]; + }); + }, + child: const Icon(Icons.chevron_right), + ), + ], + ), + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 3bc067f..2b0d477 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -33,6 +33,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" + change_app_package_name: + dependency: "direct dev" + description: + name: change_app_package_name + sha256: f9ebaf68a4b5a68c581492579bb68273c523ef325fbf9ce2f1b57fb136ad023b + url: "https://pub.dev" + source: hosted + version: "1.1.0" characters: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 1158750..f94625a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -48,6 +48,7 @@ dev_dependencies: # rules and activating additional ones. flutter_lints: ^2.0.0 flutter_launcher_icons: + change_app_package_name: flutter_launcher_icons: