Code Explained - The Quiz Questions :
import 'package:flutter/material.dart';
import '../utils/question.dart';
import '../utils/quiz.dart';
import '../UI/answer_button.dart';
import '../UI/question_text.dart';
import '../UI/correct_wrong_overlay.dart';
import '../Pages/missedquestions_page.dart';
import '../utils/missed.dart';
import '../Pages/score_page.dart';
class QuizPage1 extends StatefulWidget {
@override
State createState() => new QuizPageState1();
}
class QuizPageState1 extends State<QuizPage1> {
Question currentQuestion;
Quiz quiz = new Quiz([
new Question("People give up certain rights to the government in order to be protected:\n "
"\nA) Social Contract Theory \nB) Elitist Theory \nC) Pluralistic Theory \nD) Hyperpluralistic Theory", "A","Social Contract Theory" ),
new Question("A right that according to natural law cannot be taken away, denied or transferred. These are the rights to life, liberty, and property.:\n "
"\nA) Undeniable Rights \nB) Inalienable Rights \nC) Alienable Rights \nD) Deniable Rights", "B", "Inalienable Rights" ),
new Question("Wrote the Second Treatise on Government and established the idea of Inalienable Rights:\n "
"\nA) Thomas Hobbes \nB) Machiavelli \nC) Montesquieu \nD) John Locke", "D", "John Locke"),
new Question("Wrote the Spirit of the Law and established the idea of Checks and Balances:\n "
"\nA) Thomas Hobbes \nB) Machiavelli \nC) Montesquieu \nD) John Locke", "C", "Montesquieu"),
new Question("Wrote the Prince and established the idea that it is better to be feared than loved\n "
"\nA) Thomas Hobbes \nB) Machiavelli \nC) Montesquieu \nD) John Locke", "B", "Machivelli"),
new Question("Wrote the Leviathan and established the idea of the absolute power of the monarch by divine right\n "
"\nA) Thomas Hobbes \nB) Machiavelli \nC) Montesquieu \nD) John Locke", "A", "Thomas Hobbes"),
new Question("A system of government by the whole population or all the eligible members of a state\n "
"\nA) Democracy \nB) Socialism \nC) Communism \nD) Dictatorship", "A", "Democracy"),
new Question("Type of democracy in which citizens elect representatives who make up a legislature\n "
"\nA) Complicated Democracy \nB) Representative Democracy \nC) Direct Democracy \nD) Minimalist Democracy", "B", "Representative Democracy"),
new Question("Type of democracy in which citizens elect political teams and give them the right to rule\n "
"\nA) Complicated Democracy \nB) Representative Democracy \nC) Direct Democracy \nD) Minimalist Democracy", "D", "Minimalist Democracy"),
new Question("Type of democracy in which citizens cast their votes directly on laws,policies, and other legislative affairs\n "
"\nA) Complicated Democracy \nB) Representative Democracy \nC) Direct Democracy \nD) Minimalist Democracy", "C", "Direct Democracy"),
new Question("A theory of government that a large and diverse array of groups compete for influence leading to the weakening state of the government\n "
"\nA) Pluralism \nB) Hyperpluralism \nC) Elitism \nD) Monarchism", "A", "Pluralism"),
new Question("A theory of government that only those who have met the criteria for being elite may enter the political system\n "
"\nA) Pluralism \nB) Hyperpluralism \nC) Elitism \nD) Monarchism", "C", "Elitism"),
new Question("Pluralism to the extreme; Overwhelming amount of groups pull at the systems of power creates a gridlock\n "
"\nA) Pluralism \nB) Hyperpluralism \nC) Elitism \nD) Monarchism", "B", "Hyperpluralism"),
new Question("Goods and services that are by their nature cannot be denied to anyone\n "
"\nA) Collective Good \nB) Political Culture \nC) Public Policy \nD) Politics", "A", "Collective Good"),
new Question("An overall set of values widely shared within a society\n "
"\nA) Collective Good \nB) Political Culture \nC) Public Policy \nD) Politics", "B", "Political Culture"),
new Question("Process determining the leaders we select and the policies they pursue\n "
"\nA) Collective Good \nB) Political Culture \nC) Public Policy \nD) Politics", "D", "Politics"),
new Question("A choice that government makes in response to a political issue\n "
"\nA) Collective Good \nB) Political Culture \nC) Public Policy \nD) Politics", "C", "Public Policy"),
new Question("Political Channels through which peoples concerns become political issues on the policy agenda\n "
"\nA) Connecting Buildings \nB) Joining Locations \nC) Linking Areas \nD) Linkage Institutions", "D", "Linkage Institutions"),
new Question("Called for equal representation in Congress\n "
"\nA) New Jersey Plan \nB) Virginia Plan \nC) Texas Plan \nD) Connecticut Compromise", "A", "New Jersey Plan"),
new Question("Called for proportional representation in Congress\n "
"\nA) New Jersey Plan \nB) Virginia Plan \nC) Texas Plan \nD) Connecticut Compromise", "B", "Virginia Plan"),
new Question("AKA The Great Compromise, combined both the Virginia and New Jersey Plan to create a bicameral legislature with equal representation for the senate and proportional representaiton for the House of Representatives\n "
"\nA) New Jersey Plan \nB) Virginia Plan \nC) Texas Plan \nD) Connecticut Compromise", "D", "Connecticut Compromise"),
]);
String questionText;
int questionNumber;
bool isCorrect;
bool overlayShouldBeVisible = false;
var answerChoices = ["Social Contract Theory", "Inalienable Rights", "John Locke", "Montesquieu", "Machiavelli", "Thomas Hobbes", "Democracy", "Representative Democracy","Minimalist Democracy"," Direct Democracy", "Pluralism", "Elitism", "Hyperpluralism", "Collective Good", "Political Culture", "Politics", "Public Policy", "Linkage Institutions", "New Jersey Plan", "Virginia Plan", "Connecticut Compromise"];
var missed = [];
int count = 0;
@override
void initState() {
super.initState();
currentQuestion = quiz.nextQuestion;
questionText = currentQuestion.question;
questionNumber = quiz.questionNumber;
}
void handleAnswer(String answer) {
isCorrect = (currentQuestion.answer == answer);
quiz.answer(isCorrect);
this.setState(() {
overlayShouldBeVisible = true;
});
if(!isCorrect){
missed.add(currentQuestion.answerChoice);
}
count++;
}
@override
Widget build(BuildContext context) {
return new Stack(
fit: StackFit.expand,
children: <Widget>[
new Column( // This is our main page
children: <Widget>[
new QuestionText(questionText, questionNumber),
new AnswerButton("A", () => handleAnswer("A")), //true button
new AnswerButton("B", () => handleAnswer("B")),
new AnswerButton("C", () => handleAnswer("C")),
new AnswerButton("D", () => handleAnswer("D")),// false button
],
),
overlayShouldBeVisible == true ? new CorrectWrongOverlay(
isCorrect,
() {
if (quiz.length == questionNumber) {
//Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(builder: (BuildContext context) => new ScorePage(quiz.score, quiz.length, missed)), (Route route) => route == null);
Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(builder: (BuildContext context) => new MissingPage(quiz.score, quiz.length, missed)), (Route route) => route == null);
print(missed);
return;
}
currentQuestion = quiz.nextQuestion;
this.setState(() {
overlayShouldBeVisible = false;
questionText = currentQuestion.question;
questionNumber = quiz.questionNumber;
});
}
) : new Container()
],
);
}
}
Code Explained - The Quiz Questions :
import 'package:flutter/material.dart';
import '../utils/question.dart';
import '../utils/quiz.dart';
import '../UI/answer_button.dart';
import '../UI/question_text.dart';
import '../UI/correct_wrong_overlay.dart';
import '../Pages/missedquestions_page.dart';
import '../utils/missed.dart';
import '../Pages/score_page.dart';
class QuizPage1 extends StatefulWidget {
@override
State createState() => new QuizPageState1();
}
class QuizPageState1 extends State<QuizPage1> {
Question currentQuestion;
Quiz quiz = new Quiz([
new Question("People give up certain rights to the government in order to be protected:\n "
"\nA) Social Contract Theory \nB) Elitist Theory \nC) Pluralistic Theory \nD) Hyperpluralistic Theory", "A","Social Contract Theory" ),
new Question("A right that according to natural law cannot be taken away, denied or transferred. These are the rights to life, liberty, and property.:\n "
"\nA) Undeniable Rights \nB) Inalienable Rights \nC) Alienable Rights \nD) Deniable Rights", "B", "Inalienable Rights" ),
new Question("Wrote the Second Treatise on Government and established the idea of Inalienable Rights:\n "
"\nA) Thomas Hobbes \nB) Machiavelli \nC) Montesquieu \nD) John Locke", "D", "John Locke"),
new Question("Wrote the Spirit of the Law and established the idea of Checks and Balances:\n "
"\nA) Thomas Hobbes \nB) Machiavelli \nC) Montesquieu \nD) John Locke", "C", "Montesquieu"),
new Question("Wrote the Prince and established the idea that it is better to be feared than loved\n "
"\nA) Thomas Hobbes \nB) Machiavelli \nC) Montesquieu \nD) John Locke", "B", "Machivelli"),
new Question("Wrote the Leviathan and established the idea of the absolute power of the monarch by divine right\n "
"\nA) Thomas Hobbes \nB) Machiavelli \nC) Montesquieu \nD) John Locke", "A", "Thomas Hobbes"),
new Question("A system of government by the whole population or all the eligible members of a state\n "
"\nA) Democracy \nB) Socialism \nC) Communism \nD) Dictatorship", "A", "Democracy"),
new Question("Type of democracy in which citizens elect representatives who make up a legislature\n "
"\nA) Complicated Democracy \nB) Representative Democracy \nC) Direct Democracy \nD) Minimalist Democracy", "B", "Representative Democracy"),
new Question("Type of democracy in which citizens elect political teams and give them the right to rule\n "
"\nA) Complicated Democracy \nB) Representative Democracy \nC) Direct Democracy \nD) Minimalist Democracy", "D", "Minimalist Democracy"),
new Question("Type of democracy in which citizens cast their votes directly on laws,policies, and other legislative affairs\n "
"\nA) Complicated Democracy \nB) Representative Democracy \nC) Direct Democracy \nD) Minimalist Democracy", "C", "Direct Democracy"),
new Question("A theory of government that a large and diverse array of groups compete for influence leading to the weakening state of the government\n "
"\nA) Pluralism \nB) Hyperpluralism \nC) Elitism \nD) Monarchism", "A", "Pluralism"),
new Question("A theory of government that only those who have met the criteria for being elite may enter the political system\n "
"\nA) Pluralism \nB) Hyperpluralism \nC) Elitism \nD) Monarchism", "C", "Elitism"),
new Question("Pluralism to the extreme; Overwhelming amount of groups pull at the systems of power creates a gridlock\n "
"\nA) Pluralism \nB) Hyperpluralism \nC) Elitism \nD) Monarchism", "B", "Hyperpluralism"),
new Question("Goods and services that are by their nature cannot be denied to anyone\n "
"\nA) Collective Good \nB) Political Culture \nC) Public Policy \nD) Politics", "A", "Collective Good"),
new Question("An overall set of values widely shared within a society\n "
"\nA) Collective Good \nB) Political Culture \nC) Public Policy \nD) Politics", "B", "Political Culture"),
new Question("Process determining the leaders we select and the policies they pursue\n "
"\nA) Collective Good \nB) Political Culture \nC) Public Policy \nD) Politics", "D", "Politics"),
new Question("A choice that government makes in response to a political issue\n "
"\nA) Collective Good \nB) Political Culture \nC) Public Policy \nD) Politics", "C", "Public Policy"),
new Question("Political Channels through which peoples concerns become political issues on the policy agenda\n "
"\nA) Connecting Buildings \nB) Joining Locations \nC) Linking Areas \nD) Linkage Institutions", "D", "Linkage Institutions"),
new Question("Called for equal representation in Congress\n "
"\nA) New Jersey Plan \nB) Virginia Plan \nC) Texas Plan \nD) Connecticut Compromise", "A", "New Jersey Plan"),
new Question("Called for proportional representation in Congress\n "
"\nA) New Jersey Plan \nB) Virginia Plan \nC) Texas Plan \nD) Connecticut Compromise", "B", "Virginia Plan"),
new Question("AKA The Great Compromise, combined both the Virginia and New Jersey Plan to create a bicameral legislature with equal representation for the senate and proportional representaiton for the House of Representatives\n "
"\nA) New Jersey Plan \nB) Virginia Plan \nC) Texas Plan \nD) Connecticut Compromise", "D", "Connecticut Compromise"),
]);
String questionText;
int questionNumber;
bool isCorrect;
bool overlayShouldBeVisible = false;
var answerChoices = ["Social Contract Theory", "Inalienable Rights", "John Locke", "Montesquieu", "Machiavelli", "Thomas Hobbes", "Democracy", "Representative Democracy","Minimalist Democracy"," Direct Democracy", "Pluralism", "Elitism", "Hyperpluralism", "Collective Good", "Political Culture", "Politics", "Public Policy", "Linkage Institutions", "New Jersey Plan", "Virginia Plan", "Connecticut Compromise"];
var missed = [];
int count = 0;
@override
void initState() {
super.initState();
currentQuestion = quiz.nextQuestion;
questionText = currentQuestion.question;
questionNumber = quiz.questionNumber;
}
void handleAnswer(String answer) {
isCorrect = (currentQuestion.answer == answer);
quiz.answer(isCorrect);
this.setState(() {
overlayShouldBeVisible = true;
});
if(!isCorrect){
missed.add(currentQuestion.answerChoice);
}
count++;
}
@override
Widget build(BuildContext context) {
return new Stack(
fit: StackFit.expand,
children: <Widget>[
new Column( // This is our main page
children: <Widget>[
new QuestionText(questionText, questionNumber),
new AnswerButton("A", () => handleAnswer("A")), //true button
new AnswerButton("B", () => handleAnswer("B")),
new AnswerButton("C", () => handleAnswer("C")),
new AnswerButton("D", () => handleAnswer("D")),// false button
],
),
overlayShouldBeVisible == true ? new CorrectWrongOverlay(
isCorrect,
() {
if (quiz.length == questionNumber) {
//Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(builder: (BuildContext context) => new ScorePage(quiz.score, quiz.length, missed)), (Route route) => route == null);
Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(builder: (BuildContext context) => new MissingPage(quiz.score, quiz.length, missed)), (Route route) => route == null);
print(missed);
return;
}
currentQuestion = quiz.nextQuestion;
this.setState(() {
overlayShouldBeVisible = false;
questionText = currentQuestion.question;
questionNumber = quiz.questionNumber;
});
}
) : new Container()
],
);
}
}