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

Develop #15

Open
wants to merge 17 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
94 changes: 49 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,65 @@
![App Brewery Banner](https://github.com/londonappbrewery/Images/blob/master/AppBreweryBanner.png)


# Quizzler ❓

## Our Goal
This project is part of a series of projects to be completed by students of the [AppBrewery](https://www.appbrewery.co/p/flutter-development-bootcamp-with-dart) flutter course.

This project focuses on creating a Quizz app.

## Preview

![App preview](./assets/app_preview.gif)

## 🧮 The Project Brief

The premise of this project is to learn how to build several classes to have a better code structure using OOP principles like Polymorphism, Abstraction, Encapsulation and Inheritance, by building a Question True/False UI.

## 🎯 Features

* You can switch between English and Spanish by touching the toggle button

#### English
![App Preview](./assets/english_quizzler.png)

#### Spanish
![App Preview](./assets/español_quizzler.png)

* You can see if your answers where right or wrong with a live update at the bottom of the screen

#### Right or Wrong?
![App Preview](./assets/resultados_quizzler.png)

* You get the number of correct answers at the end of the game

#### Results
![App Preview](./assets/alert_quizzler.png)

In this tutorial we will be reviewing Stateful and Stateless Widgets as well as learning about the fundamental building blocks of Object Oriented Programming (OOP) - Classes and Objects.
## 🧬 Technologies & Languages Used

- Dart
- Flutter
- Github

## What you will create

We’re going to make a quiz app that tests your general knowledge. As one of the most popular types of apps on the app stores, you can create your own quiz for other people to enjoy!
## 🛎️ Contributions, Issues & Forking

![Finished App](https://github.com/londonappbrewery/Images/blob/master/quizzler-demo.gif)
If you have any issues setting up the project or you come across any unintended bugs or problems, please do submit an issue to the [Quizz app](https://github.com/Psiale/quizzler-flutter/issues) page.

## What you will learn
If you want to make your own changes, modifications or improvements to our project, go ahead and Fork it!
1. [Fork it](https://github.com/Psiale/quizzler-flutter/fork)

- Modularising your code into separate classes.
- Dart classes and objects.
- Using class constructors.
- Extracting Widgets to refactor your code.
- private and public modifiers in Dart.
- How to use Dart lists.
- The difference between var, const and final.
2. Create your working branch (git checkout -b [choose-a-name])

## Code Snippet for Project
3. Commit your changes (git commit -m 'what this commit will fix/add/improve')
4. Push to the branch (git push origin [chosen-name])
5. Create a new Pull Request

```
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),
## 🤟🏽😄 😛🤙🏾 Creator

```
Alexis Sanchez
- [Github](https://github.com/Psiale)
- [Linkedin](https://www.linkedin.com/in/alexis-sanchez-dev/)

## 🙌🏾 Show Your Support

>This is a companion project to The App Brewery's Complete Flutter Development Bootcamp, check out the full course at [www.appbrewery.co](https://www.appbrewery.co/)
Give a ⭐️ if you like this project!

![End Banner](https://github.com/londonappbrewery/Images/blob/master/readme-end-banner.png)
2 changes: 2 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
use the toggleBuilder from widget_builder to create a toggle at the top right of the screen
Implement a function that changes the language and
Binary file added assets/alert_quizzler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/app_preview.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/english_quizzler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/español_quizzler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/resultados_quizzler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\Users\front\Documents\flutter"
export "FLUTTER_APPLICATION_PATH=C:\Users\front\Desktop\Flutter_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\front\Documents\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"
export "PACKAGE_CONFIG=.packages"
8 changes: 8 additions & 0 deletions lib/classes/assert.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:meta/meta.dart';

class Assert {
String question;
bool answer;

Assert({@required this.question, @required this.answer});
}
65 changes: 65 additions & 0 deletions lib/classes/quiz_brain.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:rflutter_alert/rflutter_alert.dart';
import 'package:quizzler/english_questions.dart';
import 'package:quizzler/widget_builder.dart' as WidgetBuilder;
import 'package:quizzler/spanish_questions.dart';

SpanishQuestions spanishQuestions = SpanishQuestions();
EnglishQuestions englishQuestions = EnglishQuestions();

class QuizBrain {
int _questionNumber = 0;
int _correctAnswers = 0;
List _questionsList = spanishQuestions.getSpanishQuestions();

getQuestion() => _questionsList[_questionNumber].question;

getListLength() => _questionsList.length;
getQuestionNumber() => _questionNumber;
setQuestionNumber(number) => _questionNumber = number;

nextQuestion() {
if (_questionNumber < (_questionsList.length - 1)) _questionNumber++;
}

getAnswer() => _questionsList[_questionNumber].answer;

Icon answerChecker(bool userAnswer) {
Icon response;
print("userAnswer: $userAnswer correctAnswer: ${(getAnswer())}");
if (userAnswer == getAnswer()) {
response = WidgetBuilder.iconsBuilder(Icons.check, Colors.green);
_correctAnswers++;
} else {
response = WidgetBuilder.iconsBuilder(Icons.close, Colors.red);
}
return response;
}

bool gameListener(BuildContext context, resetCallBack) {
bool result = true;
if (_questionNumber == (getListLength() - 1)) {
Alert(
context: context,
buttons: [
DialogButton(
color: Colors.blue,
child:
WidgetBuilder.iconsBuilder(Icons.refresh, Colors.white),
onPressed: () => Navigator.pop(context),
width: 120,
)
],
title:
" Lograste $_correctAnswers respuestas correctas.\n You got $_correctAnswers correct answers.")
.show();
resetCallBack();
result = false;
_correctAnswers = 0;
}
return result;
}

setList(list) => _questionsList = list;
}
47 changes: 47 additions & 0 deletions lib/english_questions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import './classes/assert.dart';

class EnglishQuestions {
List<Assert> _englishQuestions = [
Assert(question: 'Some cats are actually allergic to humans', answer: true),
Assert(
question: 'You can lead a cow down stairs but not up stairs.',
answer: false),
Assert(
question: 'Approximately one quarter of human bones are in the feet.',
answer: true),
Assert(question: 'A slug\'s blood is green.', answer: true),
Assert(
question: 'Buzz Aldrin\'s mother\'s maiden name was \"Moon\".',
answer: true),
Assert(
question: 'It is illegal to pee in the Ocean in Portugal.',
answer: true),
Assert(
question:
'No piece of square dry paper can be folded in half more than 7 times.',
answer: false),
Assert(
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.',
answer: true),
Assert(
question:
'The loudest sound produced by any animal is 188 decibels. That animal is the African Elephant.',
answer: false),
Assert(
question:
'The total surface area of two human lungs is approximately 70 square metres.',
answer: true),
Assert(question: 'Google was originally called \"Backrub\".', answer: true),
Assert(
question:
'Chocolate affects a dog\'s heart and nervous system; a few ounces are enough to kill a small dog.',
answer: true),
Assert(
question:
'In West Virginia, USA, if you accidentally hit an animal with your car, you are free to take it home to eat.',
answer: true),
];

getEnglishQuestions() => _englishQuestions;
}
70 changes: 61 additions & 9 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import 'package:flutter/material.dart';
import 'classes/quiz_brain.dart';
import 'package:toggle_switch/toggle_switch.dart';
import 'package:quizzler/spanish_questions.dart';
import 'package:quizzler/english_questions.dart';

SpanishQuestions spanishQuestions = SpanishQuestions();
EnglishQuestions englishQuestions = EnglishQuestions();
int initialIndex = 0;

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

class Quizzler extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.grey.shade900,
body: SafeArea(
Expand All @@ -25,19 +35,21 @@ class QuizPage extends StatefulWidget {
}

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

@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
toggleBuilder(),
Expanded(
flex: 5,
child: Padding(
padding: EdgeInsets.all(10.0),
child: Center(
child: Text(
'This is where the question text will go.',
quizBrain.getQuestion(),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 25.0,
Expand All @@ -61,6 +73,12 @@ class _QuizPageState extends State<QuizPage> {
),
),
onPressed: () {
setState(() {
if (quizBrain.gameListener(context, reset)) {
scoreKeeper.add(quizBrain.answerChecker(true));
quizBrain.nextQuestion();
}
});
//The user picked true.
},
),
Expand All @@ -80,18 +98,52 @@ class _QuizPageState extends State<QuizPage> {
),
onPressed: () {
//The user picked false.
setState(() {
if (quizBrain.gameListener(context, reset)) {
scoreKeeper.add(quizBrain.answerChecker(false));
quizBrain.nextQuestion();
}
});
},
),
),
),
//TODO: Add a Row here as your score keeper
Row(
children: scoreKeeper,
)
],
);
}
}

/*
question1: 'You can lead a cow down stairs but not up stairs.', false,
question2: 'Approximately one quarter of human bones are in the feet.', true,
question3: 'A slug\'s blood is green.', true,
*/
reset() {
quizBrain.setQuestionNumber(0);
scoreKeeper = [];
}

toggleBuilder() {
return Center(
child: Container(
margin: EdgeInsets.only(top: 15.0),
child: ToggleSwitch(
minWidth: 90.0,
cornerRadius: 10.0,
activeBgColor: Colors.white,
activeFgColor: Colors.blue,
inactiveBgColor: Colors.blue.shade900,
inactiveFgColor: Colors.grey,
initialLabelIndex: initialIndex,
labels: ['Español', 'English'],
onToggle: (int i) {
print('switched to $i');
setState(() {
initialIndex = i;
(i == 1)
? quizBrain.setList(englishQuestions.getEnglishQuestions())
: quizBrain.setList(spanishQuestions.getSpanishQuestions());
});
},
),
),
);
}
}
Loading