pdf, and png preview

This commit is contained in:
Juan Marulanda De Los Rios 2025-04-24 12:09:55 -04:00
parent 8ae776c92f
commit 6beda384e1
2 changed files with 16 additions and 13 deletions

View File

@ -3,6 +3,7 @@ import "dart:typed_data";
import "package:crab_ui/structs.dart"; import "package:crab_ui/structs.dart";
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import 'package:pdfrx/pdfrx.dart'; import 'package:pdfrx/pdfrx.dart';
import 'package:photo_view/photo_view.dart';
class AttachmentWidget extends StatelessWidget { class AttachmentWidget extends StatelessWidget {
final AttachmentResponse attachment; final AttachmentResponse attachment;
@ -13,25 +14,24 @@ class AttachmentWidget extends StatelessWidget {
.toString() .toString()
.substring(att.name.toString().indexOf(".") + 1) .substring(att.name.toString().indexOf(".") + 1)
.toLowerCase(); .toLowerCase();
if (extension == "jpg") { if (extension == "jpg" || extension == "png") {
return Image.memory(att.data); return Image.memory(att.data);
} else if (extension == "pdf") { } else if (extension == "pdf") {
PdfViewer pdf = PdfViewer.data( return PdfViewer.data(Uint8List.fromList(att.data),
Uint8List.fromList(att.data), sourceName: att.name,
sourceName: att.name, params: PdfViewerParams(
params: const PdfViewerParams( enableTextSelection: true,
enableTextSelection: true, scrollByMouseWheel: 0.5,
scrollByMouseWheel: 0.5, annotationRenderingMode:
) PdfAnnotationRenderingMode.annotationAndForms,
); ));
return pdf;
} }
return Text( return Center(
child: Text(
"Attachment not supported for preview, you'll need to download", "Attachment not supported for preview, you'll need to download",
style: TextStyle( style: TextStyle(
color: Colors.black, fontSize: 20, decoration: TextDecoration.none), color: Colors.black, fontSize: 20, decoration: TextDecoration.none),
); ));
} }
@override @override

View File

@ -20,10 +20,13 @@ dependencies:
mime: ^1.0.3 mime: ^1.0.3
pointer_interceptor: ^0.10.1+2 pointer_interceptor: ^0.10.1+2
file_saver: ^0.2.14 file_saver: ^0.2.14
english_words: ^4.0.0 english_words: ^4.0.0
provider: ^6.0.0 provider: ^6.0.0
intl: ^0.19.0 intl: ^0.19.0
pdfrx: ^1.0.94
photo_view: ^0.15.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: