Modificações no chatbot (dashboard aluno) e analytics (dashboard stor)
This commit is contained in:
@@ -328,7 +328,7 @@ class _TutorChatPageState extends State<TutorChatPage>
|
||||
void _addWelcomeMessage() {
|
||||
final welcomeMessage = {
|
||||
'content':
|
||||
'''**Olá! Sou a Alt, o teu Assistente IA oficial do Teach it.**
|
||||
'''**Olá! Sou o Vico, o teu Assistente IA oficial do Teach it.**
|
||||
|
||||
Estou aqui para te ajudar a aprender de forma confiante e motivadora!
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@ import '../../../../core/services/gamification_service.dart';
|
||||
import '../../../../core/models/class_stats.dart';
|
||||
import '../../../../core/models/achievement.dart';
|
||||
import '../widgets/class_analytics_card.dart';
|
||||
import '../widgets/class_ranking_widget.dart';
|
||||
import '../widgets/class_students_inline_widget.dart';
|
||||
import '../widgets/create_achievement_dialog.dart';
|
||||
|
||||
/// Analytics page for teachers with class breakdowns and rankings
|
||||
@@ -26,6 +26,7 @@ class _AnalyticsPageState extends State<AnalyticsPage>
|
||||
List<ClassStats> _classStats = [];
|
||||
bool _loading = true;
|
||||
String? _selectedClassId;
|
||||
String? _selectedClassName;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -86,89 +87,99 @@ class _AnalyticsPageState extends State<AnalyticsPage>
|
||||
final themeExtras = AppThemeExtras.of(context);
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: cs.surface,
|
||||
body: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: themeExtras.dashboardBackgroundGradient,
|
||||
stops: themeExtras.dashboardGradientStops,
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvoked: (didPop) {
|
||||
if (didPop) return;
|
||||
context.go('/teacher-dashboard');
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: cs.surface,
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: themeExtras.dashboardBackgroundGradient,
|
||||
stops: themeExtras.dashboardGradientStops,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
// Header
|
||||
Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.arrow_back,
|
||||
color: Colors.white,
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
// Header
|
||||
Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.arrow_back,
|
||||
color: Colors.white,
|
||||
),
|
||||
onPressed: () => context.go('/teacher-dashboard'),
|
||||
),
|
||||
onPressed: () => context.go('/teacher-dashboard'),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Analytics',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Analytics',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'Acompanhe o desempenho das disciplinas',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.8),
|
||||
fontSize: 16,
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'Acompanhe o desempenho das disciplinas',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.8),
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add, color: Colors.white),
|
||||
onPressed: _showCreateAchievementDialog,
|
||||
tooltip: 'Criar Conquista',
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TabBar(
|
||||
controller: _tabController,
|
||||
labelColor: Colors.white,
|
||||
unselectedLabelColor: Colors.white.withValues(
|
||||
alpha: 0.7,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add, color: Colors.white),
|
||||
onPressed: _showCreateAchievementDialog,
|
||||
tooltip: 'Criar Conquista',
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TabBar(
|
||||
controller: _tabController,
|
||||
labelColor: Colors.white,
|
||||
unselectedLabelColor: Colors.white.withValues(alpha: 0.7),
|
||||
indicatorColor: Colors.white,
|
||||
indicatorWeight: 2,
|
||||
tabs: const [
|
||||
Tab(text: 'Disciplinas'),
|
||||
Tab(text: 'Rankings'),
|
||||
],
|
||||
),
|
||||
],
|
||||
indicatorColor: Colors.white,
|
||||
indicatorWeight: 2,
|
||||
tabs: const [
|
||||
Tab(text: 'Disciplinas'),
|
||||
Tab(text: 'Alunos'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Content
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [_buildClassesTab(), _buildRankingsTab()],
|
||||
// Content
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [_buildClassesTab(), _buildStudentsTab()],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -248,7 +259,7 @@ class _AnalyticsPageState extends State<AnalyticsPage>
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
child: ClassAnalyticsCard(
|
||||
classStats: stats,
|
||||
onTap: () => _showClassRanking(stats),
|
||||
onTap: () => _showClassStudents(stats),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -257,20 +268,20 @@ class _AnalyticsPageState extends State<AnalyticsPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRankingsTab() {
|
||||
Widget _buildStudentsTab() {
|
||||
if (_selectedClassId == null) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.leaderboard,
|
||||
Icons.people_outline,
|
||||
size: 64,
|
||||
color: Colors.white.withValues(alpha: 0.5),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Selecione uma disciplina',
|
||||
'Seleciona uma disciplina',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.7),
|
||||
fontSize: 18,
|
||||
@@ -278,18 +289,22 @@ class _AnalyticsPageState extends State<AnalyticsPage>
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Clique em uma disciplina na aba "Disciplinas" para ver o ranking',
|
||||
'Clica numa disciplina no separador "Disciplinas" para ver os alunos',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.5),
|
||||
fontSize: 14,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ClassRankingWidget(classId: _selectedClassId!);
|
||||
return ClassStudentsInlineWidget(
|
||||
classId: _selectedClassId!,
|
||||
className: _selectedClassName ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildOverviewCard(
|
||||
@@ -331,11 +346,12 @@ class _AnalyticsPageState extends State<AnalyticsPage>
|
||||
).animate().scale(duration: 600.ms, curve: Curves.elasticOut);
|
||||
}
|
||||
|
||||
void _showClassRanking(ClassStats stats) {
|
||||
void _showClassStudents(ClassStats stats) {
|
||||
setState(() {
|
||||
_selectedClassId = stats.classId;
|
||||
_selectedClassName = stats.className;
|
||||
});
|
||||
_tabController.animateTo(1); // Mudar para aba de rankings
|
||||
_tabController.animateTo(1);
|
||||
}
|
||||
|
||||
void _showCreateAchievementDialog() {
|
||||
|
||||
@@ -0,0 +1,609 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
/// Inline widget (no Scaffold) showing enrolled students for a class,
|
||||
/// with search, real-time updates, and remove-student functionality.
|
||||
class ClassStudentsInlineWidget extends StatefulWidget {
|
||||
final String classId;
|
||||
final String className;
|
||||
|
||||
const ClassStudentsInlineWidget({
|
||||
super.key,
|
||||
required this.classId,
|
||||
required this.className,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ClassStudentsInlineWidget> createState() =>
|
||||
_ClassStudentsInlineWidgetState();
|
||||
}
|
||||
|
||||
class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
String _searchQuery = '';
|
||||
String? _classCode;
|
||||
late Stream<QuerySnapshot> _enrollmentsStream;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadClassCode();
|
||||
_initStream();
|
||||
}
|
||||
|
||||
void _initStream() {
|
||||
_enrollmentsStream = FirebaseFirestore.instance
|
||||
.collection('enrollments')
|
||||
.where('classId', isEqualTo: widget.classId)
|
||||
.snapshots();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ClassStudentsInlineWidget oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.classId != widget.classId) {
|
||||
_loadClassCode();
|
||||
_initStream();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadClassCode() async {
|
||||
final doc = await FirebaseFirestore.instance
|
||||
.collection('classes')
|
||||
.doc(widget.classId)
|
||||
.get();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_classCode = doc.data()?['code'] as String? ?? '—';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _removeStudent(
|
||||
BuildContext context,
|
||||
String enrollmentDocId,
|
||||
String studentName,
|
||||
) async {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
title: const Text('Remover aluno'),
|
||||
content: Text(
|
||||
'Tens a certeza que queres remover "$studentName" desta disciplina?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(false),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(backgroundColor: cs.error),
|
||||
onPressed: () => Navigator.of(ctx).pop(true),
|
||||
child: const Text('Remover'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed != true) return;
|
||||
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
.collection('enrollments')
|
||||
.doc(enrollmentDocId)
|
||||
.delete();
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context)
|
||||
..clearSnackBars()
|
||||
..showSnackBar(
|
||||
SnackBar(
|
||||
behavior: SnackBarBehavior.floating,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
backgroundColor: cs.primary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
content: Text(
|
||||
'"$studentName" foi removido da disciplina.',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('Erro ao remover aluno: $e')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
return StreamBuilder<QuerySnapshot>(
|
||||
stream: _enrollmentsStream,
|
||||
builder: (context, snapshot) {
|
||||
// Keep showing previous data while new data loads (prevents flash)
|
||||
final docs = snapshot.data?.docs ?? [];
|
||||
// Sort client-side by joinedAt ascending
|
||||
final enrollments = List<QueryDocumentSnapshot>.from(docs)
|
||||
..sort((a, b) {
|
||||
final aData = a.data() as Map<String, dynamic>;
|
||||
final bData = b.data() as Map<String, dynamic>;
|
||||
final aTs = aData['joinedAt'] as Timestamp?;
|
||||
final bTs = bData['joinedAt'] as Timestamp?;
|
||||
if (aTs == null && bTs == null) return 0;
|
||||
if (aTs == null) return 1;
|
||||
if (bTs == null) return -1;
|
||||
return aTs.compareTo(bTs);
|
||||
});
|
||||
final filtered = _searchQuery.isEmpty
|
||||
? enrollments
|
||||
: enrollments.where((doc) {
|
||||
final data = doc.data() as Map<String, dynamic>;
|
||||
final name = (data['studentName'] as String? ?? '')
|
||||
.toLowerCase();
|
||||
final email = (data['studentEmail'] as String? ?? '')
|
||||
.toLowerCase();
|
||||
final q = _searchQuery.toLowerCase();
|
||||
return name.contains(q) || email.contains(q);
|
||||
}).toList();
|
||||
|
||||
final bottomInset = MediaQuery.of(context).viewInsets.bottom;
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: bottomInset),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
children: [
|
||||
// ── Header ──────────────────────────────────────────────────
|
||||
Container(
|
||||
padding: const EdgeInsets.all(18),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [cs.primary, cs.primary.withValues(alpha: 0.8)],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.className,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
snapshot.connectionState ==
|
||||
ConnectionState.waiting
|
||||
? 'A carregar…'
|
||||
: '${enrollments.length} aluno${enrollments.length == 1 ? '' : 's'} inscrito${enrollments.length == 1 ? '' : 's'}',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.85),
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Código da disciplina
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (_classCode != null && _classCode != '—') {
|
||||
Clipboard.setData(ClipboardData(text: _classCode!));
|
||||
ScaffoldMessenger.of(context)
|
||||
..clearSnackBars()
|
||||
..showSnackBar(
|
||||
SnackBar(
|
||||
behavior: SnackBarBehavior.floating,
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 12,
|
||||
),
|
||||
backgroundColor: cs.primary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
duration: const Duration(seconds: 2),
|
||||
content: const Text(
|
||||
'Código copiado!',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
vertical: 10,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.18),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: Colors.white.withValues(alpha: 0.3),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
'Código',
|
||||
style: TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
_classCode ?? '…',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 2,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.copy,
|
||||
color: Colors.white.withValues(alpha: 0.7),
|
||||
size: 10,
|
||||
),
|
||||
const SizedBox(width: 3),
|
||||
Text(
|
||||
'copiar',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(
|
||||
alpha: 0.7,
|
||||
),
|
||||
fontSize: 9,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// ── Search bar ──────────────────────────────────────────────
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
vertical: 10,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: Colors.white.withValues(alpha: 0.2),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.search,
|
||||
color: Colors.white.withValues(alpha: 0.7),
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
onChanged: (v) =>
|
||||
setState(() => _searchQuery = v.trim()),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
),
|
||||
cursorColor: Colors.white,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Pesquisar aluno…',
|
||||
hintStyle: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.5),
|
||||
fontSize: 14,
|
||||
),
|
||||
border: InputBorder.none,
|
||||
isDense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_searchQuery.isNotEmpty)
|
||||
GestureDetector(
|
||||
onTap: () => setState(() => _searchQuery = ''),
|
||||
child: Icon(
|
||||
Icons.close,
|
||||
color: Colors.white.withValues(alpha: 0.7),
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// ── List ────────────────────────────────────────────────────
|
||||
Expanded(
|
||||
child:
|
||||
snapshot.connectionState == ConnectionState.waiting &&
|
||||
snapshot.data == null
|
||||
? const Center(
|
||||
child: CircularProgressIndicator(color: Colors.white),
|
||||
)
|
||||
: filtered.isEmpty
|
||||
? _buildEmpty(cs)
|
||||
: ListView.separated(
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: filtered.length,
|
||||
separatorBuilder: (_, __) =>
|
||||
const SizedBox(height: 10),
|
||||
itemBuilder: (context, index) {
|
||||
final doc = filtered[index];
|
||||
final data = doc.data() as Map<String, dynamic>;
|
||||
final studentName =
|
||||
data['studentName'] as String? ??
|
||||
'Aluno sem nome';
|
||||
final studentEmail =
|
||||
data['studentEmail'] as String? ?? '';
|
||||
final joinedAt = data['joinedAt'] as Timestamp?;
|
||||
final enrollmentDocId = doc.id;
|
||||
|
||||
return _buildStudentCard(
|
||||
cs: cs,
|
||||
enrollmentDocId: enrollmentDocId,
|
||||
studentName: studentName,
|
||||
studentEmail: studentEmail,
|
||||
joinedAt: joinedAt,
|
||||
index: index,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStudentCard({
|
||||
required ColorScheme cs,
|
||||
required String enrollmentDocId,
|
||||
required String studentName,
|
||||
required String studentEmail,
|
||||
required Timestamp? joinedAt,
|
||||
required int index,
|
||||
}) {
|
||||
return Dismissible(
|
||||
key: Key(enrollmentDocId),
|
||||
direction: DismissDirection.endToStart,
|
||||
confirmDismiss: (_) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
title: const Text('Remover aluno'),
|
||||
content: Text(
|
||||
'Tens a certeza que queres remover "$studentName" desta disciplina?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(false),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(backgroundColor: cs.error),
|
||||
onPressed: () => Navigator.of(ctx).pop(true),
|
||||
child: const Text('Remover'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return confirmed ?? false;
|
||||
},
|
||||
onDismissed: (_) async {
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
.collection('enrollments')
|
||||
.doc(enrollmentDocId)
|
||||
.delete();
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context)
|
||||
..clearSnackBars()
|
||||
..showSnackBar(
|
||||
SnackBar(
|
||||
behavior: SnackBarBehavior.floating,
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 12,
|
||||
),
|
||||
backgroundColor: cs.primary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
content: Text(
|
||||
'"$studentName" foi removido da disciplina.',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('Erro ao remover: $e')));
|
||||
}
|
||||
}
|
||||
},
|
||||
background: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: cs.error.withValues(alpha: 0.85),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: 20),
|
||||
child: const Icon(Icons.delete_outline, color: Colors.white, size: 24),
|
||||
),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: Colors.white.withValues(alpha: 0.18)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// Avatar with initial
|
||||
Container(
|
||||
width: 42,
|
||||
height: 42,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
studentName.isNotEmpty ? studentName[0].toUpperCase() : '?',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
// Info
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
studentName,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
if (studentEmail.isNotEmpty) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
studentEmail,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.65),
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
if (joinedAt != null) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'Entrou em ${DateFormat('dd/MM/yyyy').format(joinedAt.toDate())}',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.5),
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
// Remove button
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.person_remove_outlined,
|
||||
color: cs.error.withValues(alpha: 0.85),
|
||||
size: 20,
|
||||
),
|
||||
tooltip: 'Remover aluno',
|
||||
onPressed: () =>
|
||||
_removeStudent(context, enrollmentDocId, studentName),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmpty(ColorScheme cs) {
|
||||
if (_searchQuery.isNotEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.search_off,
|
||||
size: 48,
|
||||
color: Colors.white.withValues(alpha: 0.4),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'Nenhum aluno encontrado',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.7),
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.people_outline,
|
||||
size: 56,
|
||||
color: Colors.white.withValues(alpha: 0.35),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Text(
|
||||
'Nenhum aluno inscrito',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.7),
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'Partilha o código da disciplina com os alunos.',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.45),
|
||||
fontSize: 13,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user