diff --git a/Frontend/patient_manager/lib/mih_packages/patient_profile/builder/build_file_view.dart b/Frontend/patient_manager/lib/mih_packages/patient_profile/builder/build_file_view.dart index 74898615..b33d21e7 100644 --- a/Frontend/patient_manager/lib/mih_packages/patient_profile/builder/build_file_view.dart +++ b/Frontend/patient_manager/lib/mih_packages/patient_profile/builder/build_file_view.dart @@ -4,6 +4,7 @@ import 'package:patient_manager/mih_objects/arguments.dart'; import 'package:syncfusion_flutter_core/theme.dart'; import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart'; import "package:universal_html/html.dart" as html; +import 'package:http/http.dart' as http; class BuildFileView extends StatefulWidget { final String link; @@ -33,6 +34,21 @@ class _BuildFileViewState extends State { return path.split("/").last; } + void printDocument() async { + print("Printing ${widget.path.split("/").last}"); + http.Response response = await http.get(Uri.parse(widget.link)); + var pdfData = response.bodyBytes; + Navigator.of(context).pushNamed( + '/file-veiwer/print-preview', + arguments: PrintPreviewArguments( + pdfData, + getFileName( + widget.path, + ), + ), + ); + } + @override void dispose() { pdfViewerController.dispose(); @@ -69,16 +85,10 @@ class _BuildFileViewState extends State { iconSize: 35, padding: const EdgeInsets.all(0), onPressed: () { - Navigator.of(context).pushNamed( - '/file-veiwer', - arguments: FileViewArguments( - widget.link, - widget.path, - ), - ); + printDocument(); }, icon: Icon( - Icons.fullscreen, + Icons.print, color: MzanziInnovationHub.of(context)!.theme.primaryColor(), ), ), diff --git a/Frontend/patient_manager/lib/mih_packages/patient_profile/full_screen_file.dart b/Frontend/patient_manager/lib/mih_packages/patient_profile/full_screen_file.dart index 2df17601..d8c9f4b2 100644 --- a/Frontend/patient_manager/lib/mih_packages/patient_profile/full_screen_file.dart +++ b/Frontend/patient_manager/lib/mih_packages/patient_profile/full_screen_file.dart @@ -9,7 +9,7 @@ import 'package:syncfusion_flutter_core/theme.dart'; import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart'; import "package:universal_html/html.dart" as html; import 'package:http/http.dart' as http; -import 'package:pdf/pdf.dart'; + import 'package:printing/printing.dart'; class FullScreenFileViewer extends StatefulWidget { @@ -50,12 +50,24 @@ class _FullScreenFileViewerState extends State { print("Printing ${widget.arguments.path.split("/").last}"); http.Response response = await http.get(Uri.parse(widget.arguments.link)); var pdfData = response.bodyBytes; - try { - await Printing.layoutPdf( - onLayout: (PdfPageFormat format) async => pdfData); - } on Exception catch (_) { - print("Print Error"); - } + Navigator.of(context).pushNamed( + '/file-veiwer/print-preview', + arguments: pdfData, + ); + // Navigator.of(context).push( + // MaterialPageRoute( + // builder: (context) => PdfPreview( + // initialPageFormat: PdfPageFormat.a4, + // build: (format) => pdfData, + // ), + // ), + // ); + // try { + // await Printing.layoutPdf( + // onLayout: (PdfPageFormat format) async => pdfData); + // } on Exception catch (_) { + // print("Print Error"); + // } } void shareDocument() async { @@ -79,17 +91,11 @@ class _FullScreenFileViewerState extends State { MIHHeader getHeader(double width) { bool isPDF; - bool isDesktop; if (getExtType(widget.arguments.path).toLowerCase() == "pdf") { isPDF = true; } else { isPDF = false; } - if (MzanziInnovationHub.of(context)!.theme.screenType == "desktop") { - isDesktop = true; - } else { - isDesktop = false; - } return MIHHeader( headerAlignment: MainAxisAlignment.end, headerItems: [ @@ -188,33 +194,31 @@ class _FullScreenFileViewerState extends State { ), ), ), - IconButton( - iconSize: 30, - padding: const EdgeInsets.all(0), - onPressed: () { - if (isDesktop) { - printDocument(); - } else {} - }, - icon: Icon( - Icons.print, - color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), - ), - ), // IconButton( // iconSize: 30, // padding: const EdgeInsets.all(0), // onPressed: () { - // html.window.open( - // widget.arguments.link, - // // '${AppEnviroment.baseFileUrl}/mih/$filePath', - // 'download'); + // printDocument(); // }, // icon: Icon( - // Icons.download, + // Icons.print, // color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), // ), // ), + IconButton( + iconSize: 30, + padding: const EdgeInsets.all(0), + onPressed: () { + html.window.open( + widget.arguments.link, + // '${AppEnviroment.baseFileUrl}/mih/$filePath', + 'download'); + }, + icon: Icon( + Icons.download, + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), ], ); }