ultimas resoluções
This commit is contained in:
@@ -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',
|
||||||
const SizedBox(height: 8),
|
style: TextStyle(fontSize: 14),
|
||||||
_buildStudentPerformanceItem(
|
),
|
||||||
context,
|
)
|
||||||
'João Costa',
|
else
|
||||||
88,
|
..._topStudents.asMap().entries.map((entry) {
|
||||||
Theme.of(context).colorScheme.primary,
|
final index = entry.key;
|
||||||
),
|
final student = entry.value;
|
||||||
const SizedBox(height: 8),
|
final color = _getStudentColor(context, index);
|
||||||
_buildStudentPerformanceItem(
|
|
||||||
context,
|
return Padding(
|
||||||
'Maria Santos',
|
padding: const EdgeInsets.only(bottom: 8),
|
||||||
82,
|
child: _buildStudentPerformanceItem(
|
||||||
Theme.of(context).colorScheme.primary,
|
context,
|
||||||
),
|
student.studentName,
|
||||||
const SizedBox(height: 8),
|
student.overallScore.toInt(),
|
||||||
_buildStudentPerformanceItem(
|
color,
|
||||||
context,
|
),
|
||||||
'Pedro Lima',
|
);
|
||||||
45,
|
}).toList(),
|
||||||
Theme.of(context).colorScheme.secondary,
|
|
||||||
),
|
|
||||||
|
|
||||||
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,
|
||||||
|
|||||||
Reference in New Issue
Block a user