Teacher dashboard updates
This commit is contained in:
@@ -22,9 +22,13 @@ class TeacherDashboardPage extends StatefulWidget {
|
|||||||
State<TeacherDashboardPage> createState() => _TeacherDashboardPageState();
|
State<TeacherDashboardPage> createState() => _TeacherDashboardPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _TeacherDashboardPageState extends State<TeacherDashboardPage> {
|
class _TeacherDashboardPageState extends State<TeacherDashboardPage>
|
||||||
|
with AutomaticKeepAliveClientMixin {
|
||||||
String _userName = 'Professor';
|
String _userName = 'Professor';
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get wantKeepAlive => true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.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 {
|
Future<void> _checkRoleAndLoadData() async {
|
||||||
final user = AuthService.currentUser;
|
final user = AuthService.currentUser;
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
@@ -94,6 +104,7 @@ class _TeacherDashboardPageState extends State<TeacherDashboardPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
super.build(context);
|
||||||
final themeExtras = AppThemeExtras.of(context);
|
final themeExtras = AppThemeExtras.of(context);
|
||||||
final headerColor = themeExtras.dashboardHeaderTextColor;
|
final headerColor = themeExtras.dashboardHeaderTextColor;
|
||||||
|
|
||||||
@@ -107,83 +118,86 @@ class _TeacherDashboardPageState extends State<TeacherDashboardPage> {
|
|||||||
stops: themeExtras.dashboardGradientStops,
|
stops: themeExtras.dashboardGradientStops,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: SafeArea(
|
child: RefreshIndicator(
|
||||||
top: false,
|
onRefresh: _refreshDashboard,
|
||||||
child: SingleChildScrollView(
|
child: SafeArea(
|
||||||
child: Padding(
|
top: false,
|
||||||
padding: const EdgeInsets.only(
|
child: SingleChildScrollView(
|
||||||
left: 24.0,
|
child: Padding(
|
||||||
right: 24.0,
|
padding: const EdgeInsets.only(
|
||||||
bottom: 28.0,
|
left: 24.0,
|
||||||
top: 52.0,
|
right: 24.0,
|
||||||
),
|
bottom: 28.0,
|
||||||
child: Column(
|
top: 52.0,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
),
|
||||||
children: [
|
child: Column(
|
||||||
// Header with logout and settings
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
Row(
|
children: [
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
// Header with logout and settings
|
||||||
children: [
|
Row(
|
||||||
Expanded(
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
child: Column(
|
children: [
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
Expanded(
|
||||||
children: [
|
child: Column(
|
||||||
Text(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
'Bem-vindo, $_userName!',
|
children: [
|
||||||
style: TextStyle(
|
Text(
|
||||||
color: headerColor,
|
'Bem-vindo, $_userName!',
|
||||||
fontSize: 28,
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
color: headerColor,
|
||||||
|
fontSize: 28,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 4),
|
||||||
const SizedBox(height: 4),
|
Text(
|
||||||
Text(
|
'Painel de Gestão de Conteúdo',
|
||||||
'Painel de Gestão de Conteúdo',
|
style: TextStyle(
|
||||||
style: TextStyle(
|
color: headerColor,
|
||||||
color: headerColor,
|
fontSize: 16,
|
||||||
fontSize: 16,
|
fontWeight: FontWeight.w300,
|
||||||
fontWeight: FontWeight.w300,
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
IconButton(
|
||||||
IconButton(
|
icon: Icon(Icons.settings, color: headerColor),
|
||||||
icon: Icon(Icons.settings, color: headerColor),
|
onPressed: () {
|
||||||
onPressed: () {
|
AppRouter.goToSettings(context);
|
||||||
AppRouter.goToSettings(context);
|
},
|
||||||
},
|
tooltip: 'Configurações',
|
||||||
tooltip: 'Configurações',
|
),
|
||||||
),
|
IconButton(
|
||||||
IconButton(
|
icon: Icon(Icons.logout, color: headerColor),
|
||||||
icon: Icon(Icons.logout, color: headerColor),
|
onPressed: () async {
|
||||||
onPressed: () async {
|
await AuthService.signOut();
|
||||||
await AuthService.signOut();
|
if (mounted) {
|
||||||
if (mounted) {
|
context.go('/login');
|
||||||
context.go('/login');
|
}
|
||||||
}
|
},
|
||||||
},
|
tooltip: 'Sair',
|
||||||
tooltip: 'Sair',
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
const SizedBox(height: 32),
|
||||||
const SizedBox(height: 32),
|
|
||||||
|
|
||||||
// Hero Section - Class Overview
|
// Hero Section - Class Overview
|
||||||
TeacherHeroWidget(userName: _userName),
|
TeacherHeroWidget(userName: _userName),
|
||||||
|
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
|
|
||||||
// Quick Actions Section
|
// Quick Actions Section
|
||||||
const TeacherQuickActionsWidget(),
|
const TeacherQuickActionsWidget(),
|
||||||
|
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
|
|
||||||
// Classes List Section
|
// Classes List Section
|
||||||
const TeacherClassesListWidget(),
|
const TeacherClassesListWidget(),
|
||||||
|
|
||||||
const SizedBox(height: 40),
|
const SizedBox(height: 40),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
|
|
||||||
import '../../../../core/theme/app_theme_extension.dart';
|
|
||||||
import '../../../../core/services/gamification_service.dart';
|
import '../../../../core/services/gamification_service.dart';
|
||||||
import '../../../../core/models/class_stats.dart';
|
import '../../../../core/models/class_stats.dart';
|
||||||
import '../../../../core/services/auth_service.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
|
/// Hero section for teacher dashboard showing class overview
|
||||||
class TeacherHeroWidget extends StatefulWidget {
|
class TeacherHeroWidget extends StatefulWidget {
|
||||||
final String userName;
|
final String userName;
|
||||||
|
final VoidCallback? onRefresh;
|
||||||
|
|
||||||
const TeacherHeroWidget({super.key, required this.userName});
|
const TeacherHeroWidget({super.key, required this.userName, this.onRefresh});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<TeacherHeroWidget> createState() => _TeacherHeroWidgetState();
|
State<TeacherHeroWidget> createState() => _TeacherHeroWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
|
class _TeacherHeroWidgetState extends State<TeacherHeroWidget>
|
||||||
|
with AutomaticKeepAliveClientMixin {
|
||||||
List<ClassStats> _classStats = [];
|
List<ClassStats> _classStats = [];
|
||||||
|
List<ClassStats> _cachedClassStats = [];
|
||||||
bool _loading = true;
|
bool _loading = true;
|
||||||
|
bool _isFirstLoad = true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get wantKeepAlive => true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -26,11 +32,24 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
|
|||||||
_loadClassStats();
|
_loadClassStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadClassStats() async {
|
Future<void> _loadClassStats({bool forceRefresh = false}) async {
|
||||||
try {
|
try {
|
||||||
final user = AuthService.currentUser;
|
final user = AuthService.currentUser;
|
||||||
if (user == null) return;
|
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
|
// Obter turmas do professor
|
||||||
final classesSnapshot = await FirebaseFirestore.instance
|
final classesSnapshot = await FirebaseFirestore.instance
|
||||||
.collection('classes')
|
.collection('classes')
|
||||||
@@ -41,10 +60,9 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
|
|||||||
|
|
||||||
for (final classDoc in classesSnapshot.docs) {
|
for (final classDoc in classesSnapshot.docs) {
|
||||||
final classId = classDoc.id;
|
final classId = classDoc.id;
|
||||||
// Forçar atualização para obter dados mais recentes
|
|
||||||
final stats = await GamificationService.getClassStats(
|
final stats = await GamificationService.getClassStats(
|
||||||
classId,
|
classId,
|
||||||
forceRefresh: true,
|
forceRefresh: forceRefresh,
|
||||||
);
|
);
|
||||||
if (stats != null) {
|
if (stats != null) {
|
||||||
classStatsList.add(stats);
|
classStatsList.add(stats);
|
||||||
@@ -54,7 +72,9 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
|
|||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_classStats = classStatsList;
|
_classStats = classStatsList;
|
||||||
|
_cachedClassStats = classStatsList;
|
||||||
_loading = false;
|
_loading = false;
|
||||||
|
_isFirstLoad = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -62,19 +82,27 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
|
|||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_loading = false;
|
_loading = false;
|
||||||
|
_isFirstLoad = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Public method to refresh data
|
||||||
|
Future<void> refresh() async {
|
||||||
|
await _loadClassStats(forceRefresh: true);
|
||||||
|
}
|
||||||
|
|
||||||
int get totalStudents =>
|
int get totalStudents =>
|
||||||
_classStats.fold(0, (sum, stats) => sum + stats.totalStudents);
|
_classStats.fold(0, (sum, stats) => sum + stats.totalStudents);
|
||||||
int get activeQuizzes =>
|
int get activeQuizzes =>
|
||||||
_classStats.fold(0, (sum, stats) => sum + stats.activeQuizzes);
|
_classStats.fold(0, (sum, stats) => sum + stats.activeQuizzes);
|
||||||
int get uploadedContent =>
|
int get uploadedContent =>
|
||||||
_classStats.fold(0, (sum, stats) => sum + stats.totalContent);
|
_classStats.fold(0, (sum, stats) => sum + stats.totalContent);
|
||||||
int get studentsNeedingSupport =>
|
int get studentsNeedingSupport => _classStats.fold(
|
||||||
_classStats.fold(0, (sum, stats) => sum + stats.studentsNeedingSupport.length);
|
0,
|
||||||
|
(sum, stats) => sum + stats.studentsNeedingSupport.length,
|
||||||
|
);
|
||||||
double get classAverageProgress {
|
double get classAverageProgress {
|
||||||
if (_classStats.isEmpty) return 0.0;
|
if (_classStats.isEmpty) return 0.0;
|
||||||
final totalProgress = _classStats.fold(
|
final totalProgress = _classStats.fold(
|
||||||
@@ -98,6 +126,7 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
super.build(context);
|
||||||
if (_loading) {
|
if (_loading) {
|
||||||
return Container(
|
return Container(
|
||||||
margin: const EdgeInsets.only(bottom: 24),
|
margin: const EdgeInsets.only(bottom: 24),
|
||||||
@@ -189,72 +218,6 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
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
|
// Stats Grid
|
||||||
IntrinsicHeight(
|
IntrinsicHeight(
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -275,14 +238,6 @@ class _TeacherHeroWidgetState extends State<TeacherHeroWidget> {
|
|||||||
label: 'Conteúdos',
|
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'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -325,80 +325,83 @@ class _ContentManagementPageState extends State<ContentManagementPage> {
|
|||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
SafeArea(
|
Container(
|
||||||
top: false,
|
decoration: BoxDecoration(color: const Color(0xFF82C9BD)),
|
||||||
child: Padding(
|
child: SafeArea(
|
||||||
padding: const EdgeInsets.only(
|
top: false,
|
||||||
left: 16,
|
child: Padding(
|
||||||
right: 16,
|
padding: const EdgeInsets.only(
|
||||||
bottom: 20,
|
left: 16,
|
||||||
top: 52,
|
right: 16,
|
||||||
),
|
bottom: 20,
|
||||||
child: Column(
|
top: 52,
|
||||||
children: [
|
),
|
||||||
Row(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
children: [
|
||||||
children: [
|
Row(
|
||||||
IconButton(
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
icon: Icon(Icons.arrow_back, color: cs.onSurface),
|
children: [
|
||||||
onPressed: () => Navigator.pop(context),
|
IconButton(
|
||||||
),
|
icon: Icon(Icons.arrow_back, color: Colors.white),
|
||||||
const SizedBox(width: 8),
|
onPressed: () => Navigator.pop(context),
|
||||||
Expanded(
|
),
|
||||||
child: Text(
|
const SizedBox(width: 8),
|
||||||
'Gerenciamento de Conteúdo',
|
Expanded(
|
||||||
style: TextStyle(
|
child: Text(
|
||||||
color: cs.onSurface,
|
'Gerenciamento de Conteúdo',
|
||||||
fontSize: 24,
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
color: Colors.white,
|
||||||
|
fontSize: 24,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: cs.surface.withOpacity(0.8),
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
border: Border.all(
|
|
||||||
color: cs.outline.withOpacity(0.2),
|
|
||||||
width: 1,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: TextField(
|
const SizedBox(height: 8),
|
||||||
controller: _searchController,
|
Container(
|
||||||
decoration: InputDecoration(
|
decoration: BoxDecoration(
|
||||||
hintText: 'Procurar turmas...',
|
color: Colors.white.withOpacity(0.9),
|
||||||
hintStyle: TextStyle(color: cs.onSurfaceVariant),
|
borderRadius: BorderRadius.circular(16),
|
||||||
prefixIcon: Icon(
|
border: Border.all(
|
||||||
Icons.search,
|
color: Colors.white.withOpacity(0.3),
|
||||||
color: cs.onSurfaceVariant,
|
width: 1,
|
||||||
),
|
|
||||||
suffixIcon: _searchQuery.isNotEmpty
|
|
||||||
? IconButton(
|
|
||||||
icon: Icon(
|
|
||||||
Icons.clear,
|
|
||||||
color: cs.onSurfaceVariant,
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
_searchController.clear();
|
|
||||||
_filterClasses('');
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
filled: true,
|
|
||||||
fillColor: Colors.transparent,
|
|
||||||
border: InputBorder.none,
|
|
||||||
contentPadding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 16,
|
|
||||||
vertical: 12,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onChanged: _filterClasses,
|
child: TextField(
|
||||||
|
controller: _searchController,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Procurar turmas...',
|
||||||
|
hintStyle: TextStyle(color: Colors.grey[600]),
|
||||||
|
prefixIcon: Icon(
|
||||||
|
Icons.search,
|
||||||
|
color: Colors.grey[600],
|
||||||
|
),
|
||||||
|
suffixIcon: _searchQuery.isNotEmpty
|
||||||
|
? IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
Icons.clear,
|
||||||
|
color: Colors.grey[600],
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
_searchController.clear();
|
||||||
|
_filterClasses('');
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
filled: true,
|
||||||
|
fillColor: Colors.transparent,
|
||||||
|
border: InputBorder.none,
|
||||||
|
contentPadding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 16,
|
||||||
|
vertical: 12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onChanged: _filterClasses,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -570,22 +573,38 @@ class _ContentManagementPageState extends State<ContentManagementPage> {
|
|||||||
final fileName = material['fileName'] ?? 'Ficheiro sem nome';
|
final fileName = material['fileName'] ?? 'Ficheiro sem nome';
|
||||||
final url = material['url'] as String?;
|
final url = material['url'] as String?;
|
||||||
final createdAt = material['createdAt'] as Timestamp?;
|
final createdAt = material['createdAt'] as Timestamp?;
|
||||||
|
final mimeType = material['mimeType'] as String?;
|
||||||
|
|
||||||
final extension = path.extension(fileName).toLowerCase();
|
// Determine icon based on MIME type, fallback to extension
|
||||||
IconData iconData;
|
IconData iconData;
|
||||||
Color iconColor;
|
Color iconColor;
|
||||||
|
|
||||||
if (extension == '.pdf') {
|
if (mimeType != null) {
|
||||||
iconData = Icons.picture_as_pdf;
|
if (mimeType == 'application/pdf') {
|
||||||
iconColor = Colors.red;
|
iconData = Icons.picture_as_pdf;
|
||||||
} else if (extension == '.jpg' ||
|
iconColor = Colors.red;
|
||||||
extension == '.jpeg' ||
|
} else if (mimeType.startsWith('image/')) {
|
||||||
extension == '.png') {
|
iconData = Icons.image;
|
||||||
iconData = Icons.image;
|
iconColor = Colors.blue;
|
||||||
iconColor = Colors.blue;
|
} else {
|
||||||
|
iconData = Icons.insert_drive_file;
|
||||||
|
iconColor = const Color(0xFF82C9BD);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
iconData = Icons.insert_drive_file;
|
// Fallback to extension for old files without MIME type
|
||||||
iconColor = const Color(0xFF82C9BD);
|
final extension = path.extension(fileName).toLowerCase();
|
||||||
|
if (extension == '.pdf') {
|
||||||
|
iconData = Icons.picture_as_pdf;
|
||||||
|
iconColor = Colors.red;
|
||||||
|
} else if (extension == '.jpg' ||
|
||||||
|
extension == '.jpeg' ||
|
||||||
|
extension == '.png') {
|
||||||
|
iconData = Icons.image;
|
||||||
|
iconColor = Colors.blue;
|
||||||
|
} else {
|
||||||
|
iconData = Icons.insert_drive_file;
|
||||||
|
iconColor = const Color(0xFF82C9BD);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String formattedDate = 'Data desconhecida';
|
String formattedDate = 'Data desconhecida';
|
||||||
@@ -633,15 +652,16 @@ class _ContentManagementPageState extends State<ContentManagementPage> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
SingleChildScrollView(
|
||||||
fileName,
|
scrollDirection: Axis.horizontal,
|
||||||
style: TextStyle(
|
child: Text(
|
||||||
fontWeight: FontWeight.bold,
|
fileName,
|
||||||
fontSize: 15,
|
style: TextStyle(
|
||||||
color: cs.onSurface,
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 15,
|
||||||
|
color: cs.onSurface,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
maxLines: 2,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 6),
|
const SizedBox(height: 6),
|
||||||
Row(
|
Row(
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import 'package:path/path.dart' as path;
|
|||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
import '../../../../core/services/auth_service.dart';
|
import '../../../../core/services/auth_service.dart';
|
||||||
|
import 'pdf_viewer_page.dart';
|
||||||
|
|
||||||
/// Página de Materiais do Professor
|
/// Página de Materiais do Professor
|
||||||
/// Tela dedicada para upload e gestão de materiais para a IA
|
/// Tela dedicada para upload e gestão de materiais para a IA
|
||||||
@@ -78,10 +79,12 @@ class _TeacherMaterialsPageState extends State<TeacherMaterialsPage> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text(
|
title: const Text(
|
||||||
'Materiais da Disciplina',
|
'Gerenciamento de conteudo',
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
|
backgroundColor: const Color(0xFF82C9BD),
|
||||||
|
foregroundColor: Colors.white,
|
||||||
),
|
),
|
||||||
body: Container(
|
body: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@@ -116,10 +119,12 @@ class _TeacherMaterialsPageState extends State<TeacherMaterialsPage> {
|
|||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text(
|
title: const Text(
|
||||||
'Materiais da Disciplina',
|
'Gerenciamento de conteudo',
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
|
backgroundColor: const Color(0xFF82C9BD),
|
||||||
|
foregroundColor: Colors.white,
|
||||||
bottom: PreferredSize(
|
bottom: PreferredSize(
|
||||||
preferredSize: const Size.fromHeight(kToolbarHeight + 60),
|
preferredSize: const Size.fromHeight(kToolbarHeight + 60),
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -296,17 +301,32 @@ class _TeacherMaterialsPageState extends State<TeacherMaterialsPage> {
|
|||||||
final fileName =
|
final fileName =
|
||||||
material['fileName'] ?? 'Ficheiro sem nome';
|
material['fileName'] ?? 'Ficheiro sem nome';
|
||||||
final createdAt = material['createdAt'] as Timestamp?;
|
final createdAt = material['createdAt'] as Timestamp?;
|
||||||
final extension = path.extension(fileName).toLowerCase();
|
final mimeType = material['mimeType'] as String?;
|
||||||
final fileType = extension == '.pdf'
|
final url = material['url'] as String?;
|
||||||
? 'pdf'
|
|
||||||
: (extension == '.jpg' ||
|
// Determine file type from MIME type, fallback to extension
|
||||||
extension == '.jpeg' ||
|
String fileType;
|
||||||
extension == '.png')
|
if (mimeType != null) {
|
||||||
? 'image'
|
if (mimeType == 'application/pdf') {
|
||||||
: 'other';
|
fileType = 'pdf';
|
||||||
|
} else if (mimeType.startsWith('image/')) {
|
||||||
|
fileType = 'image';
|
||||||
|
} else {
|
||||||
|
fileType = 'other';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Fallback to extension for old files without MIME type
|
||||||
|
final extension = path.extension(fileName).toLowerCase();
|
||||||
|
fileType = extension == '.pdf'
|
||||||
|
? 'pdf'
|
||||||
|
: (extension == '.jpg' ||
|
||||||
|
extension == '.jpeg' ||
|
||||||
|
extension == '.png')
|
||||||
|
? 'image'
|
||||||
|
: 'other';
|
||||||
|
}
|
||||||
|
|
||||||
final docId = materials[index].id;
|
final docId = materials[index].id;
|
||||||
final url = material['url'] as String?;
|
|
||||||
|
|
||||||
return _buildMaterialCard(
|
return _buildMaterialCard(
|
||||||
docId: docId,
|
docId: docId,
|
||||||
@@ -699,7 +719,16 @@ class _TeacherMaterialsPageState extends State<TeacherMaterialsPage> {
|
|||||||
.child('materials')
|
.child('materials')
|
||||||
.child(cleanFileName);
|
.child(cleanFileName);
|
||||||
|
|
||||||
await ref.putFile(File(filePath));
|
// Set content type based on file type parameter
|
||||||
|
final metadata = SettableMetadata(
|
||||||
|
contentType: fileType == 'pdf'
|
||||||
|
? 'application/pdf'
|
||||||
|
: fileType == 'image'
|
||||||
|
? 'image/jpeg'
|
||||||
|
: 'application/octet-stream',
|
||||||
|
);
|
||||||
|
|
||||||
|
await ref.putFile(File(filePath), metadata);
|
||||||
final downloadUrl = await ref.getDownloadURL();
|
final downloadUrl = await ref.getDownloadURL();
|
||||||
|
|
||||||
// Criar documento no Firestore
|
// Criar documento no Firestore
|
||||||
@@ -707,6 +736,11 @@ class _TeacherMaterialsPageState extends State<TeacherMaterialsPage> {
|
|||||||
'teacherId': uid,
|
'teacherId': uid,
|
||||||
'fileName': cleanFileName,
|
'fileName': cleanFileName,
|
||||||
'url': downloadUrl,
|
'url': downloadUrl,
|
||||||
|
'mimeType': fileType == 'pdf'
|
||||||
|
? 'application/pdf'
|
||||||
|
: fileType == 'image'
|
||||||
|
? 'image/jpeg'
|
||||||
|
: 'application/octet-stream',
|
||||||
'createdAt': FieldValue.serverTimestamp(),
|
'createdAt': FieldValue.serverTimestamp(),
|
||||||
};
|
};
|
||||||
if (classId != null && classId.isNotEmpty) {
|
if (classId != null && classId.isNotEmpty) {
|
||||||
@@ -835,31 +869,6 @@ class _TeacherMaterialsPageState extends State<TeacherMaterialsPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _openFile(String? url, String fileName) async {
|
|
||||||
if (url == null || url.isEmpty) {
|
|
||||||
_showErrorSnackBar('URL do ficheiro não disponível');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
print('Opening file: $fileName');
|
|
||||||
print('URL: $url');
|
|
||||||
final uri = Uri.parse(url);
|
|
||||||
|
|
||||||
final launched = await launchUrl(
|
|
||||||
uri,
|
|
||||||
mode: LaunchMode.externalApplication,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!launched) {
|
|
||||||
_showErrorSnackBar('Não foi possível abrir o ficheiro');
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
print('Error opening file: $e');
|
|
||||||
_showErrorSnackBar('Erro ao abrir ficheiro: $e');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _downloadFile(String? url, String fileName) async {
|
Future<void> _downloadFile(String? url, String fileName) async {
|
||||||
if (url == null || url.isEmpty) {
|
if (url == null || url.isEmpty) {
|
||||||
_showErrorSnackBar('URL do ficheiro não disponível');
|
_showErrorSnackBar('URL do ficheiro não disponível');
|
||||||
@@ -887,6 +896,20 @@ class _TeacherMaterialsPageState extends State<TeacherMaterialsPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _viewInApp(String? url, String fileName) async {
|
||||||
|
if (url == null || url.isEmpty) {
|
||||||
|
_showErrorSnackBar('URL do ficheiro não disponível');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => PdfViewerPage(url: url, fileName: fileName),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildMaterialCard({
|
Widget _buildMaterialCard({
|
||||||
required String docId,
|
required String docId,
|
||||||
required String fileName,
|
required String fileName,
|
||||||
@@ -938,15 +961,16 @@ class _TeacherMaterialsPageState extends State<TeacherMaterialsPage> {
|
|||||||
),
|
),
|
||||||
child: Icon(iconData, color: iconColor, size: 28),
|
child: Icon(iconData, color: iconColor, size: 28),
|
||||||
),
|
),
|
||||||
title: Text(
|
title: SingleChildScrollView(
|
||||||
fileName,
|
scrollDirection: Axis.horizontal,
|
||||||
style: TextStyle(
|
child: Text(
|
||||||
fontWeight: FontWeight.w600,
|
fileName,
|
||||||
fontSize: 16,
|
style: TextStyle(
|
||||||
color: Theme.of(context).colorScheme.onSurface,
|
fontWeight: FontWeight.w600,
|
||||||
|
fontSize: 16,
|
||||||
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
maxLines: 2,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
formattedDate,
|
formattedDate,
|
||||||
@@ -962,7 +986,7 @@ class _TeacherMaterialsPageState extends State<TeacherMaterialsPage> {
|
|||||||
icon: const Icon(Icons.visibility_outlined, color: Colors.blue),
|
icon: const Icon(Icons.visibility_outlined, color: Colors.blue),
|
||||||
tooltip: 'Ver',
|
tooltip: 'Ver',
|
||||||
constraints: const BoxConstraints(minWidth: 40, minHeight: 40),
|
constraints: const BoxConstraints(minWidth: 40, minHeight: 40),
|
||||||
onPressed: () => _openFile(url, fileName),
|
onPressed: () => _viewInApp(url, fileName),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.download_outlined, color: Colors.green),
|
icon: const Icon(Icons.download_outlined, color: Colors.green),
|
||||||
|
|||||||
@@ -1141,13 +1141,13 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "1.17.0"
|
version: "1.17.0"
|
||||||
mime:
|
mime:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: mime
|
name: mime
|
||||||
sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6"
|
sha256: "801fd0b26f14a4a58ccb09d5892c3fbdeff209594300a542492cf13fba9d247a"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.0"
|
version: "1.0.6"
|
||||||
mockito:
|
mockito:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ dependencies:
|
|||||||
file_selector: ^1.0.3
|
file_selector: ^1.0.3
|
||||||
image_picker: ^1.0.4
|
image_picker: ^1.0.4
|
||||||
syncfusion_flutter_pdf: ^33.2.6
|
syncfusion_flutter_pdf: ^33.2.6
|
||||||
|
mime: ^1.0.5
|
||||||
|
|
||||||
# Markdown rendering
|
# Markdown rendering
|
||||||
flutter_markdown: ^0.6.23
|
flutter_markdown: ^0.6.23
|
||||||
|
|||||||
Reference in New Issue
Block a user