Muitas coisas e já me esqueci delas todas, cenas principalmente no dashboard do aluno bug fixes e etc
This commit is contained in:
@@ -70,14 +70,16 @@ class _QuizListPageState extends State<QuizListPage>
|
||||
.collection('enrollments')
|
||||
.where('studentId', isEqualTo: uid)
|
||||
.get();
|
||||
Logger.info('Enrollments found for student $uid: ${enrollSnap.docs.length}');
|
||||
|
||||
Logger.info(
|
||||
'Enrollments found for student $uid: ${enrollSnap.docs.length}',
|
||||
);
|
||||
|
||||
final classIds = enrollSnap.docs
|
||||
.map((d) => d.data()['classId'] as String?)
|
||||
.whereType<String>()
|
||||
.toSet();
|
||||
Logger.info('ClassIds from enrollments: $classIds');
|
||||
|
||||
|
||||
if (classIds.isEmpty) {
|
||||
Logger.info('No classIds found for student, returning empty');
|
||||
if (mounted) setState(() => _loadingTeacherQuizzes = false);
|
||||
@@ -85,7 +87,10 @@ class _QuizListPageState extends State<QuizListPage>
|
||||
}
|
||||
// Obter também os teacherIds (fallback para quizzes sem classIds)
|
||||
final classSnaps = await Future.wait(
|
||||
classIds.map((id) => FirebaseFirestore.instance.collection('classes').doc(id).get()),
|
||||
classIds.map(
|
||||
(id) =>
|
||||
FirebaseFirestore.instance.collection('classes').doc(id).get(),
|
||||
),
|
||||
);
|
||||
final teacherIds = classSnaps
|
||||
.where((d) => d.exists)
|
||||
@@ -98,7 +103,7 @@ class _QuizListPageState extends State<QuizListPage>
|
||||
// Simplificar: tentar query básica primeiro
|
||||
final classIdList = classIds.toList();
|
||||
final batches = <Future<QuerySnapshot>>[];
|
||||
|
||||
|
||||
// Query 1: por teacherId (mais simples e compatível)
|
||||
if (teacherIds.isNotEmpty) {
|
||||
Logger.info('Executing simple teacherIds query with: $teacherIds');
|
||||
@@ -111,7 +116,7 @@ class _QuizListPageState extends State<QuizListPage>
|
||||
batches.add(query.get());
|
||||
Logger.info('Added teacherIds batch query: $batch');
|
||||
}
|
||||
|
||||
|
||||
// Query 2: por classIds (se a primeira não retornar resultados)
|
||||
if (classIdList.isNotEmpty) {
|
||||
Logger.info('Executing classIds query with: $classIdList');
|
||||
@@ -153,18 +158,19 @@ class _QuizListPageState extends State<QuizListPage>
|
||||
final allQuizzes = allSnap.docs
|
||||
.map((d) => {'id': d.id, ...d.data() as Map<String, dynamic>})
|
||||
.toList();
|
||||
|
||||
|
||||
// Filtrar manualmente para testar
|
||||
final filteredQuizzes = allQuizzes.where((quiz) {
|
||||
final quizTeacherId = quiz['teacherId'] as String?;
|
||||
final quizClassIds = (quiz['classIds'] as List?)?.cast<String>() ?? [];
|
||||
return teacherIds.contains(quizTeacherId) ||
|
||||
quizClassIds.any((cid) => classIds.contains(cid));
|
||||
final quizClassIds =
|
||||
(quiz['classIds'] as List?)?.cast<String>() ?? [];
|
||||
return teacherIds.contains(quizTeacherId) ||
|
||||
quizClassIds.any((cid) => classIds.contains(cid));
|
||||
}).toList();
|
||||
|
||||
|
||||
Logger.info('Manual filtered quizzes: ${filteredQuizzes.length}');
|
||||
Logger.info('=== END ALL QUIZZES NO FILTER ===');
|
||||
|
||||
|
||||
// Usar este resultado temporariamente para debug
|
||||
if (filteredQuizzes.isNotEmpty) {
|
||||
Logger.info('Using manually filtered quizzes for UI');
|
||||
@@ -183,7 +189,7 @@ class _QuizListPageState extends State<QuizListPage>
|
||||
// Executar queries e processar resultados
|
||||
final results = await Future.wait(batches);
|
||||
Logger.info('Query batches completed: ${results.length} results');
|
||||
|
||||
|
||||
// deduplicar por id (pode aparecer em múltiplos batches)
|
||||
final seen = <String>{};
|
||||
final quizzes = results
|
||||
@@ -191,13 +197,17 @@ class _QuizListPageState extends State<QuizListPage>
|
||||
.where((d) => seen.add(d.id))
|
||||
.map((d) => {'id': d.id, ...d.data() as Map<String, dynamic>})
|
||||
.toList();
|
||||
|
||||
|
||||
Logger.info('Final quizzes after deduplication: ${quizzes.length}');
|
||||
for (final quiz in quizzes.take(3)) {
|
||||
Logger.info('Quiz sample: ${quiz['materialName']} - classIds: ${quiz['classIds']} - teacherId: ${quiz['teacherId']}');
|
||||
Logger.info(
|
||||
'Quiz sample: ${quiz['materialName']} - classIds: ${quiz['classIds']} - teacherId: ${quiz['teacherId']}',
|
||||
);
|
||||
}
|
||||
if (mounted) {
|
||||
Logger.info('Updating UI state: _teacherQuizzes.length = ${quizzes.length}');
|
||||
Logger.info(
|
||||
'Updating UI state: _teacherQuizzes.length = ${quizzes.length}',
|
||||
);
|
||||
setState(() {
|
||||
_teacherQuizzes = quizzes;
|
||||
_loadingTeacherQuizzes = false;
|
||||
@@ -558,7 +568,7 @@ class _QuizListPageState extends State<QuizListPage>
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Inscreve-te numa turma para aceder aos PDFs do professor.',
|
||||
'Inscreve-te numa disciplina para aceder aos PDFs do professor.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: cs.onSurfaceVariant.withOpacity(0.7),
|
||||
@@ -1233,7 +1243,7 @@ class _TeacherQuizInteractiveSheetState
|
||||
'total': widget.questions.length,
|
||||
'submittedAt': FieldValue.serverTimestamp(),
|
||||
});
|
||||
|
||||
|
||||
// Registrar atividade no sistema de gamificação
|
||||
await GamificationService.recordQuizActivity(
|
||||
user.uid,
|
||||
|
||||
@@ -34,7 +34,7 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
.collection('users')
|
||||
.doc(user.uid)
|
||||
.get();
|
||||
|
||||
|
||||
if (userDoc.exists) {
|
||||
setState(() {
|
||||
_userRole = userDoc.data()?['role'] ?? '';
|
||||
@@ -49,7 +49,7 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
if (user == null) return;
|
||||
|
||||
Query query;
|
||||
|
||||
|
||||
if (_userRole == 'teacher') {
|
||||
// Professor: ver todos os quizzes criados
|
||||
query = FirebaseFirestore.instance
|
||||
@@ -59,7 +59,10 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
} else {
|
||||
// Aluno: ver quizzes criados pelo próprio aluno + conceitos dominados
|
||||
final results = await Future.wait([
|
||||
FirebaseFirestore.instance.collection('userStats').doc(user.uid).get(),
|
||||
FirebaseFirestore.instance
|
||||
.collection('userStats')
|
||||
.doc(user.uid)
|
||||
.get(),
|
||||
FirebaseFirestore.instance
|
||||
.collection('quizHistory')
|
||||
.doc(user.uid)
|
||||
@@ -67,12 +70,12 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
.orderBy('createdAt', descending: true)
|
||||
.get(),
|
||||
]);
|
||||
|
||||
|
||||
final userStatsSnapshot = results[0] as DocumentSnapshot;
|
||||
final studentQuizzesSnapshot = results[1] as QuerySnapshot;
|
||||
|
||||
|
||||
List<Map<String, dynamic>> quizList = [];
|
||||
|
||||
|
||||
// Adicionar quizzes criados pelo aluno
|
||||
for (final doc in studentQuizzesSnapshot.docs) {
|
||||
final data = Map<String, dynamic>.from(doc.data() as Map);
|
||||
@@ -81,15 +84,17 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
data['type'] = 'created';
|
||||
quizList.add(data);
|
||||
}
|
||||
|
||||
|
||||
// Adicionar conceitos dominados
|
||||
if (userStatsSnapshot.exists) {
|
||||
final stats = userStatsSnapshot.data() as Map<String, dynamic>?;
|
||||
if (stats != null) {
|
||||
final masteredConcepts = (stats['masteredConcepts'] as List<dynamic>?)
|
||||
?.map((c) => Map<String, dynamic>.from(c as Map))
|
||||
.toList() ?? [];
|
||||
|
||||
final masteredConcepts =
|
||||
(stats['masteredConcepts'] as List<dynamic>?)
|
||||
?.map((c) => Map<String, dynamic>.from(c as Map))
|
||||
.toList() ??
|
||||
[];
|
||||
|
||||
for (final concept in masteredConcepts) {
|
||||
quizList.add({
|
||||
'id': concept['conceptName'] ?? '',
|
||||
@@ -102,7 +107,7 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setState(() {
|
||||
_quizHistory = quizList;
|
||||
_loading = false;
|
||||
@@ -111,13 +116,16 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
}
|
||||
|
||||
final snapshot = await query.get();
|
||||
|
||||
|
||||
setState(() {
|
||||
_quizHistory = snapshot.docs.map((doc) {
|
||||
final data = Map<String, dynamic>.from(doc.data() as Map);
|
||||
data['id'] = doc.id;
|
||||
return data;
|
||||
}).cast<Map<String, dynamic>>().toList();
|
||||
_quizHistory = snapshot.docs
|
||||
.map((doc) {
|
||||
final data = Map<String, dynamic>.from(doc.data() as Map);
|
||||
data['id'] = doc.id;
|
||||
return data;
|
||||
})
|
||||
.cast<Map<String, dynamic>>()
|
||||
.toList();
|
||||
_loading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -132,21 +140,27 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
try {
|
||||
String confirmMessage;
|
||||
String successMessage;
|
||||
|
||||
|
||||
if (_userRole == 'teacher') {
|
||||
confirmMessage = 'Tem certeza que deseja eliminar o quiz "$quizTitle"? Esta ação não pode ser desfeita.';
|
||||
confirmMessage =
|
||||
'Tem certeza que deseja eliminar o quiz "$quizTitle"? Esta ação não pode ser desfeita.';
|
||||
successMessage = 'Quiz eliminado com sucesso!';
|
||||
} else {
|
||||
if (type == 'created') {
|
||||
confirmMessage = 'Tem certeza que deseja eliminar seu quiz "$quizTitle"?';
|
||||
confirmMessage =
|
||||
'Tem certeza que deseja eliminar seu quiz "$quizTitle"?';
|
||||
successMessage = 'Quiz eliminado com sucesso!';
|
||||
} else {
|
||||
confirmMessage = 'Tem certeza que deseja remover o conceito "$quizTitle" do seu histórico?';
|
||||
confirmMessage =
|
||||
'Tem certeza que deseja remover o conceito "$quizTitle" do seu histórico?';
|
||||
successMessage = 'Conceito removido com sucesso!';
|
||||
}
|
||||
}
|
||||
|
||||
final confirmed = await _showDeleteConfirmation(quizTitle, confirmMessage);
|
||||
|
||||
final confirmed = await _showDeleteConfirmation(
|
||||
quizTitle,
|
||||
confirmMessage,
|
||||
);
|
||||
if (!confirmed) return;
|
||||
|
||||
if (_userRole == 'teacher') {
|
||||
@@ -155,13 +169,13 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
.collection('teacherQuizzes')
|
||||
.doc(quizId)
|
||||
.delete();
|
||||
|
||||
|
||||
// Também eliminar do histórico de alunos
|
||||
final historySnapshot = await FirebaseFirestore.instance
|
||||
.collection('quizHistory')
|
||||
.where('quizId', isEqualTo: quizId)
|
||||
.get();
|
||||
|
||||
|
||||
for (final doc in historySnapshot.docs) {
|
||||
await doc.reference.delete();
|
||||
}
|
||||
@@ -186,26 +200,30 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
.collection('userStats')
|
||||
.doc(user.uid)
|
||||
.get();
|
||||
|
||||
|
||||
if (userStatsDoc.exists) {
|
||||
final userStats = userStatsDoc.data() as Map<String, dynamic>;
|
||||
final masteredConcepts = (userStats['masteredConcepts'] as List<dynamic>?)
|
||||
?.map((c) => Map<String, dynamic>.from(c as Map))
|
||||
.toList() ?? [];
|
||||
|
||||
final masteredConcepts =
|
||||
(userStats['masteredConcepts'] as List<dynamic>?)
|
||||
?.map((c) => Map<String, dynamic>.from(c as Map))
|
||||
.toList() ??
|
||||
[];
|
||||
|
||||
// Encontrar o conceito específico para remover
|
||||
final conceptToRemove = masteredConcepts.firstWhere(
|
||||
(c) => c['conceptName'] == quizId,
|
||||
orElse: () => {},
|
||||
);
|
||||
|
||||
|
||||
if (conceptToRemove.isNotEmpty) {
|
||||
await FirebaseFirestore.instance
|
||||
.collection('userStats')
|
||||
.doc(user.uid)
|
||||
.update({
|
||||
'masteredConcepts': FieldValue.arrayRemove([conceptToRemove])
|
||||
});
|
||||
'masteredConcepts': FieldValue.arrayRemove([
|
||||
conceptToRemove,
|
||||
]),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -213,7 +231,7 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
}
|
||||
|
||||
_loadQuizHistory(); // Recarregar lista
|
||||
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
@@ -239,7 +257,9 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
final result = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(_userRole == 'teacher' ? 'Eliminar Quiz' : 'Confirmar Eliminação'),
|
||||
title: Text(
|
||||
_userRole == 'teacher' ? 'Eliminar Quiz' : 'Confirmar Eliminação',
|
||||
),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -264,15 +284,25 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
return Scaffold(
|
||||
backgroundColor: cs.surface,
|
||||
appBar: AppBar(
|
||||
title: Text(_userRole == 'teacher' ? 'Gerenciar Quizzes' : 'Meu Histórico'),
|
||||
title: Text(
|
||||
_userRole == 'teacher' ? 'Gerenciar Quizzes' : 'Meu Histórico',
|
||||
),
|
||||
backgroundColor: cs.surface,
|
||||
foregroundColor: cs.onSurface,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () => context.go(_userRole == 'teacher'
|
||||
? '/teacher-dashboard'
|
||||
: '/student-dashboard'),
|
||||
onPressed: () {
|
||||
if (Navigator.of(context).canPop()) {
|
||||
Navigator.of(context).pop();
|
||||
} else {
|
||||
context.go(
|
||||
_userRole == 'teacher'
|
||||
? '/teacher-dashboard'
|
||||
: '/student-dashboard',
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
body: Container(
|
||||
@@ -280,34 +310,31 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
cs.primary.withValues(alpha: 0.05),
|
||||
cs.surface,
|
||||
],
|
||||
colors: [cs.primary.withValues(alpha: 0.05), cs.surface],
|
||||
),
|
||||
),
|
||||
child: _loading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _quizHistory.isEmpty
|
||||
? _buildEmptyState()
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: _quizHistory.length,
|
||||
itemBuilder: (context, index) {
|
||||
final quiz = _quizHistory[index];
|
||||
return _buildQuizCard(quiz)
|
||||
.animate()
|
||||
.slideX(duration: const Duration(milliseconds: 300))
|
||||
.then(delay: Duration(milliseconds: index * 50));
|
||||
},
|
||||
),
|
||||
? _buildEmptyState()
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: _quizHistory.length,
|
||||
itemBuilder: (context, index) {
|
||||
final quiz = _quizHistory[index];
|
||||
return _buildQuizCard(quiz)
|
||||
.animate()
|
||||
.slideX(duration: const Duration(milliseconds: 300))
|
||||
.then(delay: Duration(milliseconds: index * 50));
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
@@ -315,13 +342,17 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
_userRole == 'teacher' ? Icons.quiz_outlined : Icons.history_edu_outlined,
|
||||
_userRole == 'teacher'
|
||||
? Icons.quiz_outlined
|
||||
: Icons.history_edu_outlined,
|
||||
size: 64,
|
||||
color: cs.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_userRole == 'teacher' ? 'Nenhum quiz criado' : 'Nenhum quiz no histórico',
|
||||
_userRole == 'teacher'
|
||||
? 'Nenhum quiz criado'
|
||||
: 'Nenhum quiz no histórico',
|
||||
style: TextStyle(
|
||||
color: cs.onSurface,
|
||||
fontSize: 20,
|
||||
@@ -331,13 +362,10 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_userRole == 'teacher'
|
||||
_userRole == 'teacher'
|
||||
? 'Crie seu primeiro quiz para começar!'
|
||||
: 'Complete alguns quizzes para ver seu histórico aqui.',
|
||||
style: TextStyle(
|
||||
color: cs.onSurfaceVariant,
|
||||
fontSize: 14,
|
||||
),
|
||||
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 14),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
@@ -348,7 +376,7 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
|
||||
Widget _buildQuizCard(Map<String, dynamic> quiz) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(16),
|
||||
@@ -405,11 +433,12 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => _deleteQuiz(quiz['id'], quiz['title'] ?? 'Quiz', quiz['type'] ?? 'unknown'),
|
||||
icon: Icon(
|
||||
Icons.delete_outline,
|
||||
color: Colors.red,
|
||||
onPressed: () => _deleteQuiz(
|
||||
quiz['id'],
|
||||
quiz['title'] ?? 'Quiz',
|
||||
quiz['type'] ?? 'unknown',
|
||||
),
|
||||
icon: Icon(Icons.delete_outline, color: Colors.red),
|
||||
tooltip: _userRole == 'teacher' ? 'Eliminar Quiz' : 'Remover',
|
||||
),
|
||||
],
|
||||
@@ -420,13 +449,16 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
spacing: 4,
|
||||
children: (quiz['classIds'] as List<dynamic>).map((classId) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
'Turma: $classId',
|
||||
'Disciplina: $classId',
|
||||
style: TextStyle(
|
||||
color: cs.onPrimaryContainer,
|
||||
fontSize: 10,
|
||||
@@ -443,7 +475,7 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
|
||||
String _formatDate(dynamic date) {
|
||||
if (date == null) return 'Data desconhecida';
|
||||
|
||||
|
||||
DateTime dateTime;
|
||||
if (date is Timestamp) {
|
||||
dateTime = date.toDate();
|
||||
@@ -452,7 +484,7 @@ class _QuizManagementPageState extends State<QuizManagementPage> {
|
||||
} else {
|
||||
return 'Data desconhecida';
|
||||
}
|
||||
|
||||
|
||||
return '${dateTime.day}/${dateTime.month}/${dateTime.year}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user