Alteração do acesso às settings, mudança visual na interface de entrar numa turma

This commit is contained in:
2026-05-17 14:34:19 +01:00
parent 51ea446ae9
commit 5649f7d96a
7 changed files with 924 additions and 344 deletions

View File

@@ -45,13 +45,20 @@ class _QuizListPageState extends State<QuizListPage>
Future<void> _loadMaterials() async {
final mats = await MaterialsRAGService.getAvailableMaterialsForStudent();
if (mounted) setState(() { _materials = mats; _loadingMaterials = false; });
if (mounted)
setState(() {
_materials = mats;
_loadingMaterials = false;
});
}
Future<void> _loadTeacherQuizzes() async {
try {
final uid = FirebaseAuth.instance.currentUser?.uid;
if (uid == null) { if (mounted) setState(() => _loadingTeacherQuizzes = false); return; }
if (uid == null) {
if (mounted) setState(() => _loadingTeacherQuizzes = false);
return;
}
// Obter teacherIds dos professores do aluno
final enrollSnap = await FirebaseFirestore.instance
@@ -70,11 +77,19 @@ class _QuizListPageState extends State<QuizListPage>
final classIdList = classIds.toList();
final batches = <Future<QuerySnapshot>>[];
for (int i = 0; i < classIdList.length; i += 10) {
batches.add(FirebaseFirestore.instance
.collection('teacherQuizzes')
.where('classIds', arrayContainsAny: classIdList.sublist(i, (i + 10).clamp(0, classIdList.length)))
.orderBy('createdAt', descending: true)
.get());
batches.add(
FirebaseFirestore.instance
.collection('teacherQuizzes')
.where(
'classIds',
arrayContainsAny: classIdList.sublist(
i,
(i + 10).clamp(0, classIdList.length),
),
)
.orderBy('createdAt', descending: true)
.get(),
);
}
final results = await Future.wait(batches);
// deduplicar por id (pode aparecer em múltiplos batches)
@@ -84,7 +99,11 @@ class _QuizListPageState extends State<QuizListPage>
.where((d) => seen.add(d.id))
.map((d) => {'id': d.id, ...d.data() as Map<String, dynamic>})
.toList();
if (mounted) setState(() { _teacherQuizzes = quizzes; _loadingTeacherQuizzes = false; });
if (mounted)
setState(() {
_teacherQuizzes = quizzes;
_loadingTeacherQuizzes = false;
});
} catch (e) {
Logger.error('Error loading teacher quizzes: $e');
if (mounted) setState(() => _loadingTeacherQuizzes = false);
@@ -94,7 +113,10 @@ class _QuizListPageState extends State<QuizListPage>
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('quizHistory')
.doc(uid)
@@ -103,7 +125,11 @@ class _QuizListPageState extends State<QuizListPage>
.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('Error loading quiz history: $e');
if (mounted) setState(() => _loadingHistory = false);
@@ -141,7 +167,8 @@ class _QuizListPageState extends State<QuizListPage>
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;
}
@@ -153,11 +180,11 @@ class _QuizListPageState extends State<QuizListPage>
.doc(uid)
.collection('quizzes')
.add({
'materialId': matId,
'materialName': matName,
'quizJson': raw,
'createdAt': FieldValue.serverTimestamp(),
});
'materialId': matId,
'materialName': matName,
'quizJson': raw,
'createdAt': FieldValue.serverTimestamp(),
});
await _loadHistory();
}
@@ -171,7 +198,8 @@ class _QuizListPageState extends State<QuizListPage>
}
Widget _buildTeacherQuizzesTab(ColorScheme cs) {
if (_loadingTeacherQuizzes) return const Center(child: CircularProgressIndicator());
if (_loadingTeacherQuizzes)
return const Center(child: CircularProgressIndicator());
if (_teacherQuizzes.isEmpty) {
return Center(
child: Padding(
@@ -179,15 +207,26 @@ class _QuizListPageState extends State<QuizListPage>
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.school_outlined, size: 64, color: cs.onSurfaceVariant.withValues(alpha: 0.4)),
Icon(
Icons.school_outlined,
size: 64,
color: cs.onSurfaceVariant.withValues(alpha: 0.4),
),
const SizedBox(height: 16),
Text('Sem quizzes do professor disponíveis.',
textAlign: TextAlign.center,
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 16)),
Text(
'Sem quizzes do professor disponíveis.',
textAlign: TextAlign.center,
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 16),
),
const SizedBox(height: 8),
Text('O teu professor ainda não publicou quizzes.',
textAlign: TextAlign.center,
style: TextStyle(color: cs.onSurfaceVariant.withValues(alpha: 0.7), fontSize: 13)),
Text(
'O teu professor ainda não publicou quizzes.',
textAlign: TextAlign.center,
style: TextStyle(
color: cs.onSurfaceVariant.withValues(alpha: 0.7),
fontSize: 13,
),
),
],
),
),
@@ -206,17 +245,27 @@ class _QuizListPageState extends State<QuizListPage>
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}';
dateStr =
'${dt.day.toString().padLeft(2, '0')}/${dt.month.toString().padLeft(2, '0')}/${dt.year}';
}
return Container(
decoration: BoxDecoration(
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,
@@ -226,14 +275,27 @@ class _QuizListPageState extends State<QuizListPage>
),
child: Icon(Icons.school, color: cs.secondary, 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('Publicado em $dateStr', style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant))
? Text(
'Publicado em $dateStr',
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant),
)
: null,
trailing: Icon(Icons.play_circle_outline, color: cs.secondary, size: 28),
trailing: Icon(
Icons.play_circle_outline,
color: cs.secondary,
size: 28,
),
onTap: () => _showTeacherQuiz(quiz),
),
);
@@ -275,16 +337,24 @@ class _QuizListPageState extends State<QuizListPage>
final jsonStr = raw.substring(start, end + 1);
final decoded = _jsonDecode(jsonStr);
if (decoded is! List) return [];
return decoded.map<_QuizQuestion?>((e) {
if (e is! Map) return null;
final q = e['q'] as String?;
final opts = (e['opts'] as List?)?.cast<String>();
final ans = e['ans'] as int?;
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);
}).whereType<_QuizQuestion>().toList();
return decoded
.map<_QuizQuestion?>((e) {
if (e is! Map) return null;
final q = e['q'] as String?;
final opts = (e['opts'] as List?)?.cast<String>();
final ans = e['ans'] as int?;
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,
);
})
.whereType<_QuizQuestion>()
.toList();
} catch (e) {
Logger.error('Quiz JSON parse error: $e');
return [];
@@ -373,7 +443,11 @@ class _QuizListPageState extends State<QuizListPage>
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.folder_open, size: 64, color: cs.onSurfaceVariant.withOpacity(0.4)),
Icon(
Icons.folder_open,
size: 64,
color: cs.onSurfaceVariant.withOpacity(0.4),
),
const SizedBox(height: 16),
Text(
'Nenhum material disponível.',
@@ -384,7 +458,10 @@ class _QuizListPageState extends State<QuizListPage>
Text(
'Inscreve-te numa turma para aceder aos PDFs do professor.',
textAlign: TextAlign.center,
style: TextStyle(color: cs.onSurfaceVariant.withOpacity(0.7), fontSize: 13),
style: TextStyle(
color: cs.onSurfaceVariant.withOpacity(0.7),
fontSize: 13,
),
),
],
),
@@ -413,7 +490,10 @@ class _QuizListPageState extends State<QuizListPage>
],
),
child: ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
leading: Container(
width: 44,
height: 44,
@@ -465,7 +545,11 @@ class _QuizListPageState extends State<QuizListPage>
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.history, size: 64, color: cs.onSurfaceVariant.withOpacity(0.4)),
Icon(
Icons.history,
size: 64,
color: cs.onSurfaceVariant.withOpacity(0.4),
),
const SizedBox(height: 16),
Text(
'Ainda não geraste nenhum quiz.',
@@ -490,7 +574,8 @@ class _QuizListPageState extends State<QuizListPage>
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} ${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}';
dateStr =
'${dt.day.toString().padLeft(2, '0')}/${dt.month.toString().padLeft(2, '0')}/${dt.year} ${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}';
}
return Container(
decoration: BoxDecoration(
@@ -506,7 +591,10 @@ class _QuizListPageState extends State<QuizListPage>
],
),
child: ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
leading: Container(
width: 44,
height: 44,
@@ -527,10 +615,16 @@ class _QuizListPageState extends State<QuizListPage>
),
),
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.chevron_right, color: cs.onSurfaceVariant),
onTap: () => _showQuizFromHistory(matName, item['quizJson'] as String? ?? item['quizText'] as String? ?? ''),
onTap: () => _showQuizFromHistory(
matName,
item['quizJson'] as String? ?? item['quizText'] as String? ?? '',
),
),
);
},
@@ -584,19 +678,24 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
void _next() {
if (_current < widget.questions.length - 1) {
setState(() { _current++; });
setState(() {
_current++;
});
} else {
setState(() => _submitted = true);
}
}
void _prev() {
if (_current > 0) setState(() { _current--; });
if (_current > 0)
setState(() {
_current--;
});
}
int get _score => List.generate(widget.questions.length, (i) {
return _chosen[i] == widget.questions[i].correctIndex ? 1 : 0;
}).fold(0, (a, b) => a + b);
return _chosen[i] == widget.questions[i].correctIndex ? 1 : 0;
}).fold(0, (a, b) => a + b);
@override
Widget build(BuildContext context) {
@@ -627,44 +726,48 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
}
Widget _buildHandle(ColorScheme cs) => Container(
margin: const EdgeInsets.only(top: 12, bottom: 4),
width: 40,
height: 4,
decoration: BoxDecoration(
color: cs.outline.withOpacity(0.3),
borderRadius: BorderRadius.circular(2),
),
);
margin: const EdgeInsets.only(top: 12, bottom: 4),
width: 40,
height: 4,
decoration: BoxDecoration(
color: cs.outline.withOpacity(0.3),
borderRadius: BorderRadius.circular(2),
),
);
Widget _buildHeader(ColorScheme cs) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold, color: cs.onSurface),
),
if (!_submitted)
Text(
'Pergunta ${_current + 1} de ${widget.questions.length}',
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant),
),
],
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: cs.onSurface,
),
),
),
IconButton(
icon: Icon(Icons.close, color: cs.onSurfaceVariant),
onPressed: () => Navigator.of(context).pop(),
),
],
if (!_submitted)
Text(
'Pergunta ${_current + 1} de ${widget.questions.length}',
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant),
),
],
),
),
);
IconButton(
icon: Icon(Icons.close, color: cs.onSurfaceVariant),
onPressed: () => Navigator.of(context).pop(),
),
],
),
);
Widget _buildQuestion(ColorScheme cs, ScrollController sc) {
final q = widget.questions[_current];
@@ -687,7 +790,12 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
// Pergunta
Text(
q.question,
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: cs.onSurface, height: 1.4),
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: cs.onSurface,
height: 1.4,
),
),
const SizedBox(height: 20),
// Opções
@@ -700,12 +808,19 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
onTap: () => _selectOption(i),
child: AnimatedContainer(
duration: const Duration(milliseconds: 150),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 14,
),
decoration: BoxDecoration(
color: isSelected ? cs.primary.withOpacity(0.12) : cs.surfaceVariant.withOpacity(0.4),
color: isSelected
? cs.primary.withOpacity(0.12)
: cs.surfaceVariant.withOpacity(0.4),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: isSelected ? cs.primary : cs.outline.withOpacity(0.2),
color: isSelected
? cs.primary
: cs.outline.withOpacity(0.2),
width: isSelected ? 2 : 1,
),
),
@@ -717,11 +832,14 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
style: TextStyle(
fontSize: 14,
color: isSelected ? cs.primary : cs.onSurface,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
fontWeight: isSelected
? FontWeight.w600
: FontWeight.normal,
),
),
),
if (isSelected) Icon(Icons.check_circle, color: cs.primary, size: 20),
if (isSelected)
Icon(Icons.check_circle, color: cs.primary, size: 20),
],
),
),
@@ -738,7 +856,9 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
onPressed: _prev,
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text('Anterior'),
),
@@ -751,9 +871,15 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
backgroundColor: cs.primary,
foregroundColor: cs.onPrimary,
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
_current < widget.questions.length - 1
? 'Próxima'
: 'Submeter',
),
child: Text(_current < widget.questions.length - 1 ? 'Próxima' : 'Submeter'),
),
),
],
@@ -769,8 +895,8 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
final Color scoreColor = pct >= 80
? const Color(0xFF10B981)
: pct >= 50
? const Color(0xFFF59E0B)
: const Color(0xFFEF4444);
? const Color(0xFFF59E0B)
: const Color(0xFFEF4444);
return ListView(
controller: sc,
@@ -788,7 +914,11 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
children: [
Text(
'$score / $total',
style: TextStyle(fontSize: 40, fontWeight: FontWeight.bold, color: scoreColor),
style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
color: scoreColor,
),
),
const SizedBox(height: 4),
Text(
@@ -801,7 +931,11 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
const SizedBox(height: 24),
Text(
'Revisão',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: cs.onSurface),
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: cs.onSurface,
),
),
const SizedBox(height: 12),
// Revisão pergunta a pergunta
@@ -809,7 +943,9 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
final q = widget.questions[i];
final chosen = _chosen[i];
final isCorrect = chosen == q.correctIndex;
final revColor = isCorrect ? const Color(0xFF10B981) : const Color(0xFFEF4444);
final revColor = isCorrect
? const Color(0xFF10B981)
: const Color(0xFFEF4444);
return Container(
margin: const EdgeInsets.only(bottom: 16),
padding: const EdgeInsets.all(16),
@@ -823,27 +959,49 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
children: [
Row(
children: [
Icon(isCorrect ? Icons.check_circle : Icons.cancel, color: revColor, size: 18),
Icon(
isCorrect ? Icons.check_circle : Icons.cancel,
color: revColor,
size: 18,
),
const SizedBox(width: 8),
Expanded(
child: Text(
'Pergunta ${i + 1}',
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: revColor),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: revColor,
),
),
),
],
),
const SizedBox(height: 8),
Text(q.question, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: cs.onSurface)),
Text(
q.question,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: cs.onSurface,
),
),
const SizedBox(height: 8),
if (chosen >= 0 && chosen < q.options.length && !isCorrect)
Text(
'A tua resposta: ${q.options[chosen]}',
style: const TextStyle(fontSize: 13, color: Color(0xFFEF4444)),
style: const TextStyle(
fontSize: 13,
color: Color(0xFFEF4444),
),
),
Text(
'Resposta correcta: ${q.options[q.correctIndex]}',
style: TextStyle(fontSize: 13, color: isCorrect ? const Color(0xFF10B981) : cs.onSurface, fontWeight: FontWeight.w500),
style: TextStyle(
fontSize: 13,
color: isCorrect ? const Color(0xFF10B981) : cs.onSurface,
fontWeight: FontWeight.w500,
),
),
if (q.explanation.isNotEmpty) ...[
const SizedBox(height: 8),
@@ -856,12 +1014,20 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(Icons.info_outline, size: 14, color: cs.onSurfaceVariant),
Icon(
Icons.info_outline,
size: 14,
color: cs.onSurfaceVariant,
),
const SizedBox(width: 6),
Expanded(
child: Text(
q.explanation,
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant, height: 1.4),
style: TextStyle(
fontSize: 12,
color: cs.onSurfaceVariant,
height: 1.4,
),
),
),
],
@@ -879,7 +1045,9 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
backgroundColor: cs.primary,
foregroundColor: cs.onPrimary,
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text('Fechar'),
),
@@ -901,10 +1069,12 @@ class _TeacherQuizInteractiveSheet extends StatefulWidget {
});
@override
State<_TeacherQuizInteractiveSheet> createState() => _TeacherQuizInteractiveSheetState();
State<_TeacherQuizInteractiveSheet> createState() =>
_TeacherQuizInteractiveSheetState();
}
class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveSheet> {
class _TeacherQuizInteractiveSheetState
extends State<_TeacherQuizInteractiveSheet> {
int _current = 0;
late List<int> _chosen;
bool _submitted = false;
@@ -933,11 +1103,16 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
if (_current > 0) setState(() => _current--);
}
int get _score => List.generate(widget.questions.length,
(i) => _chosen[i] == widget.questions[i].correctIndex ? 1 : 0).fold(0, (a, b) => a + b);
int get _score => List.generate(
widget.questions.length,
(i) => _chosen[i] == widget.questions[i].correctIndex ? 1 : 0,
).fold(0, (a, b) => a + b);
Future<void> _submit() async {
setState(() { _submitted = true; _saving = true; });
setState(() {
_submitted = true;
_saving = true;
});
try {
final user = FirebaseAuth.instance.currentUser;
if (user != null) {
@@ -947,12 +1122,13 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
.collection('submissions')
.doc(user.uid) // 1 submissão por aluno (sobrescreve)
.set({
'studentId': user.uid,
'studentName': user.displayName ?? user.email?.split('@')[0] ?? 'Aluno',
'score': _score,
'total': widget.questions.length,
'submittedAt': FieldValue.serverTimestamp(),
});
'studentId': user.uid,
'studentName':
user.displayName ?? user.email?.split('@')[0] ?? 'Aluno',
'score': _score,
'total': widget.questions.length,
'submittedAt': FieldValue.serverTimestamp(),
});
}
} catch (e) {
Logger.error('Error submitting teacher quiz result: $e');
@@ -978,7 +1154,8 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
// Handle
Container(
margin: const EdgeInsets.only(top: 12, bottom: 4),
width: 40, height: 4,
width: 40,
height: 4,
decoration: BoxDecoration(
color: cs.outline.withValues(alpha: 0.3),
borderRadius: BorderRadius.circular(2),
@@ -993,18 +1170,33 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold, color: cs.onSurface)),
Text(
widget.title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: cs.onSurface,
),
),
if (!_submitted)
Text('Pergunta ${_current + 1} de ${widget.questions.length}',
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant)),
Text(
'Pergunta ${_current + 1} de ${widget.questions.length}',
style: TextStyle(
fontSize: 12,
color: cs.onSurfaceVariant,
),
),
],
),
),
if (_saving)
const SizedBox(width: 24, height: 24, child: CircularProgressIndicator(strokeWidth: 2))
const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(strokeWidth: 2),
)
else
IconButton(
icon: Icon(Icons.close, color: cs.onSurfaceVariant),
@@ -1042,8 +1234,15 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
),
),
const SizedBox(height: 20),
Text(q.question,
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: cs.onSurface, height: 1.4)),
Text(
q.question,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: cs.onSurface,
height: 1.4,
),
),
const SizedBox(height: 20),
...List.generate(q.options.length, (i) {
final isSelected = chosen == i;
@@ -1054,26 +1253,38 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
onTap: () => _selectOption(i),
child: AnimatedContainer(
duration: const Duration(milliseconds: 150),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 14,
),
decoration: BoxDecoration(
color: isSelected ? cs.secondary.withValues(alpha: 0.12) : cs.surfaceContainerHighest.withValues(alpha: 0.4),
color: isSelected
? cs.secondary.withValues(alpha: 0.12)
: cs.surfaceContainerHighest.withValues(alpha: 0.4),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: isSelected ? cs.secondary : cs.outline.withValues(alpha: 0.2),
color: isSelected
? cs.secondary
: cs.outline.withValues(alpha: 0.2),
width: isSelected ? 2 : 1,
),
),
child: Row(
children: [
Expanded(
child: Text(q.options[i],
style: TextStyle(
fontSize: 14,
color: isSelected ? cs.secondary : cs.onSurface,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
)),
child: Text(
q.options[i],
style: TextStyle(
fontSize: 14,
color: isSelected ? cs.secondary : cs.onSurface,
fontWeight: isSelected
? FontWeight.w600
: FontWeight.normal,
),
),
),
if (isSelected) Icon(Icons.check_circle, color: cs.secondary, size: 20),
if (isSelected)
Icon(Icons.check_circle, color: cs.secondary, size: 20),
],
),
),
@@ -1089,7 +1300,9 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
onPressed: _prev,
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text('Anterior'),
),
@@ -1103,9 +1316,15 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
backgroundColor: cs.secondary,
foregroundColor: cs.onSecondary,
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
_current < widget.questions.length - 1
? 'Próxima'
: 'Submeter',
),
child: Text(_current < widget.questions.length - 1 ? 'Próxima' : 'Submeter'),
),
),
],
@@ -1121,8 +1340,8 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
final Color scoreColor = pct >= 80
? const Color(0xFF10B981)
: pct >= 50
? const Color(0xFFF59E0B)
: const Color(0xFFEF4444);
? const Color(0xFFF59E0B)
: const Color(0xFFEF4444);
return ListView(
controller: sc,
padding: const EdgeInsets.fromLTRB(20, 20, 20, 32),
@@ -1136,25 +1355,44 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
),
child: Column(
children: [
Text('$score / $total',
style: TextStyle(fontSize: 40, fontWeight: FontWeight.bold, color: scoreColor)),
Text(
'$score / $total',
style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
color: scoreColor,
),
),
const SizedBox(height: 4),
Text('$pct% de respostas correctas',
style: TextStyle(fontSize: 14, color: scoreColor)),
Text(
'$pct% de respostas correctas',
style: TextStyle(fontSize: 14, color: scoreColor),
),
const SizedBox(height: 4),
Text('Resultado enviado ao professor ✓',
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant)),
Text(
'Resultado enviado ao professor ✓',
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant),
),
],
),
),
const SizedBox(height: 24),
Text('Revisão', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: cs.onSurface)),
Text(
'Revisão',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: cs.onSurface,
),
),
const SizedBox(height: 12),
...List.generate(total, (i) {
final q = widget.questions[i];
final chosen = _chosen[i];
final isCorrect = chosen == q.correctIndex;
final revColor = isCorrect ? const Color(0xFF10B981) : const Color(0xFFEF4444);
final revColor = isCorrect
? const Color(0xFF10B981)
: const Color(0xFFEF4444);
return Container(
margin: const EdgeInsets.only(bottom: 16),
padding: const EdgeInsets.all(16),
@@ -1168,26 +1406,50 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
children: [
Row(
children: [
Icon(isCorrect ? Icons.check_circle : Icons.cancel, color: revColor, size: 18),
Icon(
isCorrect ? Icons.check_circle : Icons.cancel,
color: revColor,
size: 18,
),
const SizedBox(width: 8),
Expanded(
child: Text('Pergunta ${i + 1}',
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: revColor)),
child: Text(
'Pergunta ${i + 1}',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: revColor,
),
),
),
],
),
const SizedBox(height: 8),
Text(q.question,
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: cs.onSurface)),
Text(
q.question,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: cs.onSurface,
),
),
const SizedBox(height: 8),
if (chosen >= 0 && chosen < q.options.length && !isCorrect)
Text('A tua resposta: ${q.options[chosen]}',
style: const TextStyle(fontSize: 13, color: Color(0xFFEF4444))),
Text('Resposta correcta: ${q.options[q.correctIndex]}',
style: TextStyle(
fontSize: 13,
color: isCorrect ? const Color(0xFF10B981) : cs.onSurface,
fontWeight: FontWeight.w500)),
Text(
'A tua resposta: ${q.options[chosen]}',
style: const TextStyle(
fontSize: 13,
color: Color(0xFFEF4444),
),
),
Text(
'Resposta correcta: ${q.options[q.correctIndex]}',
style: TextStyle(
fontSize: 13,
color: isCorrect ? const Color(0xFF10B981) : cs.onSurface,
fontWeight: FontWeight.w500,
),
),
if (q.explanation.isNotEmpty) ...[
const SizedBox(height: 8),
Container(
@@ -1199,11 +1461,21 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(Icons.info_outline, size: 14, color: cs.onSurfaceVariant),
Icon(
Icons.info_outline,
size: 14,
color: cs.onSurfaceVariant,
),
const SizedBox(width: 6),
Expanded(
child: Text(q.explanation,
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant, height: 1.4)),
child: Text(
q.explanation,
style: TextStyle(
fontSize: 12,
color: cs.onSurfaceVariant,
height: 1.4,
),
),
),
],
),
@@ -1219,7 +1491,9 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
backgroundColor: cs.secondary,
foregroundColor: cs.onSecondary,
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text('Fechar'),
),