Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finally Done with the quiz App #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\Users\Semite\flutter"
export "FLUTTER_APPLICATION_PATH=C:\Projects\quizzler-flutter"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=C:\Users\Semite\flutter\bin\cache\artifacts\engine\ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
49 changes: 47 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'package:flutter/material.dart';
import 'package:rflutter_alert/rflutter_alert.dart';
import 'quiz_brain.dart';

QuizBrain quizBrain = QuizBrain();
void main() => runApp(Quizzler());

class Quizzler extends StatelessWidget {
Expand All @@ -25,6 +28,44 @@ class QuizPage extends StatefulWidget {
}

class _QuizPageState extends State<QuizPage> {
List<Icon> scoreKeeper = [];

void checkAnswer(bool userPickedAnswer) {
bool correctAnswer = quizBrain.getQuestionAnswer();

setState(() {
//On the next line, you can also use if (quizBrain.isFinished()) {}, it does the same thing.
if (quizBrain.isFinished() == true) {
//This is the code for the basic alert from the docs for rFlutter Alert:
//Alert(context: context, title: "RFLUTTER", desc: "Flutter is awesome.").show();

//Modified for our purposes:
Alert(
context: context,
title: 'Finished!',
desc: 'You\'ve reached the end of the quiz.',
).show();

quizBrain.reset();

scoreKeeper = [];
} else {
if (userPickedAnswer == correctAnswer) {
scoreKeeper.add(Icon(
Icons.check,
color: Colors.green,
));
} else {
scoreKeeper.add(Icon(
Icons.close,
color: Colors.red,
));
}
quizBrain.nextQuestion();
}
});
}

@override
Widget build(BuildContext context) {
return Column(
Expand All @@ -37,7 +78,7 @@ class _QuizPageState extends State<QuizPage> {
padding: EdgeInsets.all(10.0),
child: Center(
child: Text(
'This is where the question text will go.',
quizBrain.getQuestionText(),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 25.0,
Expand All @@ -62,6 +103,7 @@ class _QuizPageState extends State<QuizPage> {
),
onPressed: () {
//The user picked true.
checkAnswer(true);
},
),
),
Expand All @@ -80,11 +122,14 @@ class _QuizPageState extends State<QuizPage> {
),
onPressed: () {
//The user picked false.
checkAnswer(false);
},
),
),
),
//TODO: Add a Row here as your score keeper
Row(
children: scoreKeeper,
)
],
);
}
Expand Down
7 changes: 7 additions & 0 deletions lib/question.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Question {

String questionText;
bool questionAnswer;

Question(this.questionText, this.questionAnswer);
}
68 changes: 68 additions & 0 deletions lib/quiz_brain.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'question.dart';

class QuizBrain {

int _questionNumber = 0;

List<Question> _questionBank = [
Question('Some cats are actually allergic to humans',true),
Question('You can lead a cow down stairs but not up stairs.', false),
Question('Approximately one quarter of human bones are in the feet.', true),
Question('A slug\'s blood is green.', true),
Question('Buzz Aldrin\'s mother\'s maiden name was \"Moon\".', true),
Question('It is illegal to pee in the Ocean in Portugal.', true),
Question(
'No piece of square dry paper can be folded in half more than 7 times.',
false),
Question(
'In London, UK, if you happen to die in the House of Parliament, you are technically entitled to a state funeral, because the building is considered too sacred a place.',
true),
Question(
'The loudest sound produced by any animal is 188 decibels. That animal is the African Elephant.',
false),
Question(
'The total surface area of two human lungs is approximately 70 square metres.',
true),
Question('Google was originally called \"Backrub\".', true),
Question(
'Chocolate affects a dog\'s heart and nervous system; a few ounces are enough to kill a small dog.',
true),
Question(
'In West Virginia, USA, if you accidentally hit an animal with your car, you are free to take it home to eat.',
true),

];

void nextQuestion() {
if (_questionNumber < _questionBank.length - 1) {
_questionNumber++;
}
print(_questionNumber);
print(_questionBank.length);
}

String getQuestionText() {
return _questionBank[_questionNumber].questionText;

}

bool getQuestionAnswer() {
return _questionBank[_questionNumber].questionAnswer;
}



bool isFinished() {
if (_questionNumber >= _questionBank.length - 1) {
print('Now returning true');
return true;
} else {
return false;
}
}


void reset() {
_questionNumber = 0;
}
}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
rflutter_alert: ^1.0.3

dev_dependencies:
flutter_test:
Expand Down