Skip to content

Instantly share code, notes, and snippets.

@gboliknow
Created January 20, 2023 15:09
Show Gist options
  • Save gboliknow/6c204bbfa2d301b255246a0717c81753 to your computer and use it in GitHub Desktop.
Save gboliknow/6c204bbfa2d301b255246a0717c81753 to your computer and use it in GitHub Desktop.
Quiz App
class QuizWidget extends StatefulWidget {
const QuizWidget({
super.key,
required this.quizModel,
});
final QuizModel quizModel;
@override
State<QuizWidget> createState() => _QuizWidgetState();
}
class _QuizWidgetState extends State<QuizWidget> {
int selected = -1;
void toggle(int pageNum) {
setState(() {
selected = pageNum;
});
}
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
AppText(
fontSize: 16.sp,
height: 19.2 / 16,
text: widget.quizModel.questionText,
color: grey700,
weight: FontWeight.w400,
textAlign: TextAlign.start,
),
SizedBox(
height: 32.h,
),
ListView.builder(
itemCount: widget.quizModel.options.length,
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return OptionCard(
option: widget.quizModel.options[index].optionText,
clicked: selected == index,
onTap: () {
toggle(index);
},
);
},
),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment