import 'package:flutter/material.dart'; import 'package:flutter_linkify/flutter_linkify.dart'; import 'package:matrix/matrix.dart'; import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/utils/file_description.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart'; import 'package:fluffychat/utils/url_launcher.dart'; class MessageDownloadContent extends StatelessWidget { final Event event; final Color textColor; final Color linkColor; const MessageDownloadContent( this.event, { required this.textColor, required this.linkColor, super.key, }); @override Widget build(BuildContext context) { final filename = event.content.tryGet('filename') ?? event.body; final filetype = (filename.contains('.') ? filename.split('.').last.toUpperCase() : event.content .tryGetMap('info') ?.tryGet('mimetype') ?.toUpperCase() ?? 'UNKNOWN'); final sizeString = event.sizeString ?? '?MB'; final fileDescription = event.fileDescription; return Padding( padding: const EdgeInsets.symmetric( horizontal: 16, vertical: 8, ), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, spacing: 8, children: [ OutlinedButton.icon( style: OutlinedButton.styleFrom( foregroundColor: textColor, side: BorderSide(color: textColor), ), icon: const Icon(Icons.file_download_outlined), label: Text( '$sizeString | $filetype - $filename', maxLines: 1, overflow: TextOverflow.ellipsis, ), onPressed: () => event.saveFile(context), ), if (fileDescription != null) ...[ Linkify( text: fileDescription, textScaleFactor: MediaQuery.textScalerOf(context).scale(1), style: TextStyle( color: textColor, fontSize: AppConfig.fontSizeFactor * AppConfig.messageFontSize, ), options: const LinkifyOptions(humanize: false), linkStyle: TextStyle( color: linkColor, fontSize: AppConfig.fontSizeFactor * AppConfig.messageFontSize, decoration: TextDecoration.underline, decorationColor: linkColor, ), onOpen: (url) => UrlLauncher(context, url.url).launchUrl(), ), ], ], ), ); } }