Alteração do acesso às settings, mudança visual na interface de entrar numa turma

This commit is contained in:
2026-05-17 14:34:19 +01:00
parent 51ea446ae9
commit 5649f7d96a
7 changed files with 924 additions and 344 deletions

View File

@@ -1,16 +1,17 @@
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../../core/services/auth_service.dart'; import '../../../../core/services/auth_service.dart';
/// Página para o aluno entrar numa turma usando o código /// Página para o aluno entrar numa turma usando o código
class JoinClassPage extends StatefulWidget { class JoinClassPage extends ConsumerStatefulWidget {
const JoinClassPage({super.key}); const JoinClassPage({super.key});
@override @override
State<JoinClassPage> createState() => _JoinClassPageState(); ConsumerState<JoinClassPage> createState() => _JoinClassPageState();
} }
class _JoinClassPageState extends State<JoinClassPage> { class _JoinClassPageState extends ConsumerState<JoinClassPage> {
final _codeController = TextEditingController(); final _codeController = TextEditingController();
bool _isLoading = false; bool _isLoading = false;
@@ -67,8 +68,7 @@ class _JoinClassPageState extends State<JoinClassPage> {
final classDoc = classQuery.docs.first; final classDoc = classQuery.docs.first;
final classId = classDoc.id; final classId = classDoc.id;
final classSchoolClassId = final classSchoolClassId = classDoc.data()['schoolClassId'] as String?;
classDoc.data()['schoolClassId'] as String?;
// Verificar se o aluno está autorizado a entrar nesta turma // Verificar se o aluno está autorizado a entrar nesta turma
// O schoolClassId do aluno deve corresponder ao schoolClassId da disciplina // O schoolClassId do aluno deve corresponder ao schoolClassId da disciplina
@@ -112,11 +112,22 @@ class _JoinClassPageState extends State<JoinClassPage> {
// Mostrar sucesso // Mostrar sucesso
if (mounted) { if (mounted) {
final colorScheme = Theme.of(context).colorScheme;
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
const SnackBar( SnackBar(
content: Text('Entraste na turma com sucesso!'), content: Row(
backgroundColor: Color(0xFF10B981), children: [
duration: Duration(seconds: 2), Icon(Icons.check_circle, color: Colors.white),
const SizedBox(width: 8),
const Text('Entraste na turma com sucesso!'),
],
),
backgroundColor: colorScheme.primary,
duration: const Duration(seconds: 2),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
), ),
); );
@@ -130,110 +141,273 @@ class _JoinClassPageState extends State<JoinClassPage> {
} }
void _showError(String message) { void _showError(String message) {
final colorScheme = Theme.of(context).colorScheme;
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text(message), content: Row(
backgroundColor: const Color(0xFFEF4444), children: [
Icon(Icons.error_outline, color: Colors.white),
const SizedBox(width: 8),
Expanded(child: Text(message)),
],
),
backgroundColor: colorScheme.error,
duration: const Duration(seconds: 3), duration: const Duration(seconds: 3),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
), ),
); );
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final theme = Theme.of(context);
final colorScheme = theme.colorScheme;
final isDark = theme.brightness == Brightness.dark;
return Scaffold( return Scaffold(
backgroundColor: const Color(0xFFF8F9FA), body: Container(
appBar: AppBar( decoration: BoxDecoration(
backgroundColor: const Color(0xFF82C9BD), gradient: LinearGradient(
elevation: 0, begin: Alignment.topLeft,
leading: IconButton( end: Alignment.bottomRight,
icon: const Icon(Icons.arrow_back, color: Colors.white), colors: isDark
? [
colorScheme.surfaceContainerHighest,
colorScheme.surface,
colorScheme.surfaceContainerLow,
]
: const [
Color(0xFFD4E8E8),
Color(0xFFE8D4C0),
Color(0xFFD8E0E8),
],
),
),
child: SafeArea(
child: Column(
children: [
// Custom AppBar
Container(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
IconButton(
icon: Icon(
Icons.arrow_back,
color: colorScheme.onSurface,
),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
), ),
title: const Text( Expanded(
child: Text(
'Entrar numa Turma', 'Entrar numa Turma',
style: TextStyle( style: TextStyle(
color: Colors.white, color: colorScheme.onSurface,
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
), ),
body: Padding( ],
),
),
// Body content
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24.0), padding: const EdgeInsets.all(24.0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Ícone e descrição const SizedBox(height: 20),
// Header illustration card
Center( Center(
child: Card(
elevation: isDark ? 4 : 8,
shadowColor: isDark
? Colors.black.withOpacity(0.4)
: Colors.black.withOpacity(0.1),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
child: Container( child: Container(
width: double.infinity,
padding: const EdgeInsets.all(32),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: isDark
? [
colorScheme.primary.withOpacity(0.1),
colorScheme.secondary.withOpacity(0.05),
]
: [
colorScheme.primary.withOpacity(0.05),
colorScheme.secondary.withOpacity(0.02),
],
),
),
child: Column(
children: [
Container(
width: 80, width: 80,
height: 80, height: 80,
decoration: BoxDecoration( decoration: BoxDecoration(
color: const Color(0xFF82C9BD).withOpacity(0.1), color: colorScheme.primary.withOpacity(0.1),
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
border: Border.all(
color: colorScheme.primary.withOpacity(
0.2,
), ),
child: const Icon( width: 2,
),
),
child: Icon(
Icons.group_add, Icons.group_add,
color: Color(0xFF82C9BD), color: colorScheme.primary,
size: 40, size: 40,
), ),
), ),
),
const SizedBox(height: 24), const SizedBox(height: 24),
const Center( Text(
child: Text(
'Insere o código da turma', 'Insere o código da turma',
style: TextStyle( style: theme.textTheme.headlineSmall
color: Color(0xFF2D3748), ?.copyWith(
fontSize: 18, color: colorScheme.onSurface,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), textAlign: TextAlign.center,
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
Center( Text(
child: Text(
'O professor partilhou contigo um código de 6 caracteres.', 'O professor partilhou contigo um código de 6 caracteres.',
style: TextStyle(color: Colors.grey[600], fontSize: 14), style: theme.textTheme.bodyMedium?.copyWith(
color: colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
],
),
),
),
),
const SizedBox(height: 32),
// Instructions card
Card(
elevation: isDark ? 2 : 4,
shadowColor: isDark
? Colors.black.withOpacity(0.3)
: Colors.black.withOpacity(0.08),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
Icons.info_outline,
color: colorScheme.primary,
size: 20,
),
const SizedBox(width: 8),
Text(
'Como funciona',
style: theme.textTheme.titleMedium
?.copyWith(
color: colorScheme.onSurface,
fontWeight: FontWeight.w600,
),
),
],
),
const SizedBox(height: 12),
_buildInstructionItem(
context,
'1.',
'Pedir ao professor o código da turma',
colorScheme,
),
const SizedBox(height: 8),
_buildInstructionItem(
context,
'2.',
'Inserir o código no campo abaixo',
colorScheme,
),
const SizedBox(height: 8),
_buildInstructionItem(
context,
'3.',
'Clicar em "Entrar na Turma" para confirmar',
colorScheme,
),
],
),
),
), ),
const SizedBox(height: 32), const SizedBox(height: 32),
// Campo de código // Campo de código
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: theme.cardColor,
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(16),
border: Border.all(color: const Color(0xFFE2E8F0), width: 1), border: Border.all(
color: colorScheme.outline.withOpacity(0.3),
width: 1,
),
boxShadow: [
BoxShadow(
color: isDark
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
), ),
child: TextField( child: TextField(
controller: _codeController, controller: _codeController,
textCapitalization: TextCapitalization.characters, textCapitalization: TextCapitalization.characters,
maxLength: 6, maxLength: 6,
style: const TextStyle( style: theme.textTheme.headlineMedium?.copyWith(
fontSize: 20,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
letterSpacing: 4, letterSpacing: 8,
color: Color(0xFF2D3748), color: colorScheme.onSurface,
), ),
textAlign: TextAlign.center, textAlign: TextAlign.center,
decoration: InputDecoration( decoration: InputDecoration(
hintText: 'XXXXXX', hintText: 'XXXXXX',
hintStyle: TextStyle( hintStyle: theme.textTheme.headlineMedium?.copyWith(
fontSize: 20,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
letterSpacing: 4, letterSpacing: 8,
color: Colors.grey[400], color: colorScheme.onSurfaceVariant.withOpacity(
0.5,
),
), ),
border: InputBorder.none, border: InputBorder.none,
contentPadding: const EdgeInsets.all(20), contentPadding: const EdgeInsets.all(24),
counterText: '', counterText: '',
prefixIcon: Icon(
Icons.vpn_key,
color: colorScheme.primary,
size: 24,
),
prefixIconConstraints: const BoxConstraints(
minWidth: 48,
minHeight: 48,
), ),
), ),
), ),
const SizedBox(height: 24), ),
const SizedBox(height: 32),
// Botão de entrar // Botão de entrar
SizedBox( SizedBox(
@@ -242,30 +416,65 @@ class _JoinClassPageState extends State<JoinClassPage> {
child: ElevatedButton( child: ElevatedButton(
onPressed: _isLoading ? null : _joinClass, onPressed: _isLoading ? null : _joinClass,
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF82C9BD), backgroundColor: colorScheme.primary,
foregroundColor: Colors.white, foregroundColor: colorScheme.onPrimary,
elevation: 0, elevation: 2,
shadowColor: colorScheme.primary.withOpacity(0.3),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(16),
), ),
disabledBackgroundColor: const Color( disabledBackgroundColor: colorScheme.primary
0xFF82C9BD, .withOpacity(0.5),
).withOpacity(0.5),
), ),
child: _isLoading child: _isLoading
? const SizedBox( ? SizedBox(
width: 24, width: 24,
height: 24, height: 24,
child: CircularProgressIndicator( child: CircularProgressIndicator(
color: Colors.white, color: colorScheme.onPrimary,
strokeWidth: 2, strokeWidth: 2,
), ),
) )
: const Text( : Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.login,
size: 20,
color: colorScheme.onPrimary,
),
const SizedBox(width: 8),
Text(
'Entrar na Turma', 'Entrar na Turma',
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: colorScheme.onPrimary,
),
),
],
),
),
),
const SizedBox(height: 16),
// Help text
Center(
child: TextButton.icon(
onPressed: () {
_showHelpDialog(context, colorScheme);
},
icon: Icon(
Icons.help_outline,
size: 16,
color: colorScheme.primary,
),
label: Text(
'Precisas de ajuda?',
style: TextStyle(
color: colorScheme.primary,
fontSize: 14,
fontWeight: FontWeight.w500,
), ),
), ),
), ),
@@ -273,6 +482,95 @@ class _JoinClassPageState extends State<JoinClassPage> {
], ],
), ),
), ),
),
],
),
),
),
);
}
Widget _buildInstructionItem(
BuildContext context,
String number,
String text,
ColorScheme colorScheme,
) {
final theme = Theme.of(context);
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 24,
height: 24,
decoration: BoxDecoration(
color: colorScheme.primary,
borderRadius: BorderRadius.circular(12),
),
child: Center(
child: Text(
number,
style: const TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
),
),
const SizedBox(width: 12),
Expanded(
child: Text(
text,
style: theme.textTheme.bodyMedium?.copyWith(
color: colorScheme.onSurfaceVariant,
),
),
),
],
);
}
void _showHelpDialog(BuildContext context, ColorScheme colorScheme) {
showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: Theme.of(context).cardColor,
title: Row(
children: [
Icon(Icons.help_outline, color: colorScheme.primary),
const SizedBox(width: 8),
Text(
'Ajuda - Código da Turma',
style: TextStyle(color: colorScheme.onSurface),
),
],
),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'O código da turma é um código único de 6 caracteres que o teu professor cria para cada turma.',
style: TextStyle(color: colorScheme.onSurfaceVariant),
),
const SizedBox(height: 12),
Text(
'Se não tens o código, contacta o teu professor.',
style: TextStyle(color: colorScheme.onSurfaceVariant),
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(
'Entendido',
style: TextStyle(color: colorScheme.primary),
),
),
],
),
); );
} }
} }

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import '../../../../core/services/auth_service.dart'; import '../../../../core/services/auth_service.dart';
import '../../../../core/theme/app_theme_extension.dart'; import '../../../../core/theme/app_theme_extension.dart';
import '../../../../core/routing/app_router.dart';
import '../widgets/progress_hero_widget.dart'; import '../widgets/progress_hero_widget.dart';
import '../widgets/quick_access_widget.dart'; import '../widgets/quick_access_widget.dart';
import '../widgets/student_classes_list_widget.dart'; import '../widgets/student_classes_list_widget.dart';
@@ -104,7 +105,7 @@ class _StudentDashboardPageState extends State<StudentDashboardPage> {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Header with logout // Header with logout and settings
Row( Row(
children: [ children: [
Expanded( Expanded(
@@ -131,6 +132,13 @@ class _StudentDashboardPageState extends State<StudentDashboardPage> {
], ],
), ),
), ),
IconButton(
icon: Icon(Icons.settings, color: headerColor),
onPressed: () {
AppRouter.goToSettings(context);
},
tooltip: 'Configurações',
),
IconButton( IconButton(
icon: Icon(Icons.logout, color: headerColor), icon: Icon(Icons.logout, color: headerColor),
onPressed: () async { onPressed: () async {

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import '../../../../core/services/auth_service.dart'; import '../../../../core/services/auth_service.dart';
import '../../../../core/theme/app_theme_extension.dart'; import '../../../../core/theme/app_theme_extension.dart';
import '../../../../core/routing/app_router.dart';
import '../widgets/teacher_hero_widget.dart'; import '../widgets/teacher_hero_widget.dart';
import '../widgets/teacher_quick_actions_widget.dart'; import '../widgets/teacher_quick_actions_widget.dart';
import '../widgets/teacher_classes_list_widget.dart'; import '../widgets/teacher_classes_list_widget.dart';
@@ -100,7 +101,7 @@ class _TeacherDashboardPageState extends State<TeacherDashboardPage> {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Header with logout // Header with logout and settings
Row( Row(
children: [ children: [
Expanded( Expanded(
@@ -127,6 +128,13 @@ class _TeacherDashboardPageState extends State<TeacherDashboardPage> {
], ],
), ),
), ),
IconButton(
icon: Icon(Icons.settings, color: headerColor),
onPressed: () {
AppRouter.goToSettings(context);
},
tooltip: 'Configurações',
),
IconButton( IconButton(
icon: Icon(Icons.logout, color: headerColor), icon: Icon(Icons.logout, color: headerColor),
onPressed: () async { onPressed: () async {

View File

@@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import '../../../../core/theme/app_theme_extension.dart'; import '../../../../core/theme/app_theme_extension.dart';
import 'package:flutter_animate/flutter_animate.dart'; import 'package:flutter_animate/flutter_animate.dart';
import '../../../../core/services/auth_service.dart'; import '../../../../core/services/auth_service.dart';
import '../../../../core/routing/app_router.dart';
/// Profile section with user info and achievements /// Profile section with user info and achievements
class ProfileSectionWidget extends StatelessWidget { class ProfileSectionWidget extends StatelessWidget {
@@ -100,25 +99,6 @@ class ProfileSectionWidget extends StatelessWidget {
], ],
), ),
), ),
GestureDetector(
onTap: () {
AppRouter.goToSettings(context);
},
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(
context,
).colorScheme.secondary.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child: Icon(
Icons.settings,
color: Theme.of(context).colorScheme.secondary,
size: 20,
),
),
),
], ],
), ),
const SizedBox(height: 20), const SizedBox(height: 20),

View File

@@ -99,20 +99,6 @@ class TeacherAnalyticsPreviewWidget extends StatelessWidget {
], ],
), ),
), ),
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(
context,
).colorScheme.secondary.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child: Icon(
Icons.settings,
color: Theme.of(context).colorScheme.secondary,
size: 20,
),
),
], ],
), ),
const SizedBox(height: 20), const SizedBox(height: 20),

