pdf preview implemented

This commit is contained in:
Juan Marulanda De Los Rios 2025-04-24 00:52:42 -04:00
parent b98b8e7bc4
commit ef9cb5b00d
2 changed files with 40 additions and 38 deletions

View File

@ -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: <Widget> [
color: Colors.black38,
child: Stack(children: <Widget>[
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),
)
],
),
),
],
),
);
]));
}
}

View File

@ -309,7 +309,6 @@ class AugmentClasses {
context,
MaterialPageRoute(
builder: (context) => AttachmentWidget(attachment: file)));
}));
}
return listOfFiles;