import 'dart:html' as html; import 'package:auto_size_text/auto_size_text.dart'; import 'package:baligh_dashboard/widgets/app_toast.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; class FileCard extends StatelessWidget { const FileCard( {super.key, required this.type, required this.filename, required this.fileUrl}); final String type; final String filename; final String fileUrl; @override Widget build(BuildContext context) { return InkWell( borderRadius: const BorderRadius.all(Radius.circular(12)), hoverColor: Colors.transparent, onTap: () async { try { html.AnchorElement(href: fileUrl) ..setAttribute('target', '_blank') ..setAttribute('download', '$filename.pdf') // Specify the filename ..click(); BotToast.showCustomText(toastBuilder: (_) { return const AppToast(text: "تم التحميل"); }); } catch (e) { print(e); BotToast.showCustomText(toastBuilder: (_) { return const AppToast(text: "حدث خطأ ما في التحميل"); }); } }, child: Container( width: 180, clipBehavior: Clip.hardEdge, padding: const EdgeInsets.all(8), margin: const EdgeInsets.symmetric(horizontal: 3), decoration: BoxDecoration( color: Theme.of(context).cardColor, borderRadius: const BorderRadius.all(Radius.circular(12)), ), child: Row( children: [ Container( padding: const EdgeInsets.all(10), decoration: BoxDecoration( color: type == "image" ? Colors.red.withOpacity(0.2) : type == "video" ? Colors.blue.withOpacity(0.2) : Colors.grey.withOpacity(0.2), borderRadius: const BorderRadius.all(Radius.circular(8)), ), child: Center( child: Icon( type == "image" ? FontAwesomeIcons.image : type == "video" ? FontAwesomeIcons.video : FontAwesomeIcons.microphone, color: type == "image" ? Colors.red : type == "video" ? Colors.blue : Colors.grey, size: 18, ), ), ), const SizedBox( width: 5, ), Expanded( child: AutoSizeText( filename, style: Theme.of(context).textTheme.bodySmall, minFontSize: 6, ), ) ], ), ), ); } }