View File

@@ -45,13 +45,20 @@ class _QuizListPageState extends State<QuizListPage>
Future<void> _loadMaterials() async { Future<void> _loadMaterials() async {
final mats = await MaterialsRAGService.getAvailableMaterialsForStudent(); final mats = await MaterialsRAGService.getAvailableMaterialsForStudent();
if (mounted) setState(() { _materials = mats; _loadingMaterials = false; }); if (mounted)
setState(() {
_materials = mats;
_loadingMaterials = false;
});
} }
Future<void> _loadTeacherQuizzes() async { Future<void> _loadTeacherQuizzes() async {
try { try {
final uid = FirebaseAuth.instance.currentUser?.uid; final uid = FirebaseAuth.instance.currentUser?.uid;
if (uid == null) { if (mounted) setState(() => _loadingTeacherQuizzes = false); return; } if (uid == null) {
if (mounted) setState(() => _loadingTeacherQuizzes = false);
return;
}
// Obter teacherIds dos professores do aluno // Obter teacherIds dos professores do aluno
final enrollSnap = await FirebaseFirestore.instance final enrollSnap = await FirebaseFirestore.instance
@@ -70,11 +77,19 @@ class _QuizListPageState extends State<QuizListPage>
final classIdList = classIds.toList(); final classIdList = classIds.toList();
final batches = <Future<QuerySnapshot>>[]; final batches = <Future<QuerySnapshot>>[];
for (int i = 0; i < classIdList.length; i += 10) { for (int i = 0; i < classIdList.length; i += 10) {
batches.add(FirebaseFirestore.instance batches.add(
FirebaseFirestore.instance
.collection('teacherQuizzes') .collection('teacherQuizzes')
.where('classIds', arrayContainsAny: classIdList.sublist(i, (i + 10).clamp(0, classIdList.length))) .where(
'classIds',
arrayContainsAny: classIdList.sublist(
i,
(i + 10).clamp(0, classIdList.length),
),
)
.orderBy('createdAt', descending: true) .orderBy('createdAt', descending: true)
.get()); .get(),
);
} }
final results = await Future.wait(batches); final results = await Future.wait(batches);
// deduplicar por id (pode aparecer em múltiplos batches) // deduplicar por id (pode aparecer em múltiplos batches)
@@ -84,7 +99,11 @@ class _QuizListPageState extends State<QuizListPage>
.where((d) => seen.add(d.id)) .where((d) => seen.add(d.id))
.map((d) => {'id': d.id, ...d.data() as Map<String, dynamic>}) .map((d) => {'id': d.id, ...d.data() as Map<String, dynamic>})
.toList(); .toList();
if (mounted) setState(() { _teacherQuizzes = quizzes; _loadingTeacherQuizzes = false; }); if (mounted)
setState(() {
_teacherQuizzes = quizzes;
_loadingTeacherQuizzes = false;
});
} catch (e) { } catch (e) {
Logger.error('Error loading teacher quizzes: $e'); Logger.error('Error loading teacher quizzes: $e');
if (mounted) setState(() => _loadingTeacherQuizzes = false); if (mounted) setState(() => _loadingTeacherQuizzes = false);
@@ -94,7 +113,10 @@ class _QuizListPageState extends State<QuizListPage>
Future<void> _loadHistory() async { Future<void> _loadHistory() async {
try { try {
final uid = FirebaseAuth.instance.currentUser?.uid; final uid = FirebaseAuth.instance.currentUser?.uid;
if (uid == null) { if (mounted) setState(() => _loadingHistory = false); return; } if (uid == null) {
if (mounted) setState(() => _loadingHistory = false);
return;
}
final snap = await FirebaseFirestore.instance final snap = await FirebaseFirestore.instance
.collection('quizHistory') .collection('quizHistory')
.doc(uid) .doc(uid)
@@ -103,7 +125,11 @@ class _QuizListPageState extends State<QuizListPage>
.limit(30) .limit(30)
.get(); .get();
final list = snap.docs.map((d) => {'id': d.id, ...d.data()}).toList(); final list = snap.docs.map((d) => {'id': d.id, ...d.data()}).toList();
if (mounted) setState(() { _history = list; _loadingHistory = false; }); if (mounted)
setState(() {
_history = list;
_loadingHistory = false;
});
} catch (e) { } catch (e) {
Logger.error('Error loading quiz history: $e'); Logger.error('Error loading quiz history: $e');
if (mounted) setState(() => _loadingHistory = false); if (mounted) setState(() => _loadingHistory = false);
@@ -141,7 +167,8 @@ class _QuizListPageState extends State<QuizListPage>
final questions = _parseQuizJson(raw); final questions = _parseQuizJson(raw);
if (questions.isEmpty) { if (questions.isEmpty) {
if (mounted) _showSnack('Não foi possível gerar o quiz. Tenta novamente.'); if (mounted)
_showSnack('Não foi possível gerar o quiz. Tenta novamente.');
return; return;
} }
@@ -171,7 +198,8 @@ class _QuizListPageState extends State<QuizListPage>
} }
Widget _buildTeacherQuizzesTab(ColorScheme cs) { Widget _buildTeacherQuizzesTab(ColorScheme cs) {
if (_loadingTeacherQuizzes) return const Center(child: CircularProgressIndicator()); if (_loadingTeacherQuizzes)
return const Center(child: CircularProgressIndicator());
if (_teacherQuizzes.isEmpty) { if (_teacherQuizzes.isEmpty) {
return Center( return Center(
child: Padding( child: Padding(
@@ -179,15 +207,26 @@ class _QuizListPageState extends State<QuizListPage>
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Icon(Icons.school_outlined, size: 64, color: cs.onSurfaceVariant.withValues(alpha: 0.4)), Icon(
Icons.school_outlined,
size: 64,
color: cs.onSurfaceVariant.withValues(alpha: 0.4),
),
const SizedBox(height: 16), const SizedBox(height: 16),
Text('Sem quizzes do professor disponíveis.', Text(
'Sem quizzes do professor disponíveis.',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 16)), style: TextStyle(color: cs.onSurfaceVariant, fontSize: 16),
),
const SizedBox(height: 8), const SizedBox(height: 8),
Text('O teu professor ainda não publicou quizzes.', Text(
'O teu professor ainda não publicou quizzes.',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle(color: cs.onSurfaceVariant.withValues(alpha: 0.7), fontSize: 13)), style: TextStyle(
color: cs.onSurfaceVariant.withValues(alpha: 0.7),
fontSize: 13,
),
),
], ],
), ),
), ),
@@ -206,17 +245,27 @@ class _QuizListPageState extends State<QuizListPage>
String dateStr = ''; String dateStr = '';
if (ts is Timestamp) { if (ts is Timestamp) {
final dt = ts.toDate(); final dt = ts.toDate();
dateStr = '${dt.day.toString().padLeft(2, '0')}/${dt.month.toString().padLeft(2, '0')}/${dt.year}'; dateStr =
'${dt.day.toString().padLeft(2, '0')}/${dt.month.toString().padLeft(2, '0')}/${dt.year}';
} }
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: cs.surface, color: cs.surface,
borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
border: Border.all(color: cs.outline.withValues(alpha: 0.15)), border: Border.all(color: cs.outline.withValues(alpha: 0.15)),
boxShadow: [BoxShadow(color: cs.shadow.withValues(alpha: 0.05), blurRadius: 8, offset: const Offset(0, 2))], boxShadow: [
BoxShadow(
color: cs.shadow.withValues(alpha: 0.05),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
), ),
child: ListTile( child: ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
leading: Container( leading: Container(
width: 44, width: 44,
height: 44, height: 44,
@@ -226,14 +275,27 @@ class _QuizListPageState extends State<QuizListPage>
), ),
child: Icon(Icons.school, color: cs.secondary, size: 22), child: Icon(Icons.school, color: cs.secondary, size: 22),
), ),
title: Text(name, title: Text(
name,
maxLines: 2, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 14, color: cs.onSurface)), style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 14,
color: cs.onSurface,
),
),
subtitle: dateStr.isNotEmpty subtitle: dateStr.isNotEmpty
? Text('Publicado em $dateStr', style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant)) ? Text(
'Publicado em $dateStr',
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant),
)
: null, : null,
trailing: Icon(Icons.play_circle_outline, color: cs.secondary, size: 28), trailing: Icon(
Icons.play_circle_outline,
color: cs.secondary,
size: 28,
),
onTap: () => _showTeacherQuiz(quiz), onTap: () => _showTeacherQuiz(quiz),
), ),
); );
@@ -275,7 +337,8 @@ class _QuizListPageState extends State<QuizListPage>
final jsonStr = raw.substring(start, end + 1); final jsonStr = raw.substring(start, end + 1);
final decoded = _jsonDecode(jsonStr); final decoded = _jsonDecode(jsonStr);
if (decoded is! List) return []; if (decoded is! List) return [];
return decoded.map<_QuizQuestion?>((e) { return decoded
.map<_QuizQuestion?>((e) {
if (e is! Map) return null; if (e is! Map) return null;
final q = e['q'] as String?; final q = e['q'] as String?;
final opts = (e['opts'] as List?)?.cast<String>(); final opts = (e['opts'] as List?)?.cast<String>();
@@ -283,8 +346,15 @@ class _QuizListPageState extends State<QuizListPage>
final exp = e['exp'] as String? ?? ''; final exp = e['exp'] as String? ?? '';
if (q == null || opts == null || ans == null) return null; if (q == null || opts == null || ans == null) return null;
if (opts.length < 2 || ans < 0 || ans >= opts.length) return null; if (opts.length < 2 || ans < 0 || ans >= opts.length) return null;
return _QuizQuestion(question: q, options: opts, correctIndex: ans, explanation: exp); return _QuizQuestion(
}).whereType<_QuizQuestion>().toList(); question: q,
options: opts,
correctIndex: ans,
explanation: exp,
);
})
.whereType<_QuizQuestion>()
.toList();
} catch (e) { } catch (e) {
Logger.error('Quiz JSON parse error: $e'); Logger.error('Quiz JSON parse error: $e');
return []; return [];
@@ -373,7 +443,11 @@ class _QuizListPageState extends State<QuizListPage>
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Icon(Icons.folder_open, size: 64, color: cs.onSurfaceVariant.withOpacity(0.4)), Icon(
Icons.folder_open,
size: 64,
color: cs.onSurfaceVariant.withOpacity(0.4),
),
const SizedBox(height: 16), const SizedBox(height: 16),
Text( Text(
'Nenhum material disponível.', 'Nenhum material disponível.',
@@ -384,7 +458,10 @@ class _QuizListPageState extends State<QuizListPage>
Text( Text(
'Inscreve-te numa turma para aceder aos PDFs do professor.', 'Inscreve-te numa turma para aceder aos PDFs do professor.',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle(color: cs.onSurfaceVariant.withOpacity(0.7), fontSize: 13), style: TextStyle(
color: cs.onSurfaceVariant.withOpacity(0.7),
fontSize: 13,
),
), ),
], ],
), ),
@@ -413,7 +490,10 @@ class _QuizListPageState extends State<QuizListPage>
], ],
), ),
child: ListTile( child: ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
leading: Container( leading: Container(
width: 44, width: 44,
height: 44, height: 44,
@@ -465,7 +545,11 @@ class _QuizListPageState extends State<QuizListPage>
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Icon(Icons.history, size: 64, color: cs.onSurfaceVariant.withOpacity(0.4)), Icon(
Icons.history,
size: 64,
color: cs.onSurfaceVariant.withOpacity(0.4),
),
const SizedBox(height: 16), const SizedBox(height: 16),
Text( Text(
'Ainda não geraste nenhum quiz.', 'Ainda não geraste nenhum quiz.',
@@ -490,7 +574,8 @@ class _QuizListPageState extends State<QuizListPage>
String dateStr = ''; String dateStr = '';
if (ts is Timestamp) { if (ts is Timestamp) {
final dt = ts.toDate(); final dt = ts.toDate();
dateStr = '${dt.day.toString().padLeft(2, '0')}/${dt.month.toString().padLeft(2, '0')}/${dt.year} ${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}'; dateStr =
'${dt.day.toString().padLeft(2, '0')}/${dt.month.toString().padLeft(2, '0')}/${dt.year} ${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}';
} }
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
@@ -506,7 +591,10 @@ class _QuizListPageState extends State<QuizListPage>
], ],
), ),
child: ListTile( child: ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
leading: Container( leading: Container(
width: 44, width: 44,
height: 44, height: 44,
@@ -527,10 +615,16 @@ class _QuizListPageState extends State<QuizListPage>
), ),
), ),
subtitle: dateStr.isNotEmpty subtitle: dateStr.isNotEmpty
? Text(dateStr, style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant)) ? Text(
dateStr,
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant),
)
: null, : null,
trailing: Icon(Icons.chevron_right, color: cs.onSurfaceVariant), trailing: Icon(Icons.chevron_right, color: cs.onSurfaceVariant),
onTap: () => _showQuizFromHistory(matName, item['quizJson'] as String? ?? item['quizText'] as String? ?? ''), onTap: () => _showQuizFromHistory(
matName,
item['quizJson'] as String? ?? item['quizText'] as String? ?? '',
),
), ),
); );
}, },
@@ -584,14 +678,19 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
void _next() { void _next() {
if (_current < widget.questions.length - 1) { if (_current < widget.questions.length - 1) {
setState(() { _current++; }); setState(() {
_current++;
});
} else { } else {
setState(() => _submitted = true); setState(() => _submitted = true);
} }
} }
void _prev() { void _prev() {
if (_current > 0) setState(() { _current--; }); if (_current > 0)
setState(() {
_current--;
});
} }
int get _score => List.generate(widget.questions.length, (i) { int get _score => List.generate(widget.questions.length, (i) {
@@ -648,7 +747,11 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
widget.title, widget.title,
maxLines: 2, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold, color: cs.onSurface), style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: cs.onSurface,
),
), ),
if (!_submitted) if (!_submitted)
Text( Text(
@@ -687,7 +790,12 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
// Pergunta // Pergunta
Text( Text(
q.question, q.question,
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: cs.onSurface, height: 1.4), style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: cs.onSurface,
height: 1.4,
),
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
// Opções // Opções
@@ -700,12 +808,19 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
onTap: () => _selectOption(i), onTap: () => _selectOption(i),
child: AnimatedContainer( child: AnimatedContainer(
duration: const Duration(milliseconds: 150), duration: const Duration(milliseconds: 150),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14), padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 14,
),
decoration: BoxDecoration( decoration: BoxDecoration(
color: isSelected ? cs.primary.withOpacity(0.12) : cs.surfaceVariant.withOpacity(0.4), color: isSelected
? cs.primary.withOpacity(0.12)
: cs.surfaceVariant.withOpacity(0.4),
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
border: Border.all( border: Border.all(
color: isSelected ? cs.primary : cs.outline.withOpacity(0.2), color: isSelected
? cs.primary
: cs.outline.withOpacity(0.2),
width: isSelected ? 2 : 1, width: isSelected ? 2 : 1,
), ),
), ),
@@ -717,11 +832,14 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
style: TextStyle( style: TextStyle(
fontSize: 14, fontSize: 14,
color: isSelected ? cs.primary : cs.onSurface, color: isSelected ? cs.primary : cs.onSurface,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal, fontWeight: isSelected
? FontWeight.w600
: FontWeight.normal,
), ),
), ),
), ),
if (isSelected) Icon(Icons.check_circle, color: cs.primary, size: 20), if (isSelected)
Icon(Icons.check_circle, color: cs.primary, size: 20),
], ],
), ),
), ),
@@ -738,7 +856,9 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
onPressed: _prev, onPressed: _prev,
style: OutlinedButton.styleFrom( style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 14), padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
), ),
child: const Text('Anterior'), child: const Text('Anterior'),
), ),
@@ -751,9 +871,15 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
backgroundColor: cs.primary, backgroundColor: cs.primary,
foregroundColor: cs.onPrimary, foregroundColor: cs.onPrimary,
padding: const EdgeInsets.symmetric(vertical: 14), padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
_current < widget.questions.length - 1
? 'Próxima'
: 'Submeter',
), ),
child: Text(_current < widget.questions.length - 1 ? 'Próxima' : 'Submeter'),
), ),
), ),
], ],
@@ -788,7 +914,11 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
children: [ children: [
Text( Text(
'$score / $total', '$score / $total',
style: TextStyle(fontSize: 40, fontWeight: FontWeight.bold, color: scoreColor), style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
color: scoreColor,
),
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
Text( Text(
@@ -801,7 +931,11 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
const SizedBox(height: 24), const SizedBox(height: 24),
Text( Text(
'Revisão', 'Revisão',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: cs.onSurface), style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: cs.onSurface,
),
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
// Revisão pergunta a pergunta // Revisão pergunta a pergunta
@@ -809,7 +943,9 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
final q = widget.questions[i]; final q = widget.questions[i];
final chosen = _chosen[i]; final chosen = _chosen[i];
final isCorrect = chosen == q.correctIndex; final isCorrect = chosen == q.correctIndex;
final revColor = isCorrect ? const Color(0xFF10B981) : const Color(0xFFEF4444); final revColor = isCorrect
? const Color(0xFF10B981)
: const Color(0xFFEF4444);
return Container( return Container(
margin: const EdgeInsets.only(bottom: 16), margin: const EdgeInsets.only(bottom: 16),
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
@@ -823,27 +959,49 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
children: [ children: [
Row( Row(
children: [ children: [
Icon(isCorrect ? Icons.check_circle : Icons.cancel, color: revColor, size: 18), Icon(
isCorrect ? Icons.check_circle : Icons.cancel,
color: revColor,
size: 18,
),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: Text( child: Text(
'Pergunta ${i + 1}', 'Pergunta ${i + 1}',
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: revColor), style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: revColor,
),
), ),
), ),
], ],
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
Text(q.question, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: cs.onSurface)), Text(
q.question,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: cs.onSurface,
),
),
const SizedBox(height: 8), const SizedBox(height: 8),
if (chosen >= 0 && chosen < q.options.length && !isCorrect) if (chosen >= 0 && chosen < q.options.length && !isCorrect)
Text( Text(
'A tua resposta: ${q.options[chosen]}', 'A tua resposta: ${q.options[chosen]}',
style: const TextStyle(fontSize: 13, color: Color(0xFFEF4444)), style: const TextStyle(
fontSize: 13,
color: Color(0xFFEF4444),
),
), ),
Text( Text(
'Resposta correcta: ${q.options[q.correctIndex]}', 'Resposta correcta: ${q.options[q.correctIndex]}',
style: TextStyle(fontSize: 13, color: isCorrect ? const Color(0xFF10B981) : cs.onSurface, fontWeight: FontWeight.w500), style: TextStyle(
fontSize: 13,
color: isCorrect ? const Color(0xFF10B981) : cs.onSurface,
fontWeight: FontWeight.w500,
),
), ),
if (q.explanation.isNotEmpty) ...[ if (q.explanation.isNotEmpty) ...[
const SizedBox(height: 8), const SizedBox(height: 8),
@@ -856,12 +1014,20 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Icon(Icons.info_outline, size: 14, color: cs.onSurfaceVariant), Icon(
Icons.info_outline,
size: 14,
color: cs.onSurfaceVariant,
),
const SizedBox(width: 6), const SizedBox(width: 6),
Expanded( Expanded(
child: Text( child: Text(
q.explanation, q.explanation,
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant, height: 1.4), style: TextStyle(
fontSize: 12,
color: cs.onSurfaceVariant,
height: 1.4,
),
), ),
), ),
], ],
@@ -879,7 +1045,9 @@ class _InteractiveQuizSheetState extends State<_InteractiveQuizSheet> {
backgroundColor: cs.primary, backgroundColor: cs.primary,
foregroundColor: cs.onPrimary, foregroundColor: cs.onPrimary,
padding: const EdgeInsets.symmetric(vertical: 14), padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
), ),
child: const Text('Fechar'), child: const Text('Fechar'),
), ),
@@ -901,10 +1069,12 @@ class _TeacherQuizInteractiveSheet extends StatefulWidget {
}); });
@override @override
State<_TeacherQuizInteractiveSheet> createState() => _TeacherQuizInteractiveSheetState(); State<_TeacherQuizInteractiveSheet> createState() =>
_TeacherQuizInteractiveSheetState();
} }
class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveSheet> { class _TeacherQuizInteractiveSheetState
extends State<_TeacherQuizInteractiveSheet> {
int _current = 0; int _current = 0;
late List<int> _chosen; late List<int> _chosen;
bool _submitted = false; bool _submitted = false;
@@ -933,11 +1103,16 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
if (_current > 0) setState(() => _current--); if (_current > 0) setState(() => _current--);
} }
int get _score => List.generate(widget.questions.length, int get _score => List.generate(
(i) => _chosen[i] == widget.questions[i].correctIndex ? 1 : 0).fold(0, (a, b) => a + b); widget.questions.length,
(i) => _chosen[i] == widget.questions[i].correctIndex ? 1 : 0,
).fold(0, (a, b) => a + b);
Future<void> _submit() async { Future<void> _submit() async {
setState(() { _submitted = true; _saving = true; }); setState(() {
_submitted = true;
_saving = true;
});
try { try {
final user = FirebaseAuth.instance.currentUser; final user = FirebaseAuth.instance.currentUser;
if (user != null) { if (user != null) {
@@ -948,7 +1123,8 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
.doc(user.uid) // 1 submissão por aluno (sobrescreve) .doc(user.uid) // 1 submissão por aluno (sobrescreve)
.set({ .set({
'studentId': user.uid, 'studentId': user.uid,
'studentName': user.displayName ?? user.email?.split('@')[0] ?? 'Aluno', 'studentName':
user.displayName ?? user.email?.split('@')[0] ?? 'Aluno',
'score': _score, 'score': _score,
'total': widget.questions.length, 'total': widget.questions.length,
'submittedAt': FieldValue.serverTimestamp(), 'submittedAt': FieldValue.serverTimestamp(),
@@ -978,7 +1154,8 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
// Handle // Handle
Container( Container(
margin: const EdgeInsets.only(top: 12, bottom: 4), margin: const EdgeInsets.only(top: 12, bottom: 4),
width: 40, height: 4, width: 40,
height: 4,
decoration: BoxDecoration( decoration: BoxDecoration(
color: cs.outline.withValues(alpha: 0.3), color: cs.outline.withValues(alpha: 0.3),
borderRadius: BorderRadius.circular(2), borderRadius: BorderRadius.circular(2),
@@ -993,18 +1170,33 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text(widget.title, Text(
widget.title,
maxLines: 2, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold, color: cs.onSurface)), style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: cs.onSurface,
),
),
if (!_submitted) if (!_submitted)
Text('Pergunta ${_current + 1} de ${widget.questions.length}', Text(
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant)), 'Pergunta ${_current + 1} de ${widget.questions.length}',
style: TextStyle(
fontSize: 12,
color: cs.onSurfaceVariant,
),
),
], ],
), ),
), ),
if (_saving) if (_saving)
const SizedBox(width: 24, height: 24, child: CircularProgressIndicator(strokeWidth: 2)) const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(strokeWidth: 2),
)
else else
IconButton( IconButton(
icon: Icon(Icons.close, color: cs.onSurfaceVariant), icon: Icon(Icons.close, color: cs.onSurfaceVariant),
@@ -1042,8 +1234,15 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
), ),
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
Text(q.question, Text(
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: cs.onSurface, height: 1.4)), q.question,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: cs.onSurface,
height: 1.4,
),
),
const SizedBox(height: 20), const SizedBox(height: 20),
...List.generate(q.options.length, (i) { ...List.generate(q.options.length, (i) {
final isSelected = chosen == i; final isSelected = chosen == i;
@@ -1054,26 +1253,38 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
onTap: () => _selectOption(i), onTap: () => _selectOption(i),
child: AnimatedContainer( child: AnimatedContainer(
duration: const Duration(milliseconds: 150), duration: const Duration(milliseconds: 150),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14), padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 14,
),
decoration: BoxDecoration( decoration: BoxDecoration(
color: isSelected ? cs.secondary.withValues(alpha: 0.12) : cs.surfaceContainerHighest.withValues(alpha: 0.4), color: isSelected
? cs.secondary.withValues(alpha: 0.12)
: cs.surfaceContainerHighest.withValues(alpha: 0.4),
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
border: Border.all( border: Border.all(
color: isSelected ? cs.secondary : cs.outline.withValues(alpha: 0.2), color: isSelected
? cs.secondary
: cs.outline.withValues(alpha: 0.2),
width: isSelected ? 2 : 1, width: isSelected ? 2 : 1,
), ),
), ),
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(
child: Text(q.options[i], child: Text(
q.options[i],
style: TextStyle( style: TextStyle(
fontSize: 14, fontSize: 14,
color: isSelected ? cs.secondary : cs.onSurface, color: isSelected ? cs.secondary : cs.onSurface,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal, fontWeight: isSelected
)), ? FontWeight.w600
: FontWeight.normal,
), ),
if (isSelected) Icon(Icons.check_circle, color: cs.secondary, size: 20), ),
),
if (isSelected)
Icon(Icons.check_circle, color: cs.secondary, size: 20),
], ],
), ),
), ),
@@ -1089,7 +1300,9 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
onPressed: _prev, onPressed: _prev,
style: OutlinedButton.styleFrom( style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 14), padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
), ),
child: const Text('Anterior'), child: const Text('Anterior'),
), ),
@@ -1103,9 +1316,15 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
backgroundColor: cs.secondary, backgroundColor: cs.secondary,
foregroundColor: cs.onSecondary, foregroundColor: cs.onSecondary,
padding: const EdgeInsets.symmetric(vertical: 14), padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
_current < widget.questions.length - 1
? 'Próxima'
: 'Submeter',
), ),
child: Text(_current < widget.questions.length - 1 ? 'Próxima' : 'Submeter'),
), ),
), ),
], ],
@@ -1136,25 +1355,44 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
), ),
child: Column( child: Column(
children: [ children: [
Text('$score / $total', Text(
style: TextStyle(fontSize: 40, fontWeight: FontWeight.bold, color: scoreColor)), '$score / $total',
style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
color: scoreColor,
),
),
const SizedBox(height: 4), const SizedBox(height: 4),
Text('$pct% de respostas correctas', Text(
style: TextStyle(fontSize: 14, color: scoreColor)), '$pct% de respostas correctas',
style: TextStyle(fontSize: 14, color: scoreColor),
),
const SizedBox(height: 4), const SizedBox(height: 4),
Text('Resultado enviado ao professor ✓', Text(
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant)), 'Resultado enviado ao professor ✓',
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant),
),
], ],
), ),
), ),
const SizedBox(height: 24), const SizedBox(height: 24),
Text('Revisão', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: cs.onSurface)), Text(
'Revisão',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: cs.onSurface,
),
),
const SizedBox(height: 12), const SizedBox(height: 12),
...List.generate(total, (i) { ...List.generate(total, (i) {
final q = widget.questions[i]; final q = widget.questions[i];
final chosen = _chosen[i]; final chosen = _chosen[i];
final isCorrect = chosen == q.correctIndex; final isCorrect = chosen == q.correctIndex;
final revColor = isCorrect ? const Color(0xFF10B981) : const Color(0xFFEF4444); final revColor = isCorrect
? const Color(0xFF10B981)
: const Color(0xFFEF4444);
return Container( return Container(
margin: const EdgeInsets.only(bottom: 16), margin: const EdgeInsets.only(bottom: 16),
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
@@ -1168,26 +1406,50 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
children: [ children: [
Row( Row(
children: [ children: [
Icon(isCorrect ? Icons.check_circle : Icons.cancel, color: revColor, size: 18), Icon(
isCorrect ? Icons.check_circle : Icons.cancel,
color: revColor,
size: 18,
),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: Text('Pergunta ${i + 1}', child: Text(
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: revColor)), 'Pergunta ${i + 1}',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: revColor,
),
),
), ),
], ],
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
Text(q.question, Text(
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: cs.onSurface)), q.question,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: cs.onSurface,
),
),
const SizedBox(height: 8), const SizedBox(height: 8),
if (chosen >= 0 && chosen < q.options.length && !isCorrect) if (chosen >= 0 && chosen < q.options.length && !isCorrect)
Text('A tua resposta: ${q.options[chosen]}', Text(
style: const TextStyle(fontSize: 13, color: Color(0xFFEF4444))), 'A tua resposta: ${q.options[chosen]}',
Text('Resposta correcta: ${q.options[q.correctIndex]}', style: const TextStyle(
fontSize: 13,
color: Color(0xFFEF4444),
),
),
Text(
'Resposta correcta: ${q.options[q.correctIndex]}',
style: TextStyle( style: TextStyle(
fontSize: 13, fontSize: 13,
color: isCorrect ? const Color(0xFF10B981) : cs.onSurface, color: isCorrect ? const Color(0xFF10B981) : cs.onSurface,
fontWeight: FontWeight.w500)), fontWeight: FontWeight.w500,
),
),
if (q.explanation.isNotEmpty) ...[ if (q.explanation.isNotEmpty) ...[
const SizedBox(height: 8), const SizedBox(height: 8),
Container( Container(
@@ -1199,11 +1461,21 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Icon(Icons.info_outline, size: 14, color: cs.onSurfaceVariant), Icon(
Icons.info_outline,
size: 14,
color: cs.onSurfaceVariant,
),
const SizedBox(width: 6), const SizedBox(width: 6),
Expanded( Expanded(
child: Text(q.explanation, child: Text(
style: TextStyle(fontSize: 12, color: cs.onSurfaceVariant, height: 1.4)), q.explanation,
style: TextStyle(
fontSize: 12,
color: cs.onSurfaceVariant,
height: 1.4,
),
),
), ),
], ],
), ),
@@ -1219,7 +1491,9 @@ class _TeacherQuizInteractiveSheetState extends State<_TeacherQuizInteractiveShe
backgroundColor: cs.secondary, backgroundColor: cs.secondary,
foregroundColor: cs.onSecondary, foregroundColor: cs.onSecondary,
padding: const EdgeInsets.symmetric(vertical: 14), padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
), ),
child: const Text('Fechar'), child: const Text('Fechar'),
), ),

