Teacher dashboard updates

This commit is contained in:
2026-05-24 20:09:22 +01:00
parent 1a98fff5e8
commit c2fd663170
6 changed files with 301 additions and 307 deletions

View File

@@ -22,9 +22,13 @@ class TeacherDashboardPage extends StatefulWidget {
State<TeacherDashboardPage> createState() => _TeacherDashboardPageState();
}
class _TeacherDashboardPageState extends State<TeacherDashboardPage> {
class _TeacherDashboardPageState extends State<TeacherDashboardPage>
with AutomaticKeepAliveClientMixin {
String _userName = 'Professor';
@override
bool get wantKeepAlive => true;
@override
void initState() {
super.initState();
@@ -36,6 +40,12 @@ class _TeacherDashboardPageState extends State<TeacherDashboardPage> {
}
}
Future<void> _refreshDashboard() async {
// Clear cached data to force refresh
TeacherDashboardPage.clearCachedUserName();
await _loadUserData();
}
Future<void> _checkRoleAndLoadData() async {
final user = AuthService.currentUser;
if (user == null) {
@@ -94,6 +104,7 @@ class _TeacherDashboardPageState extends State<TeacherDashboardPage> {
@override
Widget build(BuildContext context) {
super.build(context);
final themeExtras = AppThemeExtras.of(context);
final headerColor = themeExtras.dashboardHeaderTextColor;
@@ -107,83 +118,86 @@ class _TeacherDashboardPageState extends State<TeacherDashboardPage> {
stops: themeExtras.dashboardGradientStops,
),
),
child: SafeArea(
top: false,
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(
left: 24.0,
right: 24.0,
bottom: 28.0,
top: 52.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header with logout and settings
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Bem-vindo, $_userName!',
style: TextStyle(
color: headerColor,
fontSize: 28,
fontWeight: FontWeight.bold,
child: RefreshIndicator(
onRefresh: _refreshDashboard,
child: SafeArea(
top: false,
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(
left: 24.0,
right: 24.0,
bottom: 28.0,
top: 52.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header with logout and settings
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Bem-vindo, $_userName!',
style: TextStyle(
color: headerColor,
fontSize: 28,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 4),
Text(
'Painel de Gestão de Conteúdo',
style: TextStyle(
color: headerColor,
fontSize: 16,
fontWeight: FontWeight.w300,
const SizedBox(height: 4),
Text(
'Painel de Gestão de Conteúdo',
style: TextStyle(
color: headerColor,
fontSize: 16,
fontWeight: FontWeight.w300,
),
),
),
],
],
),
),
),
IconButton(
icon: Icon(Icons.settings, color: headerColor),
onPressed: () {
AppRouter.goToSettings(context);
},
tooltip: 'Configurações',
),
IconButton(
icon: Icon(Icons.logout, color: headerColor),
onPressed: () async {
await AuthService.signOut();
if (mounted) {
context.go('/login');
}
},
tooltip: 'Sair',
),
],
),
const SizedBox(height: 32),
IconButton(
icon: Icon(Icons.settings, color: headerColor),
onPressed: () {
AppRouter.goToSettings(context);
},
tooltip: 'Configurações',
),
IconButton(
icon: Icon(Icons.logout, color: headerColor),
onPressed: () async {
await AuthService.signOut();
if (mounted) {
context.go('/login');
}
},
tooltip: 'Sair',
),
],
),
const SizedBox(height: 32),
// Hero Section - Class Overview
TeacherHeroWidget(userName: _userName),
// Hero Section - Class Overview
TeacherHeroWidget(userName: _userName),
const SizedBox(height: 24),
const SizedBox(height: 24),
// Quick Actions Section
const TeacherQuickActionsWidget(),
// Quick Actions Section
const TeacherQuickActionsWidget(),
const SizedBox(height: 24),
const SizedBox(height: 24),
// Classes List Section
const TeacherClassesListWidget(),
// Classes List Section
const TeacherClassesListWidget(),
const SizedBox(height: 40),
],
const SizedBox(height: 40),
],
),
),
),
),

View File

