633 lines
20 KiB
Dart
633 lines
20 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_animate/flutter_animate.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import '../../../../core/services/auth_service.dart';
|
|
import '../../../../features/materials/presentation/pages/teacher_materials_page.dart';
|
|
|
|
/// Quick access cards for teacher actions
|
|
class TeacherQuickActionsWidget extends StatefulWidget {
|
|
const TeacherQuickActionsWidget({super.key});
|
|
|
|
@override
|
|
State<TeacherQuickActionsWidget> createState() => _TeacherQuickActionsWidgetState();
|
|
}
|
|
|
|
class _TeacherQuickActionsWidgetState extends State<TeacherQuickActionsWidget> {
|
|
bool _isCreatingClass = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'Ações Rápidas',
|
|
style: TextStyle(
|
|
color: const Color(0xFF2D3748),
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
// Primary Actions Row
|
|
Row(
|
|
children: [
|
|
// Upload Content Card (Primary)
|
|
Expanded(flex: 2, child: _buildUploadContentCard(context)),
|
|
const SizedBox(width: 16),
|
|
// Create Class Card
|
|
Expanded(flex: 2, child: _buildCreateClassCard(context)),
|
|
const SizedBox(width: 16),
|
|
// Create Quiz Card (Secondary)
|
|
Expanded(flex: 2, child: _buildCreateQuizCard(context)),
|
|
],
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
// Secondary Actions Row
|
|
Row(
|
|
children: [
|
|
// Manage Students Card
|
|
Expanded(child: _buildManageStudentsCard(context)),
|
|
const SizedBox(width: 16),
|
|
// View Analytics Card
|
|
Expanded(child: _buildViewAnalyticsCard(context)),
|
|
],
|
|
),
|
|
],
|
|
)
|
|
.animate()
|
|
.slideY(
|
|
duration: const Duration(milliseconds: 800),
|
|
curve: Curves.easeOut,
|
|
)
|
|
.then(delay: const Duration(milliseconds: 200));
|
|
}
|
|
|
|
Widget _buildUploadContentCard(BuildContext context) {
|
|
return Container(
|
|
constraints: const BoxConstraints(minHeight: 135, maxHeight: 160),
|
|
decoration: BoxDecoration(
|
|
gradient: const LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [Color(0xFF82C9BD), Color(0xFF6BA8A0)],
|
|
),
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: const Color(0xFF82C9BD).withOpacity(0.3),
|
|
blurRadius: 15,
|
|
offset: const Offset(0, 8),
|
|
),
|
|
],
|
|
),
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
borderRadius: BorderRadius.circular(16),
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) => const TeacherMaterialsPage(),
|
|
),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(14),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white.withOpacity(0.2),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: const Icon(
|
|
Icons.upload_file,
|
|
color: Colors.white,
|
|
size: 22,
|
|
),
|
|
),
|
|
const Spacer(),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 8,
|
|
vertical: 3,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFFF68D2D),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: const Text(
|
|
'NOVO',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 9,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const Spacer(),
|
|
const Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'Upload Conteúdo',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
SizedBox(height: 4),
|
|
Text(
|
|
'PDFs, textos, imagens',
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 12,
|
|
height: 1.2,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
.animate()
|
|
.scale(
|
|
duration: const Duration(milliseconds: 600),
|
|
curve: Curves.elasticOut,
|
|
)
|
|
.then(delay: const Duration(milliseconds: 100));
|
|
}
|
|
|
|
Widget _buildCreateQuizCard(BuildContext context) {
|
|
return Container(
|
|
height: 150,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: const Color(0xFFE2E8F0), width: 1),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.05),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
borderRadius: BorderRadius.circular(16),
|
|
onTap: () => context.go('/teacher/quiz/create'),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(14),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(10),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFFF68D2D).withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: const Icon(
|
|
Icons.quiz,
|
|
color: Color(0xFFF68D2D),
|
|
size: 24,
|
|
),
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
'Criar Quiz',
|
|
style: TextStyle(
|
|
color: Color(0xFF2D3748),
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'Avaliações interativas',
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
color: const Color(0xFF718096),
|
|
fontSize: 12,
|
|
height: 1.2,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
.animate()
|
|
.scale(
|
|
duration: const Duration(milliseconds: 600),
|
|
curve: Curves.elasticOut,
|
|
)
|
|
.then(delay: const Duration(milliseconds: 200));
|
|
}
|
|
|
|
Widget _buildManageStudentsCard(BuildContext context) {
|
|
return Container(
|
|
height: 120,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: const Color(0xFFE2E8F0), width: 1),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.05),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
borderRadius: BorderRadius.circular(16),
|
|
onTap: () => context.go('/teacher/students'),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF82C9BD).withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: const Icon(
|
|
Icons.people,
|
|
color: Color(0xFF82C9BD),
|
|
size: 20,
|
|
),
|
|
),
|
|
const Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'Gerir Alunos',
|
|
style: TextStyle(
|
|
color: Color(0xFF2D3748),
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Text(
|
|
'Acesso e permissões',
|
|
style: TextStyle(
|
|
color: Color(0xFF718096),
|
|
fontSize: 11,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
.animate()
|
|
.scale(
|
|
duration: const Duration(milliseconds: 600),
|
|
curve: Curves.elasticOut,
|
|
)
|
|
.then(delay: const Duration(milliseconds: 300));
|
|
}
|
|
|
|
Widget _buildViewAnalyticsCard(BuildContext context) {
|
|
return Container(
|
|
height: 120,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: const Color(0xFFE2E8F0), width: 1),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.05),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
borderRadius: BorderRadius.circular(16),
|
|
onTap: () => context.go('/teacher/analytics'),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF6BA8A0).withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: const Icon(
|
|
Icons.analytics,
|
|
color: Color(0xFF6BA8A0),
|
|
size: 20,
|
|
),
|
|
),
|
|
const Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'Analytics',
|
|
style: TextStyle(
|
|
color: Color(0xFF2D3748),
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Text(
|
|
'Desempenho da turma',
|
|
style: TextStyle(
|
|
color: Color(0xFF718096),
|
|
fontSize: 11,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
.animate()
|
|
.scale(
|
|
duration: const Duration(milliseconds: 600),
|
|
curve: Curves.elasticOut,
|
|
)
|
|
.then(delay: const Duration(milliseconds: 400));
|
|
}
|
|
|
|
Widget _buildCreateClassCard(BuildContext context) {
|
|
return Container(
|
|
constraints: const BoxConstraints(minHeight: 135, maxHeight: 160),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: const Color(0xFFE2E8F0), width: 1),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.05),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
borderRadius: BorderRadius.circular(16),
|
|
onTap: _isCreatingClass ? null : () => _showCreateClassDialog(context),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(14),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(10),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF82C9BD).withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: _isCreatingClass
|
|
? const SizedBox(
|
|
width: 24,
|
|
height: 24,
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 2,
|
|
color: Color(0xFF82C9BD),
|
|
),
|
|
)
|
|
: const Icon(
|
|
Icons.school,
|
|
color: Color(0xFF82C9BD),
|
|
size: 24,
|
|
),
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'Criar Turma',
|
|
style: TextStyle(
|
|
color: const Color(0xFF2D3748),
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'Gerar código de acesso',
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
color: const Color(0xFF718096),
|
|
fontSize: 12,
|
|
height: 1.2,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
.animate()
|
|
.scale(
|
|
duration: const Duration(milliseconds: 600),
|
|
curve: Curves.elasticOut,
|
|
)
|
|
.then(delay: const Duration(milliseconds: 150));
|
|
}
|
|
|
|
void _showCreateClassDialog(BuildContext context) {
|
|
final TextEditingController nameController = TextEditingController();
|
|
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext dialogContext) {
|
|
return AlertDialog(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
title: const Text(
|
|
'Criar Nova Turma',
|
|
style: TextStyle(
|
|
color: Color(0xFF2D3748),
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
'Digite o nome da turma:',
|
|
style: TextStyle(
|
|
color: Color(0xFF718096),
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
TextField(
|
|
controller: nameController,
|
|
decoration: InputDecoration(
|
|
hintText: 'Ex: Matemática 9º Ano',
|
|
filled: true,
|
|
fillColor: const Color(0xFFF7FAFC),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
borderSide: BorderSide.none,
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
borderSide: BorderSide.none,
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
borderSide: const BorderSide(
|
|
color: Color(0xFF82C9BD),
|
|
width: 2,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(dialogContext).pop(),
|
|
child: const Text(
|
|
'Cancelar',
|
|
style: TextStyle(color: Color(0xFF718096)),
|
|
),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
final className = nameController.text.trim();
|
|
if (className.isNotEmpty) {
|
|
Navigator.of(dialogContext).pop();
|
|
_createClass(className);
|
|
}
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: const Color(0xFF82C9BD),
|
|
foregroundColor: Colors.white,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
child: const Text('Criar'),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
String _generateClassCode() {
|
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
final random = Random();
|
|
return String.fromCharCodes(
|
|
Iterable.generate(
|
|
6,
|
|
(_) => chars.codeUnitAt(random.nextInt(chars.length)),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _createClass(String className) async {
|
|
setState(() {
|
|
_isCreatingClass = true;
|
|
});
|
|
|
|
try {
|
|
final currentUser = AuthService.currentUser;
|
|
if (currentUser == null) {
|
|
throw Exception('Utilizador não autenticado');
|
|
}
|
|
|
|
final classCode = _generateClassCode();
|
|
final firestore = FirebaseFirestore.instance;
|
|
|
|
await firestore.collection('classes').add({
|
|
'name': className,
|
|
'teacherId': currentUser.uid,
|
|
'code': classCode,
|
|
'createdAt': FieldValue.serverTimestamp(),
|
|
});
|
|
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text('Turma "$className" criada com sucesso! Código: $classCode'),
|
|
backgroundColor: const Color(0xFF82C9BD),
|
|
behavior: SnackBarBehavior.floating,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} catch (e) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text('Erro ao criar turma: $e'),
|
|
backgroundColor: Colors.red,
|
|
behavior: SnackBarBehavior.floating,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} finally {
|
|
setState(() {
|
|
_isCreatingClass = false;
|
|
});
|
|
}
|
|
}
|
|
}
|