This repository has been archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e21889
commit 991f687
Showing
9 changed files
with
874 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | ||
|
||
class Category{ | ||
final int id; | ||
final String name; | ||
final dynamic icon; | ||
Category(this.id, this.name, {this.icon}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_custom_clippers/flutter_custom_clippers.dart'; | ||
import 'package:flutter_ui_challenges/src/pages/quiz_app/home.dart'; | ||
import 'question.dart'; | ||
|
||
class CheckAnswersPage extends StatelessWidget { | ||
final List<Question> questions; | ||
final Map<int,dynamic> answers; | ||
|
||
const CheckAnswersPage({Key key, @required this.questions, @required this.answers}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context){ | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text('Check Answers'), | ||
elevation: 0, | ||
), | ||
body: Stack( | ||
children: <Widget>[ | ||
ClipPath( | ||
clipper: WaveClipperTwo(), | ||
child: Container( | ||
decoration: BoxDecoration( | ||
color: Theme.of(context).primaryColor | ||
), | ||
height: 200, | ||
), | ||
), | ||
ListView.builder( | ||
padding: const EdgeInsets.all(16.0), | ||
itemCount: questions.length+1, | ||
itemBuilder: _buildItem, | ||
|
||
) | ||
], | ||
), | ||
); | ||
} | ||
Widget _buildItem(BuildContext context, int index) { | ||
if(index == questions.length) { | ||
return RaisedButton( | ||
child: Text("Done"), | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(20.0) | ||
), | ||
color: Theme.of(context).primaryColor, | ||
textColor: Colors.white, | ||
onPressed: (){ | ||
Navigator.of(context).pushReplacement(MaterialPageRoute( | ||
builder: (_) => QuizHomePage() | ||
)); | ||
}, | ||
); | ||
} | ||
Question question = questions[index]; | ||
bool correct = question.correctAnswer == answers[index]; | ||
return Card( | ||
child: Padding( | ||
padding: const EdgeInsets.all(16.0), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: <Widget>[ | ||
Text(question.question, style: TextStyle( | ||
color: Colors.black, | ||
fontWeight: FontWeight.w500, | ||
fontSize: 16.0 | ||
),), | ||
SizedBox(height: 5.0), | ||
Text("${answers[index]}", style: TextStyle( | ||
color: correct ? Colors.green : Colors.red, | ||
fontSize: 18.0, | ||
fontWeight: FontWeight.bold | ||
),), | ||
SizedBox(height: 5.0), | ||
correct ? Container(): Text.rich(TextSpan( | ||
children: [ | ||
TextSpan(text: "Answer: "), | ||
TextSpan(text:question.correctAnswer , style: TextStyle( | ||
fontWeight: FontWeight.w500 | ||
)) | ||
] | ||
),style: TextStyle( | ||
fontSize: 16.0 | ||
),) | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
|
||
//questions taken from https://opentdb.com | ||
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | ||
|
||
import 'category.dart'; | ||
import 'question.dart'; | ||
|
||
const Map<int,dynamic> demoAnswers = { | ||
0:"Multi Pass", | ||
1:1, | ||
2:"Motherboard", | ||
3:"Cascading Style Sheet", | ||
4:"Marshmallow", | ||
5:"140", | ||
6:"Python", | ||
7:"True", | ||
8:"Jakarta" | ||
}; | ||
|
||
final List<Category> categories = [ | ||
Category(9,"General Knowledge", icon: FontAwesomeIcons.globeAsia), | ||
Category(10,"Books", icon: FontAwesomeIcons.bookOpen), | ||
Category(11,"Film", icon: FontAwesomeIcons.video), | ||
Category(12,"Music", icon: FontAwesomeIcons.music), | ||
Category(13,"Musicals & Theatres", icon: FontAwesomeIcons.theaterMasks), | ||
Category(14,"Television", icon: FontAwesomeIcons.tv), | ||
Category(15,"Video Games", icon: FontAwesomeIcons.gamepad), | ||
Category(16,"Board Games", icon: FontAwesomeIcons.chessBoard), | ||
Category(17,"Science & Nature", icon: FontAwesomeIcons.microscope), | ||
Category(18,"Computer", icon: FontAwesomeIcons.laptopCode), | ||
Category(19,"Maths", icon: FontAwesomeIcons.sortNumericDown), | ||
Category(20,"Mythology"), | ||
Category(21,"Sports", icon: FontAwesomeIcons.footballBall), | ||
Category(22,"Geography", icon: FontAwesomeIcons.mountain), | ||
Category(23,"History", icon: FontAwesomeIcons.monument), | ||
Category(24,"Politics"), | ||
Category(25,"Art", icon: FontAwesomeIcons.paintBrush), | ||
Category(26,"Celebrities"), | ||
Category(27,"Animals", icon: FontAwesomeIcons.dog), | ||
Category(28,"Vehicles", icon: FontAwesomeIcons.carAlt), | ||
Category(29,"Comics"), | ||
Category(30,"Gadgets", icon: FontAwesomeIcons.mobileAlt), | ||
Category(31,"Japanese Anime & Manga"), | ||
Category(32,"Cartoon & Animation"), | ||
]; | ||
|
||
final List<Question> demoQuestions = Question.fromData([ | ||
{ | ||
"category": "Science: Computers", | ||
"type": "multiple", | ||
"difficulty": "easy", | ||
"question": "What does the \"MP\" stand for in MP3?", | ||
"correct_answer": "Moving Picture", | ||
"incorrect_answers": [ | ||
"Music Player", | ||
"Multi Pass", | ||
"Micro Point" | ||
] | ||
}, | ||
{ | ||
"category": "Science: Computers", | ||
"type": "multiple", | ||
"difficulty": "easy", | ||
"question": "What amount of bits commonly equals one byte?", | ||
"correct_answer": "8", | ||
"incorrect_answers": [ | ||
"1", | ||
"2", | ||
"64" | ||
] | ||
}, | ||
{ | ||
"category": "Science: Computers", | ||
"type": "multiple", | ||
"difficulty": "easy", | ||
"question": "Which computer hardware device provides an interface for all other connected devices to communicate?", | ||
"correct_answer": "Motherboard", | ||
"incorrect_answers": [ | ||
"Central Processing Unit", | ||
"Hard Disk Drive", | ||
"Random Access Memory" | ||
] | ||
}, | ||
{ | ||
"category": "Science: Computers", | ||
"type": "multiple", | ||
"difficulty": "easy", | ||
"question": "In web design, what does CSS stand for?", | ||
"correct_answer": "Cascading Style Sheet", | ||
"incorrect_answers": [ | ||
"Counter Strike: Source", | ||
"Corrective Style Sheet", | ||
"Computer Style Sheet" | ||
] | ||
}, | ||
{ | ||
"category": "Science: Computers", | ||
"type": "multiple", | ||
"difficulty": "easy", | ||
"question": "What is the code name for the mobile operating system Android 7.0?", | ||
"correct_answer": "Nougat", | ||
"incorrect_answers": [ | ||
"Ice Cream Sandwich", | ||
"Jelly Bean", | ||
"Marshmallow" | ||
] | ||
}, | ||
{ | ||
"category": "Science: Computers", | ||
"type": "multiple", | ||
"difficulty": "easy", | ||
"question": "On Twitter, what is the character limit for a Tweet?", | ||
"correct_answer": "140", | ||
"incorrect_answers": [ | ||
"120", | ||
"160", | ||
"100" | ||
] | ||
}, | ||
{ | ||
"category": "Science: Computers", | ||
"type": "multiple", | ||
"difficulty": "easy", | ||
"question": "Which computer language would you associate Django framework with?", | ||
"correct_answer": "Python", | ||
"incorrect_answers": [ | ||
"C#", | ||
"C++", | ||
"Java" | ||
] | ||
}, | ||
{ | ||
"category": "Science: Computers", | ||
"type": "boolean", | ||
"difficulty": "easy", | ||
"question": "The Windows 7 operating system has six main editions.", | ||
"correct_answer": "True", | ||
"incorrect_answers": [ | ||
"False" | ||
] | ||
}, | ||
{ | ||
"category": "Science: Computers", | ||
"type": "multiple", | ||
"difficulty": "easy", | ||
"question": "Which programming language shares its name with an island in Indonesia?", | ||
"correct_answer": "Java", | ||
"incorrect_answers": [ | ||
"Python", | ||
"C", | ||
"Jakarta" | ||
] | ||
} | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_custom_clippers/flutter_custom_clippers.dart'; | ||
import 'category.dart'; | ||
import 'demo_values.dart'; | ||
import 'quiz_options.dart'; | ||
|
||
class QuizHomePage extends StatelessWidget { | ||
final List<Color> tileColors = [ | ||
Colors.green, | ||
Colors.blue, | ||
Colors.purple, | ||
Colors.pink, | ||
Colors.indigo, | ||
Colors.lightBlue, | ||
Colors.amber, | ||
Colors.deepOrange, | ||
Colors.red, | ||
Colors.brown | ||
]; | ||
|
||
@override | ||
Widget build(BuildContext context){ | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text('OpenTrivia'), | ||
elevation: 0, | ||
), | ||
body: Stack( | ||
children: <Widget>[ | ||
ClipPath( | ||
clipper: WaveClipperTwo(), | ||
child: Container( | ||
decoration: BoxDecoration( | ||
color: Theme.of(context).primaryColor | ||
), | ||
height: 200, | ||
), | ||
), | ||
CustomScrollView( | ||
physics: BouncingScrollPhysics(), | ||
slivers: <Widget>[ | ||
SliverToBoxAdapter( | ||
child: Padding( | ||
padding: const EdgeInsets.symmetric(horizontal: 16.0,vertical: 8.0), | ||
child: Text("Select a category to start the quiz", style: TextStyle( | ||
color: Colors.white, | ||
fontWeight: FontWeight.w500, | ||
fontSize: 16.0 | ||
),), | ||
), | ||
), | ||
SliverPadding( | ||
padding: const EdgeInsets.all(16.0), | ||
sliver: SliverGrid( | ||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( | ||
crossAxisCount: 2, | ||
childAspectRatio: 1.2, | ||
crossAxisSpacing: 10.0, | ||
mainAxisSpacing: 10.0 | ||
), | ||
delegate: SliverChildBuilderDelegate( | ||
_buildCategoryItem, | ||
childCount: categories.length, | ||
|
||
) | ||
|
||
), | ||
), | ||
], | ||
), | ||
], | ||
) | ||
); | ||
} | ||
|
||
Widget _buildCategoryItem(BuildContext context, int index) { | ||
Category category = categories[index]; | ||
return MaterialButton( | ||
elevation: 1.0, | ||
highlightElevation: 1.0, | ||
onPressed: () => _categoryPressed(context,category), | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(10.0), | ||
), | ||
color: Colors.grey.shade800, | ||
textColor: Colors.white70, | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
if(category.icon != null) | ||
Icon(category.icon), | ||
if(category.icon != null) | ||
SizedBox(height: 5.0), | ||
Text( | ||
category.name, | ||
textAlign: TextAlign.center, | ||
maxLines: 3,), | ||
], | ||
), | ||
); | ||
} | ||
|
||
_categoryPressed(BuildContext context,Category category) { | ||
showModalBottomSheet( | ||
context: context, | ||
builder: (sheetContext) => BottomSheet( | ||
builder: (_) => QuizOptionsDialog(category: category,), | ||
onClosing: (){}, | ||
|
||
), | ||
|
||
); | ||
|
||
} | ||
} |
Oops, something went wrong.