QUIZTI
QUIZTI
import 'package:flutter/material.dart';
void main() {
runApp(const QuizTiApp());
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Quiz sobre Tecnologia da Informação',
home: const QuizComImagem(),
debugShowCheckedModeBanner: false,
);
}
}
class Question {
final String questionText;
final String imageUrl;
final bool correctAnswer;
const Question({
required this.questionText,
required this.imageUrl,
required this.correctAnswer,
});
}
@override
State<QuizComImagem> createState() => _QuizComImagemState();
}
'https://www.avast.com/hs-fs/hubfs/New_Avast_Academy/what_is_a_firewall_and_do_you_
need_one_academy_refresh/Firewall-01.png?width=1320&height=600&name=Firewall-
01.png',
correctAnswer: true,
),
Question(
questionText:
'Em redes de computadores, o protocolo TCP/IP (Transmission Control
Protocol/Internet Protocol) é apenas utilizado para a comunicação entre
computadores em uma rede local.',
imageUrl:
'https://www.simplilearn.com/ice9/free_resources_article_thumb/TCP_Model_1.png',
correctAnswer: false,
),
Question(
questionText:
'A Inteligência Artificial (IA) e o Machine Learning (ML) podem ser
usados para criar sistemas de segurança que detectam e previnem ataques
cibernéticos.',
imageUrl:
'https://phoenixnap.com/glossary/wp-content/uploads/2024/07/what-is-ai-
as-a-service.jpg',
correctAnswer: true,
),
];
@override
void initState() {
super.initState();
_initializeQuizState();
_nameController = TextEditingController();
}
@override
void dispose() {
_nameController.dispose();
super.dispose();
}
void _initializeQuizState() {
_userAnswers = {};
for (int i = 0; i < _questions.length; i++) {
_userAnswers[i] = null;
}
}
void _resetQuiz() {
setState(() {
_score = 0;
_initializeQuizState();
_nameController.clear();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Quiz sobre Tecnologia da Informação'),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
TextField(
controller: _nameController,
decoration: const InputDecoration(
labelText: 'Seu Nome',
hintText: 'Digite seu nome aqui',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.name,
textCapitalization: TextCapitalization.words,
),
const SizedBox(height: 20),
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.only(bottom: 20.0),
),
),
..._questions.asMap().entries.map<Widget>(
(MapEntry<int, Question> entry) {
final int index = entry.key;
final Question question = entry.value;
final bool? userAnswer = _userAnswers[index];
final bool isAnswered = userAnswer != null;
final bool isCorrect =
isAnswered && (userAnswer == question.correctAnswer);
return Card(
margin: const EdgeInsets.only(bottom: 20),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image.network(
question.imageUrl,
fit: BoxFit.cover,
height: 200,
width: double.infinity,
errorBuilder: (BuildContext context, Object error,
StackTrace? stackTrace) =>
const Icon(Icons.error_outline,
size: 100, color: Colors.red),
),
),
const SizedBox(height: 15),
Text(
'${index + 1}) ${question.questionText}',
style: Theme.of(context).textTheme.titleLarge,
textAlign: TextAlign.center,
),
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: ElevatedButton(
onPressed: isAnswered
? null
: () => _answerQuestion(index, true),
style: ElevatedButton.styleFrom(
padding:
const EdgeInsets.symmetric(vertical: 15),
),
child: Text(
"Verdadeiro",
style: Theme.of(context)
.textTheme
.labelLarge!
.copyWith(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
),
const SizedBox(width: 10),
Expanded(
child: ElevatedButton(
onPressed: isAnswered
? null
: () => _answerQuestion(index, false),
style: ElevatedButton.styleFrom(
padding:
const EdgeInsets.symmetric(vertical: 15),
),
child: Text(
"Falso",
style: Theme.of(context)
.textTheme
.labelLarge!
.copyWith(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
if (isAnswered) ...[
const SizedBox(height: 10),
Text(
isCorrect ? 'Correto!' : 'Incorreto.',
style: Theme.of(context)
.textTheme
.bodyLarge!
.copyWith(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
],
],
),
),
);
},
)
.toList(),
const SizedBox(height: 30),
if (_allQuestionsAnswered) ...[
Text(
'Quiz Concluído!',
style: Theme.of(context).textTheme.headlineMedium,
textAlign: TextAlign.center,
),
const SizedBox(height: 20),
Text(
'Parabéns, ${_nameController.text.isNotEmpty ?
_nameController.text : 'participante'}!',
style: Theme.of(context).textTheme.headlineSmall,
textAlign: TextAlign.center,
),
const SizedBox(height: 10),
Text(
'Sua pontuação final: $_score de ${_questions.length}',
style: Theme.of(context).textTheme.headlineSmall,
textAlign: TextAlign.center,
),
const SizedBox(height: 30),
ElevatedButton(
onPressed: _resetQuiz,
style: ElevatedButton.styleFrom(
padding:
const EdgeInsets.symmetric(horizontal: 40, vertical: 15),
),
child: const Text(
'Reiniciar Quiz',
style: TextStyle(fontSize: 18),
),
),
],
const SizedBox(height: 20),
],
),
),
),
);
}
}