ultimas resoluções

This commit is contained in:
2026-05-17 20:07:42 +01:00
parent e388ca3b67
commit 2a2194699b

View File

@@ -1,12 +1,70 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import '../../../../core/theme/app_theme_extension.dart'; import '../../../../core/theme/app_theme_extension.dart';
import '../../../../core/services/auth_service.dart'; import '../../../../core/services/auth_service.dart';
import '../../../../core/services/gamification_service.dart';
import '../../../../core/models/class_stats.dart';
/// Analytics preview section for teacher dashboard /// Analytics preview section for teacher dashboard
class TeacherAnalyticsPreviewWidget extends StatelessWidget { class TeacherAnalyticsPreviewWidget extends StatefulWidget {
const TeacherAnalyticsPreviewWidget({super.key}); const TeacherAnalyticsPreviewWidget({super.key});
@override
State<TeacherAnalyticsPreviewWidget> createState() => _TeacherAnalyticsPreviewWidgetState();
}
class _TeacherAnalyticsPreviewWidgetState extends State<TeacherAnalyticsPreviewWidget> {
List<StudentRanking> _topStudents = [];
bool _loading = true;
@override
void initState() {
super.initState();
_loadTopStudents();
}
Future<void> _loadTopStudents() async {
try {
final user = AuthService.currentUser;
if (user == null) return;
// Obter turmas do professor
final classesSnapshot = await FirebaseFirestore.instance
.collection('classes')
.where('teacherId', isEqualTo: user.uid)
.get();
List<StudentRanking> allStudents = [];
// Buscar ranking de cada turma
for (final classDoc in classesSnapshot.docs) {
final classId = classDoc.id;
// Forçar atualização para obter dados mais recentes
final rankings = await GamificationService.getClassRanking(classId);
allStudents.addAll(rankings);
}
// Ordenar por score e pegar os top 4
allStudents.sort((a, b) => b.overallScore.compareTo(a.overallScore));
final top4 = allStudents.take(4).toList();
if (mounted) {
setState(() {
_topStudents = top4;
_loading = false;
});
}
} catch (e) {
print('Error loading top students: $e');
if (mounted) {
setState(() {
_loading = false;
});
}
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final user = AuthService.currentUser; final user = AuthService.currentUser;
@@ -161,33 +219,31 @@ class TeacherAnalyticsPreviewWidget extends StatelessWidget {
const SizedBox(height: 12), const SizedBox(height: 12),
// Student List Preview // Student List Preview
_buildStudentPerformanceItem( if (_loading)
context, const Center(child: CircularProgressIndicator())
'Ana Silva', else if (_topStudents.isEmpty)
95, const Center(
Theme.of(context).colorScheme.tertiary, child: Text(
'Nenhum aluno encontrado',
style: TextStyle(fontSize: 14),
), ),
const SizedBox(height: 8), )
_buildStudentPerformanceItem( else
..._topStudents.asMap().entries.map((entry) {
final index = entry.key;
final student = entry.value;
final color = _getStudentColor(context, index);
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: _buildStudentPerformanceItem(
context, context,
'João Costa', student.studentName,
88, student.overallScore.toInt(),
Theme.of(context).colorScheme.primary, color,
),
const SizedBox(height: 8),
_buildStudentPerformanceItem(
context,
'Maria Santos',
82,
Theme.of(context).colorScheme.primary,
),
const SizedBox(height: 8),
_buildStudentPerformanceItem(
context,
'Pedro Lima',
45,
Theme.of(context).colorScheme.secondary,
), ),
);
}).toList(),
const SizedBox(height: 20), const SizedBox(height: 20),
@@ -279,6 +335,16 @@ class TeacherAnalyticsPreviewWidget extends StatelessWidget {
); );
} }
Color _getStudentColor(BuildContext context, int index) {
final colors = [
Theme.of(context).colorScheme.tertiary,
Theme.of(context).colorScheme.primary,
Theme.of(context).colorScheme.primary,
Theme.of(context).colorScheme.secondary,
];
return colors[index % colors.length];
}
Widget _buildStudentPerformanceItem( Widget _buildStudentPerformanceItem(
BuildContext context, BuildContext context,
String name, String name,