Muitas coisas e já me esqueci delas todas, cenas principalmente no dashboard do aluno bug fixes e etc

This commit is contained in:
2026-05-17 19:42:49 +01:00
parent 7a26223a01
commit e388ca3b67
20 changed files with 1989 additions and 1224 deletions

View File

@@ -24,11 +24,11 @@ class _QuizQuestion {
});
Map<String, dynamic> toJson() => {
'q': question,
'opts': options,
'ans': correctIndex,
'exp': explanation,
};
'q': question,
'opts': options,
'ans': correctIndex,
'exp': explanation,
};
static _QuizQuestion? fromMap(dynamic e) {
if (e is! Map) return null;
@@ -38,7 +38,12 @@ class _QuizQuestion {
final exp = e['exp'] as String? ?? '';
if (q == null || opts == null || ans == null) return null;
if (opts.length < 2 || ans < 0 || ans >= opts.length) return null;
return _QuizQuestion(question: q, options: opts, correctIndex: ans, explanation: exp);
return _QuizQuestion(
question: q,
options: opts,
correctIndex: ans,
explanation: exp,
);
}
}
@@ -98,17 +103,33 @@ class _TeacherQuizPageState extends State<TeacherQuizPage>
Future<void> _loadMaterials() async {
try {
final uid = FirebaseAuth.instance.currentUser?.uid;
if (uid == null) { if (mounted) setState(() => _loadingMaterials = false); return; }
if (uid == null) {
if (mounted) setState(() => _loadingMaterials = false);
return;
}
final snap = await FirebaseFirestore.instance
.collection('materials')
.where('teacherId', isEqualTo: uid)
.orderBy('createdAt', descending: true)
.get();
final mats = snap.docs
.where((d) => (d.data()['fileName'] as String? ?? '').toLowerCase().endsWith('.pdf'))
.map((d) => {'id': d.id, 'name': d.data()['fileName'] as String? ?? 'Material'})
.where(
(d) => (d.data()['fileName'] as String? ?? '')
.toLowerCase()
.endsWith('.pdf'),
)
.map(
(d) => {
'id': d.id,
'name': d.data()['fileName'] as String? ?? 'Material',
},
)
.toList();
if (mounted) setState(() { _materials = mats; _loadingMaterials = false; });
if (mounted)
setState(() {
_materials = mats;
_loadingMaterials = false;
});
} catch (e) {
Logger.error('Teacher quiz load materials: $e');
if (mounted) setState(() => _loadingMaterials = false);
@@ -118,7 +139,10 @@ class _TeacherQuizPageState extends State<TeacherQuizPage>
Future<void> _loadHistory() async {
try {
final uid = FirebaseAuth.instance.currentUser?.uid;
if (uid == null) { if (mounted) setState(() => _loadingHistory = false); return; }
if (uid == null) {
if (mounted) setState(() => _loadingHistory = false);
return;
}
final snap = await FirebaseFirestore.instance
.collection('teacherQuizzes')
.where('teacherId', isEqualTo: uid)
@@ -126,7 +150,11 @@ class _TeacherQuizPageState extends State<TeacherQuizPage>
.limit(30)
.get();
final list = snap.docs.map((d) => {'id': d.id, ...d.data()}).toList();
if (mounted) setState(() { _history = list; _loadingHistory = false; });
if (mounted)
setState(() {
_history = list;
_loadingHistory = false;
});
} catch (e) {
Logger.error('Teacher quiz load history: $e');
if (mounted) setState(() => _loadingHistory = false);
@@ -163,7 +191,8 @@ class _TeacherQuizPageState extends State<TeacherQuizPage>
final questions = _parseQuizJson(raw);
if (questions.isEmpty) {
if (mounted) _showSnack('Não foi possível gerar o quiz. Tenta novamente.');
if (mounted)
_showSnack('Não foi possível gerar o quiz. Tenta novamente.');
return;
}
@@ -242,16 +271,14 @@ class _TeacherQuizPageState extends State<TeacherQuizPage>
),
body: TabBarView(
controller: _tabController,
children: [
_buildMaterialsTab(cs),
_buildHistoryTab(cs),
],
children: [_buildMaterialsTab(cs), _buildHistoryTab(cs)],
),
);
}
Widget _buildMaterialsTab(ColorScheme cs) {
if (_loadingMaterials) return const Center(child: CircularProgressIndicator());
if (_loadingMaterials)
return const Center(child: CircularProgressIndicator());
if (_materials.isEmpty) {
return Center(
child: Padding(
@@ -259,13 +286,25 @@ class _TeacherQuizPageState extends State<TeacherQuizPage>
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.folder_open, size: 64, color: cs.onSurfaceVariant.withValues(alpha: 0.4)),
Icon(
Icons.folder_open,
size: 64,
color: cs.onSurfaceVariant.withValues(alpha: 0.4),
),
const SizedBox(height: 16),
Text('Sem PDFs carregados.', style: TextStyle(color: cs.onSurfaceVariant, fontSize: 16)),
Text(
'Sem PDFs carregados.',
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 16),
),
const SizedBox(height: 8),
Text('Faz upload de um PDF nos teus materiais primeiro.',
textAlign: TextAlign.center,
style: TextStyle(color: cs.onSurfaceVariant.withValues(alpha: 0.7), fontSize: 13)),
Text(
'Faz upload de um PDF nos teus materiais primeiro.',
textAlign: TextAlign.center,
style: TextStyle(
color: cs.onSurfaceVariant.withValues(alpha: 0.7),
fontSize: 13,
),
),
],
),
),
@@ -278,7 +317,9 @@ class _TeacherQuizPageState extends State<TeacherQuizPage>
itemBuilder: (context, i) {
final mat = _materials[i];
final isGenerating = _generatingForId == mat['id'];
final name = (mat['name'] ?? 'Material').replaceAll('.pdf', '').replaceAll('_', ' ');
final name = (mat['name'] ?? 'Material')
.replaceAll('.pdf', '')
.replaceAll('_', ' ');
return _MaterialCard(
name: name,
isGenerating: isGenerating,
@@ -290,7 +331,8 @@ class _TeacherQuizPageState extends State<TeacherQuizPage>
}
Widget _buildHistoryTab(ColorScheme cs) {
if (_loadingHistory) return const Center(child: CircularProgressIndicator());
if (_loadingHistory)
return const Center(child: CircularProgressIndicator());
if (_history.isEmpty) {
return Center(
child: Padding(
@@ -298,10 +340,16 @@ class _TeacherQuizPageState extends State<TeacherQuizPage>
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.history, size: 64, color: cs.onSurfaceVariant.withValues(alpha: 0.4)),
Icon(
Icons.history,
size: 64,
color: cs.onSurfaceVariant.withValues(alpha: 0.4),
),
const SizedBox(height: 16),
Text('Ainda não criaste nenhum quiz.',
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 16)),
Text(
'Ainda não criaste nenhum quiz.',
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 16),
),
],
),
),
@@ -328,10 +376,19 @@ class _TeacherQuizPageState extends State<TeacherQuizPage>
color: cs.surface,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: cs.outline.withValues(alpha: 0.15)),
boxShadow: [BoxShadow(color: cs.shadow.withValues(alpha: 0.05), blurRadius: 8, offset: const Offset(0, 2))],
boxShadow: [
BoxShadow(
color: cs.shadow.withValues(alpha: 0.05),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
leading: Container(
width: 44,
height: 44,
@@ -341,12 +398,21 @@ class _TeacherQuizPageState extends State<TeacherQuizPage>
),
child: Icon(Icons.quiz, color: cs.primary, size: 22),
),
title: Text(name,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 14, color: cs.onSurface)),
title: Text(
name,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 14,
color: cs.onSurface,
),
),
subtitle: dateStr.isNotEmpty
? Text(dateStr, style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant))
? Text(
dateStr,
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant),
)
: null,
trailing: Icon(Icons.bar_chart, color: cs.onSurfaceVariant),
onTap: () => _showResultsPopup(item),
@@ -375,7 +441,12 @@ class _MaterialCard extends StatelessWidget {
final bool isGenerating;
final VoidCallback? onTap;
final ColorScheme cs;
const _MaterialCard({required this.name, required this.isGenerating, required this.onTap, required this.cs});
const _MaterialCard({
required this.name,
required this.isGenerating,
required this.onTap,
required this.cs,
});
@override
Widget build(BuildContext context) {
@@ -384,7 +455,13 @@ class _MaterialCard extends StatelessWidget {
color: cs.surface,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: cs.outline.withValues(alpha: 0.15)),
boxShadow: [BoxShadow(color: cs.shadow.withValues(alpha: 0.05), blurRadius: 8, offset: const Offset(0, 2))],
boxShadow: [
BoxShadow(
color: cs.shadow.withValues(alpha: 0.05),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
@@ -397,17 +474,28 @@ class _MaterialCard extends StatelessWidget {
),
child: Icon(Icons.picture_as_pdf, color: cs.secondary, size: 22),
),
title: Text(name,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 14, color: cs.onSurface)),
subtitle: Text('Gerar quiz com IA',
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant)),
title: Text(
name,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 14,
color: cs.onSurface,
),
),
subtitle: Text(
'Gerar quiz com IA',
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant),
),
trailing: isGenerating
? SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(strokeWidth: 2.5, color: cs.primary),
child: CircularProgressIndicator(
strokeWidth: 2.5,
color: cs.primary,
),
)
: Icon(Icons.auto_awesome, color: cs.primary, size: 26),
onTap: onTap,
@@ -445,14 +533,16 @@ class _QuizEditorPageState extends State<_QuizEditorPage> {
super.initState();
// cópia editável
_questions = widget.questions
.map((q) => _QuizQuestion(
question: q.question,
options: List<String>.from(q.options),
correctIndex: q.correctIndex,
explanation: q.explanation,
))
.map(
(q) => _QuizQuestion(
question: q.question,
options: List<String>.from(q.options),
correctIndex: q.correctIndex,
explanation: q.explanation,
),
)
.toList();
// selecionar todas as turmas por defeito
// selecionar todas as disciplinas por defeito
for (final c in widget.availableClasses) {
if (c['id'] != null) _selectedClassIds.add(c['id']!);
}
@@ -460,12 +550,14 @@ class _QuizEditorPageState extends State<_QuizEditorPage> {
void _addBlankQuestion() {
setState(() {
_questions.add(_QuizQuestion(
question: '',
options: ['A) ', 'B) ', 'C) ', 'D) '],
correctIndex: 0,
explanation: '',
));
_questions.add(
_QuizQuestion(
question: '',
options: ['A) ', 'B) ', 'C) ', 'D) '],
correctIndex: 0,
explanation: '',
),
);
});
}
@@ -488,7 +580,10 @@ class _QuizEditorPageState extends State<_QuizEditorPage> {
Logger.error('Error publishing teacher quiz: $e');
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Erro ao publicar: $e'), behavior: SnackBarBehavior.floating),
SnackBar(
content: Text('Erro ao publicar: $e'),
behavior: SnackBarBehavior.floating,
),
);
}
} finally {
@@ -514,10 +609,20 @@ class _QuizEditorPageState extends State<_QuizEditorPage> {
_saving
? const Padding(
padding: EdgeInsets.only(right: 16),
child: Center(child: SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2))),
child: Center(
child: SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(strokeWidth: 2),
),
),
)
: TextButton.icon(
onPressed: (widget.availableClasses.isEmpty || _selectedClassIds.isNotEmpty) ? _publish : null,
onPressed:
(widget.availableClasses.isEmpty ||
_selectedClassIds.isNotEmpty)
? _publish
: null,
icon: const Icon(Icons.publish),
label: const Text('Publicar'),
),
@@ -525,7 +630,7 @@ class _QuizEditorPageState extends State<_QuizEditorPage> {
),
body: ListView.builder(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 32),
itemCount: _questions.length + 2, // +1 turmas header +1 add button
itemCount: _questions.length + 2, // +1 disciplinas header +1 add button
itemBuilder: (context, i) {
if (i == 0) return _buildClassSelector(cs);
if (i == _questions.length + 1) {
@@ -537,7 +642,9 @@ class _QuizEditorPageState extends State<_QuizEditorPage> {
label: const Text('Adicionar Pergunta'),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
);
@@ -569,7 +676,13 @@ class _QuizEditorPageState extends State<_QuizEditorPage> {
color: cs.surface,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: cs.outline.withValues(alpha: 0.2)),
boxShadow: [BoxShadow(color: cs.shadow.withValues(alpha: 0.05), blurRadius: 8, offset: const Offset(0, 2))],
boxShadow: [
BoxShadow(
color: cs.shadow.withValues(alpha: 0.05),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -578,8 +691,14 @@ class _QuizEditorPageState extends State<_QuizEditorPage> {
children: [
Icon(Icons.groups, color: cs.primary, size: 20),
const SizedBox(width: 8),
Text('Turmas com acesso',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: cs.onSurface)),
Text(
'Disciplinas com acesso',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: cs.onSurface,
),
),
],
),
const SizedBox(height: 12),
@@ -591,21 +710,39 @@ class _QuizEditorPageState extends State<_QuizEditorPage> {
final name = c['name'] ?? id;
final selected = _selectedClassIds.contains(id);
return FilterChip(
label: Text(name, style: TextStyle(fontSize: 13, color: selected ? cs.onPrimary : cs.onSurface)),
label: Text(
name,
style: TextStyle(
fontSize: 13,
color: selected ? cs.onPrimary : cs.onSurface,
),
),
selected: selected,
onSelected: (v) => setState(() => v ? _selectedClassIds.add(id) : _selectedClassIds.remove(id)),
onSelected: (v) => setState(
() => v
? _selectedClassIds.add(id)
: _selectedClassIds.remove(id),
),
selectedColor: cs.primary,
checkmarkColor: cs.onPrimary,
backgroundColor: cs.surfaceContainerHighest.withValues(alpha: 0.5),
side: BorderSide(color: selected ? cs.primary : cs.outline.withValues(alpha: 0.3)),
backgroundColor: cs.surfaceContainerHighest.withValues(
alpha: 0.5,
),
side: BorderSide(
color: selected
? cs.primary
: cs.outline.withValues(alpha: 0.3),
),
);
}).toList(),
),
if (_selectedClassIds.isEmpty)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text('Seleciona pelo menos uma turma.',
style: TextStyle(fontSize: 12, color: cs.error)),
child: Text(
'Seleciona pelo menos uma disciplina.',
style: TextStyle(fontSize: 12, color: cs.error),
),
),
],
),
@@ -621,7 +758,13 @@ class _QuestionEditor extends StatefulWidget {
final ColorScheme cs;
final VoidCallback onChanged;
final VoidCallback? onDelete;
const _QuestionEditor({required this.index, required this.question, required this.cs, required this.onChanged, this.onDelete});
const _QuestionEditor({
required this.index,
required this.question,
required this.cs,
required this.onChanged,
this.onDelete,
});
@override
State<_QuestionEditor> createState() => _QuestionEditorState();
@@ -638,7 +781,9 @@ class _QuestionEditorState extends State<_QuestionEditor> {
super.initState();
_qCtrl = TextEditingController(text: widget.question.question);
_expCtrl = TextEditingController(text: widget.question.explanation);
_optCtrl = widget.question.options.map((o) => TextEditingController(text: o)).toList();
_optCtrl = widget.question.options
.map((o) => TextEditingController(text: o))
.toList();
}
@override
@@ -666,7 +811,13 @@ class _QuestionEditorState extends State<_QuestionEditor> {
color: cs.surface,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: cs.outline.withValues(alpha: 0.2)),
boxShadow: [BoxShadow(color: cs.shadow.withValues(alpha: 0.05), blurRadius: 8, offset: const Offset(0, 2))],
boxShadow: [
BoxShadow(
color: cs.shadow.withValues(alpha: 0.05),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Column(
children: [
@@ -686,29 +837,48 @@ class _QuestionEditorState extends State<_QuestionEditor> {
borderRadius: BorderRadius.circular(8),
),
child: Center(
child: Text('${widget.index + 1}',
style: TextStyle(fontSize: 13, fontWeight: FontWeight.bold, color: cs.primary)),
child: Text(
'${widget.index + 1}',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.bold,
color: cs.primary,
),
),
),
),
const SizedBox(width: 10),
Expanded(
child: Text(
widget.question.question.isEmpty ? 'Pergunta ${widget.index + 1}' : widget.question.question,
widget.question.question.isEmpty
? 'Pergunta ${widget.index + 1}'
: widget.question.question,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: cs.onSurface),
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: cs.onSurface,
),
),
),
if (widget.onDelete != null)
IconButton(
icon: Icon(Icons.delete_outline, color: cs.error, size: 18),
icon: Icon(
Icons.delete_outline,
color: cs.error,
size: 18,
),
padding: EdgeInsets.zero,
constraints: const BoxConstraints(),
onPressed: widget.onDelete,
tooltip: 'Remover',
),
const SizedBox(width: 4),
Icon(_expanded ? Icons.expand_less : Icons.expand_more, color: cs.onSurfaceVariant),
Icon(
_expanded ? Icons.expand_less : Icons.expand_more,
color: cs.onSurfaceVariant,
),
],
),
),
@@ -746,31 +916,59 @@ class _QuestionEditorState extends State<_QuestionEditor> {
margin: const EdgeInsets.only(right: 8),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: isCorrect ? cs.primary : cs.surfaceContainerHighest,
border: Border.all(color: isCorrect ? cs.primary : cs.outline.withValues(alpha: 0.3)),
color: isCorrect
? cs.primary
: cs.surfaceContainerHighest,
border: Border.all(
color: isCorrect
? cs.primary
: cs.outline.withValues(alpha: 0.3),
),
),
child: isCorrect
? Icon(Icons.check, size: 16, color: cs.onPrimary)
? Icon(
Icons.check,
size: 16,
color: cs.onPrimary,
)
: Center(
child: Text(String.fromCharCode(65 + i),
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant)),
child: Text(
String.fromCharCode(65 + i),
style: TextStyle(
fontSize: 12,
color: cs.onSurfaceVariant,
),
),
),
),
),
Expanded(child: _textField(_optCtrl[i], cs, hint: 'Opção ${String.fromCharCode(65 + i)}')),
Expanded(
child: _textField(
_optCtrl[i],
cs,
hint: 'Opção ${String.fromCharCode(65 + i)}',
),
),
],
),
);
}),
Text('Toca no círculo para marcar a correcta',
style: TextStyle(fontSize: 11, color: cs.onSurfaceVariant)),
Text(
'Toca no círculo para marcar a correcta',
style: TextStyle(fontSize: 11, color: cs.onSurfaceVariant),
),
const SizedBox(height: 14),
// Explicação
_label('Explicação (quando erra)', cs),
const SizedBox(height: 6),
_textField(_expCtrl, cs, maxLines: 3, hint: 'Explica porque esta é a resposta correcta...'),
_textField(
_expCtrl,
cs,
maxLines: 3,
hint: 'Explica porque esta é a resposta correcta...',
),
const SizedBox(height: 12),
Align(
@@ -790,28 +988,47 @@ class _QuestionEditorState extends State<_QuestionEditor> {
);
}
Widget _label(String text, ColorScheme cs) => Text(text,
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: cs.onSurfaceVariant));
Widget _label(String text, ColorScheme cs) => Text(
text,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: cs.onSurfaceVariant,
),
);
Widget _textField(TextEditingController ctrl, ColorScheme cs, {int maxLines = 1, String? hint}) =>
TextField(
controller: ctrl,
maxLines: maxLines,
style: TextStyle(fontSize: 14, color: cs.onSurface),
decoration: InputDecoration(
hintText: hint,
hintStyle: TextStyle(color: cs.onSurfaceVariant.withValues(alpha: 0.5), fontSize: 13),
filled: true,
fillColor: cs.surfaceContainerHighest.withValues(alpha: 0.5),
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide.none),
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide.none),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: cs.primary, width: 1.5),
),
),
);
Widget _textField(
TextEditingController ctrl,
ColorScheme cs, {
int maxLines = 1,
String? hint,
}) => TextField(
controller: ctrl,
maxLines: maxLines,
style: TextStyle(fontSize: 14, color: cs.onSurface),
decoration: InputDecoration(
hintText: hint,
hintStyle: TextStyle(
color: cs.onSurfaceVariant.withValues(alpha: 0.5),
fontSize: 13,
),
filled: true,
fillColor: cs.surfaceContainerHighest.withValues(alpha: 0.5),
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide.none,
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide.none,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: cs.primary, width: 1.5),
),
),
);
}
// ─── Popup de resultados por aluno ────────────────────────────────────────────
@@ -851,9 +1068,13 @@ class _StudentResultsDialogState extends State<_StudentResultsDialog> {
String studentName = data['studentName'] as String? ?? 'Aluno';
if (studentId != null && studentName == 'Aluno') {
try {
final userDoc = await FirebaseFirestore.instance.collection('users').doc(studentId).get();
final userDoc = await FirebaseFirestore.instance
.collection('users')
.doc(studentId)
.get();
if (userDoc.exists) {
studentName = userDoc.data()?['displayName'] as String? ??
studentName =
userDoc.data()?['displayName'] as String? ??
userDoc.data()?['name'] as String? ??
studentName;
}
@@ -861,7 +1082,11 @@ class _StudentResultsDialogState extends State<_StudentResultsDialog> {
}
results.add({...data, 'studentName': studentName});
}
if (mounted) setState(() { _results = results; _loading = false; });
if (mounted)
setState(() {
_results = results;
_loading = false;
});
} catch (e) {
Logger.error('Error loading quiz submissions: $e');
if (mounted) setState(() => _loading = false);
@@ -884,7 +1109,9 @@ class _StudentResultsDialogState extends State<_StudentResultsDialog> {
padding: const EdgeInsets.fromLTRB(20, 20, 12, 16),
decoration: BoxDecoration(
color: cs.primary.withValues(alpha: 0.08),
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(20),
),
),
child: Row(
children: [
@@ -895,7 +1122,11 @@ class _StudentResultsDialogState extends State<_StudentResultsDialog> {
widget.quizTitle,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15, color: cs.onSurface),
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: cs.onSurface,
),
),
),
IconButton(
@@ -909,69 +1140,101 @@ class _StudentResultsDialogState extends State<_StudentResultsDialog> {
// Body
Flexible(
child: _loading
? const Center(child: Padding(padding: EdgeInsets.all(32), child: CircularProgressIndicator()))
? const Center(
child: Padding(
padding: EdgeInsets.all(32),
child: CircularProgressIndicator(),
),
)
: _results.isEmpty
? Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Text(
'Nenhum aluno submeteu este quiz ainda.',
textAlign: TextAlign.center,
style: TextStyle(color: cs.onSurfaceVariant),
),
),
)
: ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
shrinkWrap: true,
itemCount: _results.length,
separatorBuilder: (_, __) => const SizedBox(height: 8),
itemBuilder: (_, i) {
final r = _results[i];
final score = r['score'] as int? ?? 0;
final total = r['total'] as int? ?? 1;
final pct = (score / total * 100).round();
final Color c = pct >= 80
? const Color(0xFF10B981)
: pct >= 50
? const Color(0xFFF59E0B)
: const Color(0xFFEF4444);
final ts = r['submittedAt'];
String dateStr = '';
if (ts is Timestamp) {
final dt = ts.toDate();
dateStr = '${dt.day.toString().padLeft(2, '0')}/${dt.month.toString().padLeft(2, '0')}/${dt.year}';
}
return Container(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
decoration: BoxDecoration(
color: c.withValues(alpha: 0.07),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: c.withValues(alpha: 0.2)),
),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(r['studentName'] as String,
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 14, color: cs.onSurface)),
if (dateStr.isNotEmpty)
Text(dateStr,
style: TextStyle(fontSize: 11, color: cs.onSurfaceVariant)),
],
),
),
Text('$score/$total',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16, color: c)),
const SizedBox(width: 6),
Text('($pct%)', style: TextStyle(fontSize: 12, color: c)),
],
),
);
},
? Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Text(
'Nenhum aluno submeteu este quiz ainda.',
textAlign: TextAlign.center,
style: TextStyle(color: cs.onSurfaceVariant),
),
),
)
: ListView.separated(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
shrinkWrap: true,
itemCount: _results.length,
separatorBuilder: (_, __) => const SizedBox(height: 8),
itemBuilder: (_, i) {
final r = _results[i];
final score = r['score'] as int? ?? 0;
final total = r['total'] as int? ?? 1;
final pct = (score / total * 100).round();
final Color c = pct >= 80
? const Color(0xFF10B981)
: pct >= 50
? const Color(0xFFF59E0B)
: const Color(0xFFEF4444);
final ts = r['submittedAt'];
String dateStr = '';
if (ts is Timestamp) {
final dt = ts.toDate();
dateStr =
'${dt.day.toString().padLeft(2, '0')}/${dt.month.toString().padLeft(2, '0')}/${dt.year}';
}
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 14,
vertical: 10,
),
decoration: BoxDecoration(
color: c.withValues(alpha: 0.07),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: c.withValues(alpha: 0.2)),
),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
r['studentName'] as String,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 14,
color: cs.onSurface,
),
),
if (dateStr.isNotEmpty)
Text(
dateStr,
style: TextStyle(
fontSize: 11,
color: cs.onSurfaceVariant,
),
),
],
),
),
Text(
'$score/$total',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: c,
),
),
const SizedBox(width: 6),
Text(
'($pct%)',
style: TextStyle(fontSize: 12, color: c),
),
],
),
);
},
),
),
],
),