Created
November 26, 2019 12:19
-
-
Save santakdalai90/347da1d4ef25aeaf269d61675cea793e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import 'package:flutter/material.dart'; | |
class Answer extends StatelessWidget { | |
final List<String> answerList; | |
final String correctAnswer; | |
Answer(this.answerList, this.correctAnswer); | |
void evaluateAnswer(currentAnswer) { | |
if (correctAnswer == currentAnswer) { | |
print("Correct Answer!!!!"); | |
} else { | |
print("WRONG Answer"); | |
} | |
} | |
List<RaisedButton> getAnswerButtons() { | |
List<RaisedButton> answerButtons = new List<RaisedButton>(); | |
for (String ans in answerList) { | |
RaisedButton r = new RaisedButton( | |
child: Text(ans), | |
color: Colors.blue, | |
textColor: Colors.white, | |
onPressed: () => evaluateAnswer(ans), | |
); | |
answerButtons.add(r); | |
} | |
return answerButtons; | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
width: double.infinity, | |
margin: EdgeInsets.all(10), | |
child: Column( | |
children: getAnswerButtons(), | |
crossAxisAlignment: CrossAxisAlignment.start, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment