Historico de quizzes e inicio de atualização da IA para leitura de pdfs de matemática (incompleto)

This commit is contained in:
2026-05-20 01:32:37 +01:00
parent 80ed2b1346
commit 98dcd621c7
12 changed files with 1539 additions and 271 deletions

View File

@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:go_router/go_router.dart';
import '../../../../core/services/auth_service.dart';
@@ -20,10 +19,14 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
bool _loading = true;
String _userRole = '';
// Disciplina seleccionada (null = vista de disciplinas)
String? _selectedDisciplineId;
// Turma seleccionada (null = vista de turmas)
String? _selectedClassId;
Map<String, String> _classNames = {}; // classId → name
// Search and filter
final TextEditingController _searchController = TextEditingController();
DateTime? _selectedDate;
@override
void initState() {
super.initState();
@@ -31,6 +34,24 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
_loadQuizHistory();
}
@override
void dispose() {
_searchController.dispose();
super.dispose();
}
Future<void> _selectDate() async {
final DateTime? picked = await showDatePicker(
context: context,
initialDate: _selectedDate ?? DateTime.now(),
firstDate: DateTime(2020),
lastDate: DateTime.now().add(const Duration(days: 365)),
);
if (picked != null) {
setState(() => _selectedDate = picked);
}
}
Future<void> _loadUserRole() async {
final user = AuthService.currentUser;
if (user != null) {
@@ -302,7 +323,7 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
return result ?? false;
}
Map<String, List<Map<String, dynamic>>> _groupByDiscipline() {
Map<String, List<Map<String, dynamic>>> _groupByClass() {
final Map<String, List<Map<String, dynamic>>> groups = {};
for (final quiz in _quizHistory) {
final quizClassIds = (quiz['classIds'] as List?)?.cast<String>() ?? [];
@@ -316,15 +337,69 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
return groups;
}
List<Map<String, dynamic>> _getFilteredQuizzes() {
final searchQuery = _searchController.text.toLowerCase();
return _quizHistory.where((quiz) {
// Filter by date if selected
if (_selectedDate != null) {
final quizDate = quiz['createdAt'] as Timestamp?;
if (quizDate == null) return false;
final quizDateTime = quizDate.toDate();
if (quizDateTime.year != _selectedDate!.year ||
quizDateTime.month != _selectedDate!.month ||
quizDateTime.day != _selectedDate!.day) {
return false;
}
}
// Filter by search query (class name or quiz title)
if (searchQuery.isNotEmpty) {
final title = (quiz['title'] as String? ?? '').toLowerCase();
final quizClassIds = (quiz['classIds'] as List?)?.cast<String>() ?? [];
bool matchesSearch = title.contains(searchQuery);
for (final classId in quizClassIds) {
if (_classNames.containsKey(classId)) {
final className = _classNames[classId]!.toLowerCase();
if (className.contains(searchQuery)) {
matchesSearch = true;
break;
}
}
}
if (!matchesSearch) return false;
}
return true;
}).toList();
}
Map<String, List<Map<String, dynamic>>> _getFilteredGroups() {
final filteredQuizzes = _getFilteredQuizzes();
final Map<String, List<Map<String, dynamic>>> groups = {};
for (final quiz in filteredQuizzes) {
final quizClassIds = (quiz['classIds'] as List?)?.cast<String>() ?? [];
String? groupId = quizClassIds.cast<String?>().firstWhere(
(cid) => cid != null && _classNames.containsKey(cid),
orElse: () => null,
);
groupId ??= quizClassIds.isNotEmpty ? quizClassIds.first : '__geral__';
groups.putIfAbsent(groupId, () => []).add(quiz);
}
return groups;
}
@override
Widget build(BuildContext context) {
final cs = Theme.of(context).colorScheme;
return PopScope(
canPop: _selectedDisciplineId == null,
canPop: _selectedClassId == null,
onPopInvokedWithResult: (didPop, _) {
if (!didPop && _selectedDisciplineId != null) {
setState(() => _selectedDisciplineId = null);
if (!didPop && _selectedClassId != null) {
setState(() => _selectedClassId = null);
}
},
child: Scaffold(
@@ -339,8 +414,8 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () {
if (_userRole == 'teacher' && _selectedDisciplineId != null) {
setState(() => _selectedDisciplineId = null);
if (_userRole == 'teacher' && _selectedClassId != null) {
setState(() => _selectedClassId = null);
return;
}
if (Navigator.of(context).canPop()) {
@@ -354,6 +429,44 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
}
},
),
actions: [
IconButton(
icon: const Icon(Icons.calendar_today),
onPressed: _selectDate,
tooltip: 'Filtrar por data',
),
if (_selectedDate != null)
IconButton(
icon: const Icon(Icons.clear),
onPressed: () {
setState(() => _selectedDate = null);
},
tooltip: 'Limpar filtro',
),
],
bottom: _selectedClassId == null
? PreferredSize(
preferredSize: const Size.fromHeight(60),
child: Padding(
padding: const EdgeInsets.all(8),
child: TextField(
controller: _searchController,
decoration: InputDecoration(
hintText: 'Pesquisar turma...',
prefixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
),
onChanged: (value) => setState(() {}),
),
),
)
: null,
),
body: Container(
decoration: BoxDecoration(
@@ -365,15 +478,15 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
),
child: _loading
? const Center(child: CircularProgressIndicator())
: _quizHistory.isEmpty
: _getFilteredQuizzes().isEmpty
? _buildEmptyState()
: _userRole == 'teacher'
? _buildTeacherBody(cs)
: ListView.builder(
padding: const EdgeInsets.all(16),
itemCount: _quizHistory.length,
itemCount: _getFilteredQuizzes().length,
itemBuilder: (context, index) {
final quiz = _quizHistory[index];
final quiz = _getFilteredQuizzes()[index];
return _buildQuizCard(quiz)
.animate()
.slideX(duration: const Duration(milliseconds: 300))
@@ -386,16 +499,16 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
}
Widget _buildTeacherBody(ColorScheme cs) {
final groups = _groupByDiscipline();
final groups = _searchController.text.isNotEmpty || _selectedDate != null
? _getFilteredGroups()
: _groupByClass();
// Vista de quizzes de uma disciplina
if (_selectedDisciplineId != null) {
final quizzes = groups[_selectedDisciplineId] ?? [];
final disciplineName =
_classNames[_selectedDisciplineId] ??
(_selectedDisciplineId == '__geral__'
? 'Geral'
: _selectedDisciplineId!);
// Vista de quizzes de uma turma
if (_selectedClassId != null) {
final quizzes = groups[_selectedClassId] ?? [];
final className =
_classNames[_selectedClassId] ??
(_selectedClassId == '__geral__' ? 'Geral' : _selectedClassId!);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -405,12 +518,12 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
children: [
IconButton(
icon: Icon(Icons.arrow_back, color: cs.onSurface),
onPressed: () => setState(() => _selectedDisciplineId = null),
onPressed: () => setState(() => _selectedClassId = null),
),
const SizedBox(width: 4),
Expanded(
child: Text(
disciplineName,
className,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
@@ -445,19 +558,19 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
);
}
// Vista de disciplinas
final disciplineIds = groups.keys.toList();
// Vista de turmas
final classIds = groups.keys.toList();
return ListView.separated(
padding: const EdgeInsets.all(16),
itemCount: disciplineIds.length,
itemCount: classIds.length,
separatorBuilder: (_, __) => const SizedBox(height: 12),
itemBuilder: (context, i) {
final dId = disciplineIds[i];
final dName = _classNames[dId] ?? (dId == '__geral__' ? 'Geral' : dId);
final count = groups[dId]!.length;
final cId = classIds[i];
final cName = _classNames[cId] ?? (cId == '__geral__' ? 'Geral' : cId);
final count = groups[cId]!.length;
return InkWell(
borderRadius: BorderRadius.circular(16),
onTap: () => setState(() => _selectedDisciplineId = dId),
onTap: () => setState(() => _selectedClassId = cId),
child: Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
@@ -489,7 +602,7 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
dName,
cName,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
@@ -631,7 +744,7 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
),
if (_userRole == 'teacher' &&
quiz['classIds'] != null &&
_selectedDisciplineId == null) ...[
_selectedClassId == null) ...[
const SizedBox(height: 8),
Wrap(
spacing: 4,