You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.7 KiB
Dart
66 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:adv_basics/answer_button.dart';
|
|
import 'package:adv_basics/data/questions.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
|
|
class QuestionsScreen extends StatefulWidget {
|
|
const QuestionsScreen({
|
|
super.key,
|
|
required this.onSelectAnswer,
|
|
});
|
|
|
|
final void Function(String answer) onSelectAnswer;
|
|
|
|
@override
|
|
State<QuestionsScreen> createState() {
|
|
return _QuestionsScreenState();
|
|
}
|
|
}
|
|
|
|
class _QuestionsScreenState extends State<QuestionsScreen> {
|
|
var currentQuestionIndex = 0;
|
|
|
|
void answerQuestion(String selectedAnswer) {
|
|
widget.onSelectAnswer(selectedAnswer);
|
|
setState(() {
|
|
currentQuestionIndex++;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(context) {
|
|
final currentQuestion = questions[currentQuestionIndex];
|
|
|
|
return SizedBox(
|
|
width: double.infinity,
|
|
child: Container(
|
|
margin: const EdgeInsets.all(40),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Text(
|
|
currentQuestion.text,
|
|
style: GoogleFonts.lato(
|
|
color: const Color.fromARGB(255, 201, 153, 251),
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 30),
|
|
...currentQuestion.shuffeldAnswers.map((answer) {
|
|
return AnswerButton(
|
|
answerText: answer,
|
|
onTap: () {
|
|
answerQuestion(answer);
|
|
},
|
|
);
|
|
})
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|