0% found this document useful (0 votes)
19 views6 pages

QUIZTI

This document contains a Flutter application for a quiz about Information Technology. It includes a series of questions with true or false answers, images, and tracks user scores. The app allows users to input their names and provides feedback on their answers, along with the option to reset the quiz after completion.

Uploaded by

Nicolas Tavares
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views6 pages

QUIZTI

This document contains a Flutter application for a quiz about Information Technology. It includes a series of questions with true or false answers, images, and tracks user scores. The app allows users to input their names and provides feedback on their answers, along with the option to reset the quiz after completion.

Uploaded by

Nicolas Tavares
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

//Nicolas ferreira Tavares e Luís Filipe Galdino

import 'package:flutter/material.dart';

void main() {
runApp(const QuizTiApp());
}

class QuizTiApp extends StatelessWidget {


const QuizTiApp({super.key});

@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,
});
}

class QuizComImagem extends StatefulWidget {


const QuizComImagem({super.key});

@override
State<QuizComImagem> createState() => _QuizComImagemState();
}

class _QuizComImagemState extends State<QuizComImagem> {


int _score = 0;
late Map<int, bool?> _userAnswers;
late TextEditingController _nameController;

final List<Question> _questions = const [


Question(
questionText:
'Uma VPN (Virtual Private Network) é uma rede virtual que proporciona uma
ligação privada e segura entre dois computadores, independentemente da sua
localização geográfica.',
imageUrl:
'https://i1.wp.com/blog.ingrammicro.com.br/wp-content/uploads/2021/05/
map-4636843_1920.jpg?fit=1920%2C1228&ssl=1',
correctAnswer: true,
),
Question(
questionText:
'O firewall é um componente essencial de segurança em redes, responsável
por monitorar o tráfego de entrada e saída e bloquear ameaças.',
imageUrl:

'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 _answerQuestion(int questionIndex, bool userAnswer) {


if (_userAnswers[questionIndex] == null) {
setState(() {
_userAnswers[questionIndex] = userAnswer;
if (_questions[questionIndex].correctAnswer == userAnswer) {
_score++;
}
});
}
}

void _resetQuiz() {
setState(() {
_score = 0;
_initializeQuizState();
_nameController.clear();
});
}

bool get _allQuestionsAnswered =>


_userAnswers.values.every((bool? answer) => answer != null);

@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),
],
),
),
),
);
}
}

You might also like