Skip to content

Instantly share code, notes, and snippets.

@santakdalai90
Created November 26, 2019 12:19
Show Gist options
  • Save santakdalai90/347da1d4ef25aeaf269d61675cea793e to your computer and use it in GitHub Desktop.
Save santakdalai90/347da1d4ef25aeaf269d61675cea793e to your computer and use it in GitHub Desktop.
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