diff --git a/lib/features/materials/presentation/pages/teacher_materials_page.dart b/lib/features/materials/presentation/pages/teacher_materials_page.dart index 08bca96..b6a3e8a 100644 --- a/lib/features/materials/presentation/pages/teacher_materials_page.dart +++ b/lib/features/materials/presentation/pages/teacher_materials_page.dart @@ -860,6 +860,33 @@ class _TeacherMaterialsPageState extends State { } } + Future _downloadFile(String? url, String fileName) async { + if (url == null || url.isEmpty) { + _showErrorSnackBar('URL do ficheiro não disponível'); + return; + } + + try { + print('Downloading file: $fileName'); + print('URL: $url'); + final uri = Uri.parse(url); + + final launched = await launchUrl( + uri, + mode: LaunchMode.externalApplication, + ); + + if (launched) { + _showSuccessSnackBar('A transferir $fileName...'); + } else { + _showErrorSnackBar('Não foi possível iniciar a transferência'); + } + } catch (e) { + print('Error downloading file: $e'); + _showErrorSnackBar('Erro ao transferir ficheiro: $e'); + } + } + Widget _buildMaterialCard({ required String docId, required String fileName, @@ -934,11 +961,19 @@ class _TeacherMaterialsPageState extends State { IconButton( icon: const Icon(Icons.visibility_outlined, color: Colors.blue), tooltip: 'Ver', + constraints: const BoxConstraints(minWidth: 40, minHeight: 40), onPressed: () => _openFile(url, fileName), ), + IconButton( + icon: const Icon(Icons.download_outlined, color: Colors.green), + tooltip: 'Transferir', + constraints: const BoxConstraints(minWidth: 40, minHeight: 40), + onPressed: () => _downloadFile(url, fileName), + ), IconButton( icon: const Icon(Icons.delete_outline, color: Colors.red), tooltip: 'Eliminar', + constraints: const BoxConstraints(minWidth: 40, minHeight: 40), onPressed: () => _showDeleteConfirmation( docId: docId, fileName: fileName,