@@ -1,7 +1,6 @@
import 'package:flutter/material.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';
@@ -9,16 +8,23 @@ import '../../../../core/services/auth_service.dart';
/// Hero section for teacher dashboard showing class overview
class TeacherHeroWidget extends StatefulWidget {
final String userName;
final VoidCallback? onRefresh;
const TeacherHeroWidget({super.key, required this.userName});
const TeacherHeroWidget({super.key, required this.userName, this.onRefresh});
@override
State<TeacherHeroWidget> createState() => _TeacherHeroWidgetState();
}
class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
class _TeacherHeroWidgetState extends State<TeacherHeroWidget>
with AutomaticKeepAliveClientMixin {
List<ClassStats> _classStats = [];
List<ClassStats> _cachedClassStats = [];
bool _loading = true;
bool _isFirstLoad = true;
@override
bool get wantKeepAlive => true;
@override
void initState() {
@@ -26,11 +32,24 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
_loadClassStats();
}
Future<void> _loadClassStats() async {
Future<void> _loadClassStats({bool forceRefresh = false}) async {
try {
final user = AuthService.currentUser;
if (user == null) return;
// Show cached data immediately if available and not forcing refresh
if (_cachedClassStats.isNotEmpty && !forceRefresh) {
setState(() {
_classStats = _cachedClassStats;
_loading = false;
});
return; // Don't reload if we have cached data
}
setState(() {
_loading = _isFirstLoad;
});
// Obter turmas do professor
final classesSnapshot = await FirebaseFirestore.instance
.collection('classes')
@@ -41,10 +60,9 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
for (final classDoc in classesSnapshot.docs) {
final classId = classDoc.id;
// Forçar atualização para obter dados mais recentes
final stats = await GamificationService.getClassStats(
classId,
forceRefresh: true,
forceRefresh: forceRefresh,
);
if (stats != null) {
classStatsList.add(stats);
@@ -54,7 +72,9 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
if (mounted) {
setState(() {
_classStats = classStatsList;
_cachedClassStats = classStatsList;
_loading = false;
_isFirstLoad = false;
});
}
} catch (e) {
@@ -62,19 +82,27 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
if (mounted) {
setState(() {
_loading = false;
_isFirstLoad = false;
});
}
}
}
/// Public method to refresh data
Future<void> refresh() async {
await _loadClassStats(forceRefresh: true);
}
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);
int get studentsNeedingSupport =>
_classStats.fold(0, (sum, stats) => sum + stats.studentsNeedingSupport.length);
int get studentsNeedingSupport => _classStats.fold(
0,
(sum, stats) => sum + stats.studentsNeedingSupport.length,
);
double get classAverageProgress {
if (_classStats.isEmpty) return 0.0;
final totalProgress = _classStats.fold(
@@ -98,6 +126,7 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
}
Widget build(BuildContext context) {
super.build(context);
if (_loading) {
return Container(
margin: const EdgeInsets.only(bottom: 24),
@@ -189,72 +218,6 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Overall Progress
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Flexible(
child: Text(
'Progresso Médio da Turma',
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
Builder(
builder: (context) {
final displayValue = (classAverageProgress * 100)
.toInt();
print('=== RENDER DEBUG ===');
print('classAverageProgress: $classAverageProgress');
print('displayValue: $displayValue%');
print('=== END RENDER DEBUG ===');
return Text(
'$displayValue%',
style: const TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold,
),
);
},
),
],
),
const SizedBox(height: 16),
// Progress Bar
GestureDetector(
onTap: () => _showProgressExplanation(context),
child: Container(
height: 12,
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.3),
borderRadius: BorderRadius.circular(6),
),
child: FractionallySizedBox(
alignment: Alignment.centerLeft,
widthFactor: classAverageProgress,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
AppThemeExtras.of(context).heroProgressStart,
AppThemeExtras.of(context).heroProgressEnd,
],
),
borderRadius: BorderRadius.circular(6),
),
),
),
),
),
const SizedBox(height: 20),
// Stats Grid
IntrinsicHeight(
child: Row(
@@ -275,14 +238,6 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
label: 'Conteúdos',
),
),
const SizedBox(width: 12),
Expanded(
child: _buildStatCard(
icon: Icons.warning_amber,
value: '$studentsNeedingSupport',
label: 'Precisam Apoio',
),
),
],
),
),
@@ -489,24 +444,4 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
],
);
}
void _showProgressExplanation(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Progresso Médio da Turma'),
content: const Text(
'O progresso médio da turma é calculado com base no domínio dos conceitos por cada aluno. '
'Cada aluno tem um nível de domínio para cada conceito (0-100%), e o progresso médio '
'é a média de todos esses níveis de domínio em toda a turma.',
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Entendi'),
),
],
),
);
}
}