View File

@@ -5,6 +5,7 @@ import '../../../../core/theme/app_colors.dart';
import '../../../../core/theme/app_theme_extension.dart'; import '../../../../core/theme/app_theme_extension.dart';
import '../../../../core/services/theme_service.dart'; import '../../../../core/services/theme_service.dart';
import '../../../../core/providers/theme_provider.dart'; import '../../../../core/providers/theme_provider.dart';
import '../../../../core/services/auth_service.dart';
/// Settings page for app configuration /// Settings page for app configuration
class SettingsPage extends ConsumerStatefulWidget { class SettingsPage extends ConsumerStatefulWidget {
@@ -22,11 +23,21 @@ class _SettingsPageState extends ConsumerState<SettingsPage> {
return PopScope( return PopScope(
canPop: false, canPop: false,
onPopInvokedWithResult: (didPop, result) { onPopInvokedWithResult: (didPop, result) async {
if (!didPop) { if (!didPop) {
// Navigate to student dashboard on back button // Navigate to appropriate dashboard based on user role
final user = AuthService.currentUser;
if (user != null) {
final role = await AuthService.getUserRole(user.uid);
if (role == 'teacher') {
context.go('/teacher-dashboard');
} else {
context.go('/student-dashboard'); context.go('/student-dashboard');
} }
} else {
context.go('/student-dashboard');
}
}
}, },
child: Scaffold( child: Scaffold(
body: Container( body: Container(
@@ -56,7 +67,22 @@ class _SettingsPageState extends ConsumerState<SettingsPage> {
Icons.arrow_back, Icons.arrow_back,
color: Theme.of(context).colorScheme.onSurface, color: Theme.of(context).colorScheme.onSurface,
), ),
onPressed: () => context.go('/student-dashboard'), onPressed: () async {
// Navigate to appropriate dashboard based on user role
final user = AuthService.currentUser;
if (user != null) {
final role = await AuthService.getUserRole(
user.uid,
);
if (role == 'teacher') {
context.go('/teacher-dashboard');
} else {
context.go('/student-dashboard');
}
} else {
context.go('/student-dashboard');
}
},
), ),
Expanded( Expanded(
child: Text( child: Text(