placeholders removidos e todos os dados reais colocados, com conquistas e tudo
This commit is contained in:
@@ -1,27 +1,89 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
|
||||
import '../../../../core/theme/app_theme_extension.dart';
|
||||
import '../../../../core/services/gamification_service.dart';
|
||||
import '../../../../core/models/class_stats.dart';
|
||||
import '../../../../core/services/auth_service.dart';
|
||||
|
||||
/// Hero section for teacher dashboard showing class overview
|
||||
class TeacherHeroWidget extends StatelessWidget {
|
||||
class TeacherHeroWidget extends StatefulWidget {
|
||||
final String userName;
|
||||
final int totalStudents;
|
||||
final int activeQuizzes;
|
||||
final int uploadedContent;
|
||||
final double classAverageProgress;
|
||||
|
||||
const TeacherHeroWidget({
|
||||
super.key,
|
||||
required this.userName,
|
||||
this.totalStudents = 24,
|
||||
this.activeQuizzes = 3,
|
||||
this.uploadedContent = 12,
|
||||
this.classAverageProgress = 0.72,
|
||||
});
|
||||
|
||||
@override
|
||||
State<TeacherHeroWidget> createState() => _TeacherHeroWidgetState();
|
||||
}
|
||||
|
||||
class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
|
||||
List<ClassStats> _classStats = [];
|
||||
bool _loading = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadClassStats();
|
||||
}
|
||||
|
||||
Future<void> _loadClassStats() 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();
|
||||
|
||||
final classStatsList = <ClassStats>[];
|
||||
|
||||
for (final classDoc in classesSnapshot.docs) {
|
||||
final classId = classDoc.id;
|
||||
final stats = await GamificationService.getClassStats(classId);
|
||||
if (stats != null) {
|
||||
classStatsList.add(stats);
|
||||
}
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_classStats = classStatsList;
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error loading class stats: $e');
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int get totalStudents => _classStats.fold(0, (sum, stats) => sum + stats.totalStudents);
|
||||
int get activeQuizzes => _classStats.fold(0, (sum, stats) => sum + stats.activeQuizzes);
|
||||
int get uploadedContent => _classStats.fold(0, (sum, stats) => sum + stats.totalContent);
|
||||
double get classAverageProgress {
|
||||
if (_classStats.isEmpty) return 0.0;
|
||||
final totalProgress = _classStats.fold(0.0, (sum, stats) => sum + stats.averageProgress);
|
||||
return totalProgress / _classStats.length;
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
if (_loading) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 24),
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 24),
|
||||
child: Column(
|
||||
@@ -231,26 +293,7 @@ class TeacherHeroWidget extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildActivityItem(
|
||||
context,
|
||||
'15 alunos completaram o quiz de Derivadas',
|
||||
'Hoje, 14:30',
|
||||
Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildActivityItem(
|
||||
context,
|
||||
'Novo conteúdo: Regra da Cadeia',
|
||||
'Ontem, 09:15',
|
||||
Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildActivityItem(
|
||||
context,
|
||||
'3 alunos precisam de apoio em Limites',
|
||||
'Ontem, 16:45',
|
||||
Theme.of(context).colorScheme.error,
|
||||
),
|
||||
..._buildRecentActivities(),
|
||||
],
|
||||
),
|
||||
)
|
||||
@@ -302,6 +345,67 @@ class TeacherHeroWidget extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildRecentActivities() {
|
||||
final activities = <Widget>[];
|
||||
|
||||
if (_classStats.isEmpty) {
|
||||
activities.add(_buildActivityItem(
|
||||
context,
|
||||
'Nenhuma atividade recente',
|
||||
'Comece criando turmas e conteúdos',
|
||||
Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
));
|
||||
return activities;
|
||||
}
|
||||
|
||||
// Adicionar atividades baseadas nas estatísticas das turmas
|
||||
for (final stats in _classStats.take(3)) {
|
||||
if (stats.activeQuizzes > 0) {
|
||||
activities.add(_buildActivityItem(
|
||||
context,
|
||||
'${stats.activeQuizzes} quizzes ativos em ${stats.className}',
|
||||
'Recente',
|
||||
Theme.of(context).colorScheme.primary,
|
||||
));
|
||||
activities.add(const SizedBox(height: 8));
|
||||
}
|
||||
|
||||
if (stats.studentsNeedingSupport.isNotEmpty) {
|
||||
activities.add(_buildActivityItem(
|
||||
context,
|
||||
'${stats.studentsNeedingSupport.length} alunos precisam de apoio em ${stats.className}',
|
||||
'Ver analytics',
|
||||
Theme.of(context).colorScheme.error,
|
||||
));
|
||||
activities.add(const SizedBox(height: 8));
|
||||
}
|
||||
|
||||
if (stats.totalContent > 0) {
|
||||
activities.add(_buildActivityItem(
|
||||
context,
|
||||
'${stats.totalContent} conteúdos disponíveis em ${stats.className}',
|
||||
'Atualizado',
|
||||
Theme.of(context).colorScheme.secondary,
|
||||
));
|
||||
activities.add(const SizedBox(height: 8));
|
||||
}
|
||||
}
|
||||
|
||||
// Remover o último SizedBox se existir
|
||||
if (activities.isNotEmpty && activities.last is SizedBox) {
|
||||
activities.removeLast();
|
||||
}
|
||||
|
||||
return activities.isEmpty ? [
|
||||
_buildActivityItem(
|
||||
context,
|
||||
'Nenhuma atividade recente',
|
||||
'Comece criando turmas e conteúdos',
|
||||
Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
)
|
||||
] : activities;
|
||||
}
|
||||
|
||||
Widget _buildActivityItem(
|
||||
BuildContext context,
|
||||
String text,
|
||||
@@ -333,7 +437,7 @@ class TeacherHeroWidget extends StatelessWidget {
|
||||
style: TextStyle(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurfaceVariant.withOpacity(0.7),
|
||||
).colorScheme.onSurfaceVariant.withValues(alpha: 0.7),
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user