hym_ui/lib/attachmentWidget.dart

72 lines
2.2 KiB
Dart

import "dart:typed_data";
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") {
PdfViewer pdf = PdfViewer.data(
Uint8List.fromList(att.data),
sourceName: att.name,
params: const PdfViewerParams(
enableTextSelection: true,
scrollByMouseWheel: 0.5,
)
);
return pdf;
}
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(children: <Widget>[
Container(
color: Colors.white,
child: Padding(
padding: EdgeInsets.fromLTRB(10, 20, 0, 10),
child: Column(
children: [
Row(
children: [
CloseButton(onPressed: () => {Navigator.pop(context)}),
Text(
attachment.name
.toString(), //its alr a string but incase ¯\(ツ)/¯ //update: i did that everywhere lol
style: TextStyle(
color: Colors.black,
fontSize: 20,
decoration: TextDecoration
.none), //TODO: personalize your fonts
),
],
),
Expanded(
child: attachmentViewer(attachment),
)
],
),
),
),
]));
}
}