browse and test Mode

This commit is contained in:
jusax23 2023-06-08 15:05:56 +02:00
parent c20ec964a0
commit 174585db0a
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41
5 changed files with 320 additions and 0 deletions

102
lib/browse.dart Normal file
View file

@ -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<QuizPageBrowse> {
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),
),
],
),
),
);
}
}

View file

@ -4,7 +4,9 @@ import 'dart:io';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:ju_learn/browse.dart';
import 'package:ju_learn/learn.dart'; import 'package:ju_learn/learn.dart';
import 'package:ju_learn/test.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
void main() => runApp(const LearnApp()); void main() => runApp(const LearnApp());
@ -91,6 +93,31 @@ class MainPageState extends State<MainPage> {
fontWeight: FontWeight.bold, 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( ListTile(
leading: const Icon(Icons.restore), leading: const Icon(Icons.restore),
title: const Text("Reset Vault"), title: const Text("Reset Vault"),
@ -249,7 +276,9 @@ class Question {
int correct; int correct;
String explanation; String explanation;
int drawer = 0; int drawer = 0;
int lastInRun = 0; int lastInRun = 0;
int pickedAwnser = -1;
Question(this.quest, this.answers, this.correct, this.explanation); Question(this.quest, this.answers, this.correct, this.explanation);
@ -306,15 +335,33 @@ class Vault {
for (var q in questions) { for (var q in questions) {
q.drawer = 0; q.drawer = 0;
q.lastInRun = 0; q.lastInRun = 0;
q.pickedAwnser = 0;
} }
} }
void softReset() { void softReset() {
for (var q in questions) { for (var q in questions) {
q.lastInRun = 0; 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, double, int) vals() {
int min = 0xffffff; int min = 0xffffff;
int total = 0; int total = 0;

162
lib/test.dart Normal file
View file

@ -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<QuizPageTest> {
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),
),
],
),
),
);
}
}

View file

@ -33,6 +33,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.1" 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: characters:
dependency: transitive dependency: transitive
description: description:

View file

@ -48,6 +48,7 @@ dev_dependencies:
# rules and activating additional ones. # rules and activating additional ones.
flutter_lints: ^2.0.0 flutter_lints: ^2.0.0
flutter_launcher_icons: flutter_launcher_icons:
change_app_package_name:
flutter_launcher_icons: flutter_launcher_icons: