Finalização de detalhes e pequenas adições em dashboards de alunos e professores
This commit is contained in:
@@ -76,7 +76,10 @@ class ClassAnalyticsCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 6,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
@@ -84,7 +87,11 @@ class ClassAnalyticsCard extends StatelessWidget {
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.trending_up, color: Colors.white, size: 16),
|
||||
const Icon(
|
||||
Icons.trending_up,
|
||||
color: Colors.white,
|
||||
size: 16,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'${(classStats.averageProgress * 100).toInt()}%',
|
||||
@@ -190,39 +197,47 @@ class ClassAnalyticsCard extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
...classStats.studentsNeedingSupport.take(3).map((student) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.orange,
|
||||
shape: BoxShape.circle,
|
||||
...classStats.studentsNeedingSupport
|
||||
.take(3)
|
||||
.map(
|
||||
(student) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.orange,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
student.studentName,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(
|
||||
alpha: 0.8,
|
||||
),
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${student.averageScore.toInt()}%',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(
|
||||
alpha: 0.8,
|
||||
),
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
student.studentName,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.8),
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${student.averageScore.toInt()}%',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.8),
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)),
|
||||
),
|
||||
if (classStats.studentsNeedingSupport.length > 3)
|
||||
Text(
|
||||
'+${classStats.studentsNeedingSupport.length - 3} alunos',
|
||||
@@ -242,7 +257,7 @@ class ClassAnalyticsCard extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'Ver ranking detalhado',
|
||||
'Ver alunos da turma',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.8),
|
||||
fontSize: 12,
|
||||
@@ -272,7 +287,7 @@ class ClassAnalyticsCard extends StatelessWidget {
|
||||
bool isWarning = false,
|
||||
}) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
@@ -285,11 +300,7 @@ class ClassAnalyticsCard extends StatelessWidget {
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
color: isWarning ? Colors.orange : Colors.white,
|
||||
size: 20,
|
||||
),
|
||||
Icon(icon, color: isWarning ? Colors.orange : Colors.white, size: 20),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
value,
|
||||
|
||||
@@ -269,7 +269,7 @@ class _ClassRankingWidgetState extends State<ClassRankingWidget> {
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Nenhum aluno na disciplina',
|
||||
'Nenhum aluno na turma',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.7),
|
||||
fontSize: 18,
|
||||
|
||||
@@ -3,8 +3,6 @@ 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;
|
||||
@@ -21,6 +19,7 @@ class ClassStudentsInlineWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
final _searchController = TextEditingController();
|
||||
String _searchQuery = '';
|
||||
String? _classCode;
|
||||
late Stream<QuerySnapshot> _enrollmentsStream;
|
||||
@@ -32,13 +31,6 @@ class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
_initStream();
|
||||
}
|
||||
|
||||
void _initStream() {
|
||||
_enrollmentsStream = FirebaseFirestore.instance
|
||||
.collection('enrollments')
|
||||
.where('classId', isEqualTo: widget.classId)
|
||||
.snapshots();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ClassStudentsInlineWidget oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
@@ -48,20 +40,30 @@ class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _initStream() {
|
||||
_enrollmentsStream = FirebaseFirestore.instance
|
||||
.collection('enrollments')
|
||||
.where('classId', isEqualTo: widget.classId)
|
||||
.snapshots();
|
||||
}
|
||||
|
||||
Future<void> _loadClassCode() async {
|
||||
final doc = await FirebaseFirestore.instance
|
||||
.collection('classes')
|
||||
.doc(widget.classId)
|
||||
.get();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_classCode = doc.data()?['code'] as String? ?? '—';
|
||||
});
|
||||
setState(() => _classCode = doc.data()?['code'] as String? ?? '—');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _removeStudent(
|
||||
BuildContext context,
|
||||
Future<void> _confirmRemove(
|
||||
String enrollmentDocId,
|
||||
String studentName,
|
||||
) async {
|
||||
@@ -72,7 +74,7 @@ class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
title: const Text('Remover aluno'),
|
||||
content: Text(
|
||||
'Tens a certeza que queres remover "$studentName" desta disciplina?',
|
||||
'Tens a certeza que queres remover "$studentName" desta turma?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -87,15 +89,187 @@ class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed != true) return;
|
||||
await _deleteEnrollment(enrollmentDocId, studentName);
|
||||
}
|
||||
|
||||
Future<void> _deleteEnrollment(
|
||||
String enrollmentDocId,
|
||||
String studentName,
|
||||
) async {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
.collection('enrollments')
|
||||
.doc(enrollmentDocId)
|
||||
.delete();
|
||||
if (mounted) {
|
||||
if (!mounted) return;
|
||||
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 turma.',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('Erro ao remover: $e')));
|
||||
}
|
||||
}
|
||||
|
||||
// ── Build ──────────────────────────────────────────────────────────────────
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
return StreamBuilder<QuerySnapshot>(
|
||||
stream: _enrollmentsStream,
|
||||
builder: (context, snapshot) {
|
||||
final docs = snapshot.data?.docs ?? [];
|
||||
final enrollments = List<QueryDocumentSnapshot>.from(docs)
|
||||
..sort((a, b) {
|
||||
final aTs = (a.data() as Map)['joinedAt'] as Timestamp?;
|
||||
final bTs = (b.data() as Map)['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 d = doc.data() as Map<String, dynamic>;
|
||||
final name = (d['studentName'] as String? ?? '').toLowerCase();
|
||||
final email = (d['studentEmail'] as String? ?? '')
|
||||
.toLowerCase();
|
||||
return name.contains(_searchQuery) ||
|
||||
email.contains(_searchQuery);
|
||||
}).toList();
|
||||
|
||||
final bottomInset = MediaQuery.of(context).viewInsets.bottom;
|
||||
|
||||
return CustomScrollView(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 20, 20, 0),
|
||||
sliver: SliverToBoxAdapter(
|
||||
child: _buildHeader(cs, enrollments.length, snapshot),
|
||||
),
|
||||
),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 14, 20, 0),
|
||||
sliver: SliverToBoxAdapter(child: _buildSearchBar()),
|
||||
),
|
||||
if (snapshot.connectionState == ConnectionState.waiting &&
|
||||
snapshot.data == null)
|
||||
const SliverFillRemaining(
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(color: Colors.white),
|
||||
),
|
||||
)
|
||||
else if (filtered.isEmpty) ...[
|
||||
SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(bottom: bottomInset),
|
||||
child: _buildEmpty(cs),
|
||||
),
|
||||
),
|
||||
] else
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.fromLTRB(20, 14, 20, 20 + bottomInset),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildBuilderDelegate((context, index) {
|
||||
final doc = filtered[index];
|
||||
final data = doc.data() as Map<String, dynamic>;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: _buildStudentCard(
|
||||
cs: cs,
|
||||
enrollmentDocId: doc.id,
|
||||
studentName:
|
||||
data['studentName'] as String? ?? 'Aluno sem nome',
|
||||
studentEmail: data['studentEmail'] as String? ?? '',
|
||||
joinedAt: data['joinedAt'] as Timestamp?,
|
||||
),
|
||||
);
|
||||
}, childCount: filtered.length),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// ── Sub-widgets ────────────────────────────────────────────────────────────
|
||||
|
||||
Widget _buildHeader(
|
||||
ColorScheme cs,
|
||||
int count,
|
||||
AsyncSnapshot<QuerySnapshot> snapshot,
|
||||
) {
|
||||
return 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 &&
|
||||
snapshot.data == null
|
||||
? 'A carregar…'
|
||||
: '$count aluno${count == 1 ? '' : 's'} inscrito${count == 1 ? '' : 's'}',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.85),
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_buildCodeBadge(cs),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCodeBadge(ColorScheme cs) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (_classCode == null || _classCode == '—') return;
|
||||
Clipboard.setData(ClipboardData(text: _classCode!));
|
||||
ScaffoldMessenger.of(context)
|
||||
..clearSnackBars()
|
||||
..showSnackBar(
|
||||
@@ -106,287 +280,124 @@ class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
content: Text(
|
||||
'"$studentName" foi removido da disciplina.',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
duration: const Duration(seconds: 2),
|
||||
content: const Text(
|
||||
'Código copiado!',
|
||||
style: 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(
|
||||
},
|
||||
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(
|
||||
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: [
|
||||
// ── 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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Icon(
|
||||
Icons.copy,
|
||||
color: Colors.white.withValues(alpha: 0.7),
|
||||
size: 10,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// ── Search bar ──────────────────────────────────────────────
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
vertical: 10,
|
||||
const SizedBox(width: 3),
|
||||
Text(
|
||||
'copiar',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.7),
|
||||
fontSize: 9,
|
||||
),
|
||||
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 _buildSearchBar() {
|
||||
return 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: Theme(
|
||||
data: ThemeData.dark().copyWith(
|
||||
textSelectionTheme: const TextSelectionThemeData(
|
||||
cursorColor: Colors.white,
|
||||
selectionColor: Colors.white24,
|
||||
selectionHandleColor: Colors.white,
|
||||
),
|
||||
),
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
onChanged: (v) =>
|
||||
setState(() => _searchQuery = v.trim().toLowerCase()),
|
||||
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: () {
|
||||
_searchController.clear();
|
||||
setState(() => _searchQuery = '');
|
||||
},
|
||||
child: Icon(
|
||||
Icons.close,
|
||||
color: Colors.white.withValues(alpha: 0.7),
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -396,7 +407,6 @@ class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
required String studentName,
|
||||
required String studentEmail,
|
||||
required Timestamp? joinedAt,
|
||||
required int index,
|
||||
}) {
|
||||
return Dismissible(
|
||||
key: Key(enrollmentDocId),
|
||||
@@ -410,7 +420,7 @@ class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
),
|
||||
title: const Text('Remover aluno'),
|
||||
content: Text(
|
||||
'Tens a certeza que queres remover "$studentName" desta disciplina?',
|
||||
'Tens a certeza que queres remover "$studentName" desta turma?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -427,41 +437,7 @@ class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
);
|
||||
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')));
|
||||
}
|
||||
}
|
||||
},
|
||||
onDismissed: (_) => _deleteEnrollment(enrollmentDocId, studentName),
|
||||
background: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: cs.error.withValues(alpha: 0.85),
|
||||
@@ -480,7 +456,6 @@ class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// Avatar with initial
|
||||
Container(
|
||||
width: 42,
|
||||
height: 42,
|
||||
@@ -500,7 +475,6 @@ class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
// Info
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -536,7 +510,6 @@ class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
],
|
||||
),
|
||||
),
|
||||
// Remove button
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.person_remove_outlined,
|
||||
@@ -544,8 +517,7 @@ class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
size: 20,
|
||||
),
|
||||
tooltip: 'Remover aluno',
|
||||
onPressed: () =>
|
||||
_removeStudent(context, enrollmentDocId, studentName),
|
||||
onPressed: () => _confirmRemove(enrollmentDocId, studentName),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -595,7 +567,7 @@ class _ClassStudentsInlineWidgetState extends State<ClassStudentsInlineWidget> {
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'Partilha o código da disciplina com os alunos.',
|
||||
'Partilha o código da turma com os alunos.',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.45),
|
||||
fontSize: 13,
|
||||
|
||||
Reference in New Issue
Block a user