From ef9cb5b00d1c5c0f1f44af3f0ad51dd5bdd7e6e4 Mon Sep 17 00:00:00 2001 From: juan Date: Thu, 24 Apr 2025 00:52:42 -0400 Subject: [PATCH] pdf preview implemented --- lib/attachmentWidget.dart | 77 ++++++++++++++++++++------------------- lib/augment.dart | 1 - 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/lib/attachmentWidget.dart b/lib/attachmentWidget.dart index c3fcf57..041ab67 100644 --- a/lib/attachmentWidget.dart +++ b/lib/attachmentWidget.dart @@ -1,59 +1,62 @@ import "package:crab_ui/structs.dart"; import "package:flutter/material.dart"; +import 'package:pdfrx/pdfrx.dart'; class AttachmentWidget extends StatelessWidget { final AttachmentResponse attachment; AttachmentWidget({required this.attachment}); + Widget attachmentViewer(AttachmentResponse att) { + String extension = att.name + .toString() + .substring(att.name.toString().indexOf(".") + 1) + .toLowerCase(); + if (extension == "jpg") { + return Image.memory(att.data); + } else if (extension == "pdf") { + return PdfViewer.data(att.data, sourceName: att.name); + } + return Text( + "Attachment not supported for preview, you'll need to download", + style: TextStyle( + color: Colors.black, fontSize: 20, decoration: TextDecoration.none), + ); + } + @override Widget build(BuildContext context) { return Container( - color: Colors.black38, - child: Stack( - // appBar: AppBar(title: Text('New Tab Content')), - children: [ - + color: Colors.black38, + child: Stack(children: [ Container( color: Colors.white, child: Padding( padding: EdgeInsets.fromLTRB(10, 20, 0, 10), - child: Row( - + child: Column( children: [ - CloseButton( - onPressed: () => { - Navigator.pop(context) - } + Row( + children: [ + CloseButton(onPressed: () => {Navigator.pop(context)}), + Text( + attachment.name + .toString(), //its alr a string but incase ¯\(ツ)/¯ + style: TextStyle( + color: Colors.black, + fontSize: 20, + decoration: + TextDecoration.none), //TODO: personalize your fonts + ), + ], ), - Text( - attachment.name.toString(), //its alr a string but incase ¯\(ツ)/¯ - style: TextStyle( - color: Colors.black, - fontSize: 20, - decoration: TextDecoration.none - ), //TODO: personalize your fonts - ), + + Expanded( + + child: attachmentViewer(attachment), + ) ], ), ), ), - Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SizedBox( - width: 1000, - height: 600, - child: Image.memory(attachment.data), - ) - ], - ), - ), - ], - ), - ); + ])); } } - - - diff --git a/lib/augment.dart b/lib/augment.dart index b75226f..ebee03b 100644 --- a/lib/augment.dart +++ b/lib/augment.dart @@ -309,7 +309,6 @@ class AugmentClasses { context, MaterialPageRoute( builder: (context) => AttachmentWidget(attachment: file))); - })); } return listOfFiles;