-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate out quiz and result, add results based on answer score
- Loading branch information
Showing
3 changed files
with
109 additions
and
26 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
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,29 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import './questions.dart'; | ||
import './answer.dart'; | ||
|
||
class Quiz extends StatelessWidget { | ||
final List<Map<String, Object>> questions; | ||
final int questionIndex; | ||
final Function(int) answerQuestion; | ||
|
||
Quiz({ | ||
required this.questions, | ||
required this.answerQuestion, | ||
required this.questionIndex, | ||
}); | ||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
Question((questions[questionIndex]['questionText'] as String)), | ||
...(questions[questionIndex]['answers'] as List<Map<String, Object>>) | ||
.map((answer) { | ||
return Answer(() => answerQuestion(answer['score'] as int), | ||
answer['text'] as String); | ||
}).toList() | ||
], | ||
); | ||
} | ||
} |
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,34 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class Result extends StatelessWidget { | ||
final int resultScore; | ||
|
||
Result(this.resultScore); | ||
|
||
String get resultPhrase { | ||
String resultText; | ||
if (resultScore <= 7) { | ||
resultText = 'You are awesome!'; | ||
} else if (resultScore <= 13) { | ||
resultText = 'Pretty likeable!'; | ||
} else { | ||
resultText = 'You weirdo!'; | ||
} | ||
return resultText; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
Center( | ||
child: Text( | ||
resultPhrase, | ||
style: const TextStyle(fontSize: 36, fontWeight: FontWeight.bold), | ||
textAlign: TextAlign.center, | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |