|
import 'package:flutter/material.dart'; |
|
|
|
enum TaskPriority { low, medium, high, veryHigh } |
|
|
|
class TodoApp extends StatelessWidget { |
|
final List<Task> tasks; // Declaração da lista de tarefas |
|
|
|
TodoApp( |
|
{required this.tasks}); // Atribuição da lista de tarefas no construtor |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return MaterialApp( |
|
title: 'Agendador Master', |
|
theme: ThemeData( |
|
primarySwatch: Colors.blue, |
|
brightness: Brightness.light, |
|
), |
|
darkTheme: ThemeData( |
|
primarySwatch: Colors.blue, |
|
brightness: Brightness.dark, |
|
), |
|
themeMode: ThemeMode.system, |
|
home: TodoListScreen( |
|
tasks: tasks), // Passagem da lista de tarefas para TodoListScreen |
|
); |
|
} |
|
} |
|
|
|
class TodoListScreen extends StatefulWidget { |
|
final List<Task> |
|
tasks; // Declaração da lista de tarefas como parâmetro obrigatório |
|
|
|
TodoListScreen( |
|
{required this.tasks}); // Atribuição da lista de tarefas no construtor |
|
|
|
@override |
|
_TodoListScreenState createState() => _TodoListScreenState(); |
|
} |
|
|
|
class _TodoListScreenState extends State<TodoListScreen> { |
|
List<Task> tasks = []; |
|
String _welcomeText = "Boas Vindas ao Agendador Master"; |
|
TaskPriority? _selectedPriority; |
|
bool _showCompletedTasks = true; |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
tasks = widget.tasks; |
|
} |
|
|
|
void addTask(Task task) { |
|
setState(() { |
|
tasks.add(task); |
|
}); |
|
} |
|
|
|
void markTaskAsDone(Task task) { |
|
setState(() { |
|
task.isDone = true; |
|
}); |
|
} |
|
|
|
void markTaskAsUndone(Task task) { |
|
setState(() { |
|
task.isDone = false; |
|
}); |
|
} |
|
|
|
void deleteTask(Task task) { |
|
setState(() { |
|
tasks.remove(task); |
|
}); |
|
} |
|
|
|
void showTaskDetails(Task task) { |
|
showDialog( |
|
context: context, |
|
builder: (context) { |
|
return AlertDialog( |
|
title: Text('Detalhes da Tarefa'), |
|
content: Column( |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
mainAxisSize: MainAxisSize.min, |
|
children: [ |
|
Text('Descrição: ${task.description}'), |
|
SizedBox(height: 8.0), |
|
Text('Data: ${task.date.toString()}'), |
|
], |
|
), |
|
actions: [ |
|
ElevatedButton( |
|
onPressed: () => Navigator.of(context).pop(), |
|
child: Text('Fechar'), |
|
), |
|
], |
|
); |
|
}, |
|
); |
|
} |
|
|
|
void editTask(Task task) { |
|
showDialog( |
|
context: context, |
|
builder: (context) { |
|
String editedTaskTitle = task.title; |
|
String editedTaskDescription = task.description; |
|
TaskPriority editedTaskPriority = task.priority; |
|
DateTime editedTaskDate = task.date; |
|
|
|
return StatefulBuilder( |
|
builder: (context, setState) { |
|
return AlertDialog( |
|
title: Text('Editar Tarefa'), |
|
content: Column( |
|
mainAxisSize: MainAxisSize.min, |
|
children: [ |
|
TextField( |
|
onChanged: (value) { |
|
editedTaskTitle = value; |
|
}, |
|
decoration: InputDecoration(labelText: 'Tarefa'), |
|
controller: TextEditingController(text: editedTaskTitle), |
|
), |
|
TextField( |
|
onChanged: (value) { |
|
editedTaskDescription = value; |
|
}, |
|
decoration: InputDecoration(labelText: 'Descrição'), |
|
controller: |
|
TextEditingController(text: editedTaskDescription), |
|
), |
|
DropdownButtonFormField<TaskPriority>( |
|
value: editedTaskPriority, |
|
items: [ |
|
DropdownMenuItem<TaskPriority>( |
|
child: Text('Baixa'), |
|
value: TaskPriority.low, |
|
), |
|
DropdownMenuItem<TaskPriority>( |
|
child: Text('Média'), |
|
value: TaskPriority.medium, |
|
), |
|
DropdownMenuItem<TaskPriority>( |
|
child: Text('Alta'), |
|
value: TaskPriority.high, |
|
), |
|
DropdownMenuItem<TaskPriority>( |
|
child: Text('Muito Alta'), |
|
value: TaskPriority.veryHigh, |
|
), |
|
], |
|
onChanged: (value) { |
|
setState(() { |
|
editedTaskPriority = value!; |
|
}); |
|
}, |
|
decoration: InputDecoration( |
|
labelText: 'Prioridade', |
|
labelStyle: TextStyle(fontSize: 18), |
|
), |
|
), |
|
SizedBox(height: 16.0), |
|
Text( |
|
'Data da Tarefa:', |
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18), |
|
), |
|
SizedBox(height: 8.0), |
|
InkWell( |
|
onTap: () async { |
|
final selectedDate = await showDatePicker( |
|
context: context, |
|
initialDate: editedTaskDate, |
|
firstDate: DateTime(2021), |
|
lastDate: DateTime(2025), |
|
); |
|
if (selectedDate != null) { |
|
setState(() { |
|
editedTaskDate = selectedDate; |
|
}); |
|
} |
|
}, |
|
child: Container( |
|
decoration: BoxDecoration( |
|
border: Border.all(color: Colors.grey), |
|
borderRadius: BorderRadius.circular(4.0), |
|
), |
|
padding: EdgeInsets.all(12.0), |
|
child: Text( |
|
editedTaskDate.toString().split(' ')[0], |
|
style: TextStyle(fontSize: 16), |
|
), |
|
), |
|
), |
|
], |
|
), |
|
actions: [ |
|
ElevatedButton( |
|
onPressed: () { |
|
if (editedTaskTitle.isNotEmpty) { |
|
final editedTask = Task( |
|
title: editedTaskTitle, |
|
description: editedTaskDescription, |
|
priority: editedTaskPriority, |
|
date: editedTaskDate, |
|
isDone: task.isDone, |
|
); |
|
setState(() { |
|
tasks[tasks.indexOf(task)] = editedTask; |
|
}); |
|
Navigator.of(context).pop(); |
|
} |
|
}, |
|
child: Text('Salvar'), |
|
), |
|
], |
|
); |
|
}, |
|
); |
|
}, |
|
); |
|
} |
|
|
|
Color getPriorityColor(TaskPriority priority) { |
|
switch (priority) { |
|
case TaskPriority.low: |
|
return Colors.greenAccent.shade700; // Cor para a prioridade "Baixa" |
|
case TaskPriority.medium: |
|
return Colors.yellow.shade600; // Cor para a prioridade "Media" |
|
case TaskPriority.high: |
|
return Colors.deepOrange.shade600; // Cor para a prioridade "Alta" |
|
case TaskPriority.veryHigh: |
|
return Colors.redAccent.shade700; // Cor para a prioridade "Muito Alta" |
|
} |
|
} |
|
|
|
void sortTasksByPriority() { |
|
setState(() { |
|
tasks.sort((a, b) => a.priority.index.compareTo(b.priority.index)); |
|
}); |
|
} |
|
|
|
void sortTasksByDate() { |
|
setState(() { |
|
tasks.sort((a, b) => a.date.compareTo(b.date)); |
|
}); |
|
} |
|
|
|
void sortTasksByTitle() { |
|
setState(() { |
|
tasks.sort((a, b) => a.title.compareTo(b.title)); |
|
}); |
|
} |
|
|
|
void toggleShowCompletedTasks() { |
|
setState(() { |
|
_showCompletedTasks = !_showCompletedTasks; |
|
}); |
|
} |
|
|
|
List<Task> getFilteredTasks() { |
|
if (!_showCompletedTasks) { |
|
return tasks.where((task) => !task.isDone).toList(); |
|
} |
|
return tasks; |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
String _message = tasks.isEmpty ? _welcomeText : "Suas tarefas:"; |
|
|
|
return Scaffold( |
|
appBar: AppBar( |
|
title: Text( |
|
'Agendador Master', |
|
style: TextStyle(fontSize: 20), |
|
), |
|
actions: [ |
|
PopupMenuButton<String>( |
|
onSelected: (value) { |
|
if (value == 'priority') { |
|
sortTasksByPriority(); |
|
} else if (value == 'date') { |
|
sortTasksByDate(); |
|
} else if (value == 'title') { |
|
sortTasksByTitle(); |
|
} |
|
}, |
|
itemBuilder: (BuildContext context) => [ |
|
PopupMenuItem<String>( |
|
child: Text('Ordenar por Prioridade'), |
|
value: 'priority', |
|
), |
|
PopupMenuItem<String>( |
|
child: Text('Ordenar por Data'), |
|
value: 'date', |
|
), |
|
PopupMenuItem<String>( |
|
child: Text('Ordenar por Título'), |
|
value: 'title', |
|
), |
|
], |
|
), |
|
IconButton( |
|
onPressed: toggleShowCompletedTasks, |
|
icon: Icon( |
|
_showCompletedTasks |
|
? Icons.check_box |
|
: Icons.check_box_outline_blank, |
|
), |
|
), |
|
], |
|
), |
|
body: ListView.builder( |
|
itemCount: getFilteredTasks().length, |
|
itemBuilder: (context, index) { |
|
final task = getFilteredTasks()[index]; |
|
return ListTile( |
|
title: Text( |
|
task.title, |
|
style: TextStyle( |
|
decoration: task.isDone ? TextDecoration.lineThrough : null, |
|
), |
|
), |
|
subtitle: Text(task.description), |
|
leading: CircleAvatar( |
|
backgroundColor: getPriorityColor(task.priority), |
|
), |
|
trailing: Row( |
|
mainAxisSize: MainAxisSize.min, |
|
children: [ |
|
IconButton( |
|
onPressed: () => showTaskDetails(task), |
|
icon: Icon(Icons.info_outline), |
|
), |
|
IconButton( |
|
onPressed: () => editTask(task), |
|
icon: Icon(Icons.edit), |
|
), |
|
IconButton( |
|
onPressed: () => deleteTask(task), |
|
icon: Icon(Icons.delete), |
|
), |
|
IconButton( |
|
onPressed: () { |
|
if (task.isDone) { |
|
markTaskAsUndone(task); |
|
} else { |
|
markTaskAsDone(task); |
|
} |
|
}, |
|
icon: Icon( |
|
task.isDone |
|
? Icons.check_box |
|
: Icons.check_box_outline_blank, |
|
), |
|
), |
|
], |
|
), |
|
); |
|
}, |
|
), |
|
floatingActionButton: FloatingActionButton( |
|
onPressed: () => _showAddTaskScreen(context), |
|
child: Icon(Icons.add), |
|
), |
|
); |
|
} |
|
|
|
void _showAddTaskScreen(BuildContext context) { |
|
Navigator.of(context).push( |
|
MaterialPageRoute( |
|
builder: (context) => AddTaskScreen(addTask), |
|
), |
|
); |
|
} |
|
} |
|
|
|
class AddTaskScreen extends StatefulWidget { |
|
final Function(Task) addTaskCallback; |
|
|
|
AddTaskScreen(this.addTaskCallback); |
|
|
|
@override |
|
_AddTaskScreenState createState() => _AddTaskScreenState(); |
|
} |
|
|
|
class _AddTaskScreenState extends State<AddTaskScreen> { |
|
String _taskTitle = ''; |
|
String _taskDescription = ''; |
|
TaskPriority _taskPriority = TaskPriority.low; |
|
DateTime _taskDate = DateTime.now(); |
|
|
|
void _addTask() { |
|
if (_taskTitle.isNotEmpty) { |
|
final newTask = Task( |
|
title: _taskTitle, |
|
description: _taskDescription, |
|
priority: _taskPriority, |
|
date: _taskDate, |
|
isDone: false, |
|
); |
|
widget.addTaskCallback(newTask); |
|
Navigator.of(context).pop(); |
|
} |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Scaffold( |
|
appBar: AppBar( |
|
title: Text('Adicionar Tarefa'), |
|
), |
|
body: Padding( |
|
padding: EdgeInsets.all(16.0), |
|
child: Column( |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
TextField( |
|
onChanged: (value) { |
|
setState(() { |
|
_taskTitle = value; |
|
}); |
|
}, |
|
decoration: InputDecoration(labelText: 'Tarefa'), |
|
), |
|
SizedBox(height: 16.0), |
|
TextField( |
|
onChanged: (value) { |
|
setState(() { |
|
_taskDescription = value; |
|
}); |
|
}, |
|
decoration: InputDecoration(labelText: 'Descrição'), |
|
), |
|
SizedBox(height: 16.0), |
|
DropdownButtonFormField<TaskPriority>( |
|
value: _taskPriority, |
|
items: [ |
|
DropdownMenuItem<TaskPriority>( |
|
child: Text('Baixa'), |
|
value: TaskPriority.low, |
|
), |
|
DropdownMenuItem<TaskPriority>( |
|
child: Text('Média'), |
|
value: TaskPriority.medium, |
|
), |
|
DropdownMenuItem<TaskPriority>( |
|
child: Text('Alta'), |
|
value: TaskPriority.high, |
|
), |
|
DropdownMenuItem<TaskPriority>( |
|
child: Text('Muito Alta'), |
|
value: TaskPriority.veryHigh, |
|
), |
|
], |
|
onChanged: (value) { |
|
setState(() { |
|
_taskPriority = value!; |
|
}); |
|
}, |
|
decoration: InputDecoration( |
|
labelText: 'Prioridade', |
|
labelStyle: TextStyle(fontSize: 18), |
|
), |
|
), |
|
SizedBox(height: 16.0), |
|
Text( |
|
'Data da Tarefa:', |
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18), |
|
), |
|
SizedBox(height: 8.0), |
|
InkWell( |
|
onTap: () async { |
|
final selectedDate = await showDatePicker( |
|
context: context, |
|
initialDate: _taskDate, |
|
firstDate: DateTime(2021), |
|
lastDate: DateTime(2025), |
|
); |
|
if (selectedDate != null) { |
|
setState(() { |
|
_taskDate = selectedDate; |
|
}); |
|
} |
|
}, |
|
child: Container( |
|
decoration: BoxDecoration( |
|
border: Border.all(color: Colors.grey), |
|
borderRadius: BorderRadius.circular(4.0), |
|
), |
|
padding: EdgeInsets.all(12.0), |
|
child: Text( |
|
_taskDate.toString().split(' ')[0], |
|
style: TextStyle(fontSize: 16), |
|
), |
|
), |
|
), |
|
SizedBox(height: 16.0), |
|
ElevatedButton( |
|
onPressed: _addTask, |
|
child: Text('Adicionar'), |
|
), |
|
], |
|
), |
|
), |
|
); |
|
} |
|
} |
|
|
|
class Task { |
|
final String title; |
|
final String description; |
|
final TaskPriority priority; |
|
final DateTime date; |
|
bool isDone; |
|
|
|
Task({ |
|
required this.title, |
|
required this.description, |
|
required this.priority, |
|
required this.date, |
|
this.isDone = false, |
|
}); |
|
} |
|
|
|
void main() { |
|
List<Task> exampleTasks = [ |
|
Task( |
|
title: 'Comprar mantimentos', |
|
description: 'Comprar leite, pão e ovos', |
|
priority: TaskPriority.medium, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
// ... outras tarefas ... |
|
Task( |
|
title: 'Tarefa Muito Alta', |
|
description: 'Exemplo de tarefa com prioridade "Muito Alta"', |
|
priority: TaskPriority.veryHigh, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Enviar relatório mensal', |
|
description: 'Preparar e enviar o relatório de vendas mensal', |
|
priority: TaskPriority.high, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Comprar mantimentos', |
|
description: 'Comprar leite, pão e ovos', |
|
priority: TaskPriority.medium, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Fazer exercícios', |
|
description: 'Fazer 30 minutos de exercícios aeróbicos', |
|
priority: TaskPriority.high, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Ler livro', |
|
description: 'Ler o capítulo 5 do livro "A Arte da Programação"', |
|
priority: TaskPriority.low, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Ir à academia', |
|
description: 'Fazer treino de musculação por 1 hora', |
|
priority: TaskPriority.high, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Pagar contas', |
|
description: 'Pagar as contas de água, luz e internet', |
|
priority: TaskPriority.medium, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Estudar para a prova', |
|
description: 'Revisar os capítulos 1 a 3 do livro de matemática', |
|
priority: TaskPriority.low, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Limpar a casa', |
|
description: 'Limpar todos os cômodos da casa', |
|
priority: TaskPriority.medium, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Preparar o jantar', |
|
description: 'Fazer macarrão com molho de tomate', |
|
priority: TaskPriority.low, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Enviar relatório', |
|
description: 'Preparar e enviar o relatório mensal', |
|
priority: TaskPriority.high, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Marcar consulta', |
|
description: 'Marcar consulta médica para a próxima semana', |
|
priority: TaskPriority.high, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Responder e-mails', |
|
description: 'Responder e-mails pendentes', |
|
priority: TaskPriority.medium, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Estudar idiomas', |
|
description: 'Praticar conversação em inglês e espanhol', |
|
priority: TaskPriority.low, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Planejar viagem', |
|
description: 'Pesquisar destinos e reservar passagens', |
|
priority: TaskPriority.high, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Fazer check-up médico', |
|
description: 'Agendar e fazer exames de rotina', |
|
priority: TaskPriority.high, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
Task( |
|
title: 'Organizar documentos', |
|
description: 'Organizar e arquivar documentos importantes', |
|
priority: TaskPriority.medium, |
|
date: DateTime.now(), |
|
isDone: false, |
|
), |
|
]; |
|
|
|
runApp(TodoApp(tasks: exampleTasks)); |
|
} |