remove full screen pdf preview and replace with print preview

This commit is contained in:
2024-10-02 16:18:43 +02:00
parent ceab3e00f3
commit dc97d7d58a
2 changed files with 53 additions and 39 deletions

View File

@@ -4,6 +4,7 @@ import 'package:patient_manager/mih_objects/arguments.dart';
import 'package:syncfusion_flutter_core/theme.dart'; import 'package:syncfusion_flutter_core/theme.dart';
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart'; import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
import "package:universal_html/html.dart" as html; import "package:universal_html/html.dart" as html;
import 'package:http/http.dart' as http;
class BuildFileView extends StatefulWidget { class BuildFileView extends StatefulWidget {
final String link; final String link;
@@ -33,6 +34,21 @@ class _BuildFileViewState extends State<BuildFileView> {
return path.split("/").last; 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 @override
void dispose() { void dispose() {
pdfViewerController.dispose(); pdfViewerController.dispose();
@@ -69,16 +85,10 @@ class _BuildFileViewState extends State<BuildFileView> {
iconSize: 35, iconSize: 35,
padding: const EdgeInsets.all(0), padding: const EdgeInsets.all(0),
onPressed: () { onPressed: () {
Navigator.of(context).pushNamed( printDocument();
'/file-veiwer',
arguments: FileViewArguments(
widget.link,
widget.path,
),
);
}, },
icon: Icon( icon: Icon(
Icons.fullscreen, Icons.print,
color: MzanziInnovationHub.of(context)!.theme.primaryColor(), color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
), ),
), ),

View File

@@ -9,7 +9,7 @@ import 'package:syncfusion_flutter_core/theme.dart';
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart'; import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
import "package:universal_html/html.dart" as html; import "package:universal_html/html.dart" as html;
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:pdf/pdf.dart';
import 'package:printing/printing.dart'; import 'package:printing/printing.dart';
class FullScreenFileViewer extends StatefulWidget { class FullScreenFileViewer extends StatefulWidget {
@@ -50,12 +50,24 @@ class _FullScreenFileViewerState extends State<FullScreenFileViewer> {
print("Printing ${widget.arguments.path.split("/").last}"); print("Printing ${widget.arguments.path.split("/").last}");
http.Response response = await http.get(Uri.parse(widget.arguments.link)); http.Response response = await http.get(Uri.parse(widget.arguments.link));
var pdfData = response.bodyBytes; var pdfData = response.bodyBytes;
try { Navigator.of(context).pushNamed(
await Printing.layoutPdf( '/file-veiwer/print-preview',
onLayout: (PdfPageFormat format) async => pdfData); arguments: pdfData,
} on Exception catch (_) { );
print("Print Error"); // 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 { void shareDocument() async {
@@ -79,17 +91,11 @@ class _FullScreenFileViewerState extends State<FullScreenFileViewer> {
MIHHeader getHeader(double width) { MIHHeader getHeader(double width) {
bool isPDF; bool isPDF;
bool isDesktop;
if (getExtType(widget.arguments.path).toLowerCase() == "pdf") { if (getExtType(widget.arguments.path).toLowerCase() == "pdf") {
isPDF = true; isPDF = true;
} else { } else {
isPDF = false; isPDF = false;
} }
if (MzanziInnovationHub.of(context)!.theme.screenType == "desktop") {
isDesktop = true;
} else {
isDesktop = false;
}
return MIHHeader( return MIHHeader(
headerAlignment: MainAxisAlignment.end, headerAlignment: MainAxisAlignment.end,
headerItems: [ headerItems: [
@@ -188,33 +194,31 @@ class _FullScreenFileViewerState extends State<FullScreenFileViewer> {
), ),
), ),
), ),
IconButton(
iconSize: 30,
padding: const EdgeInsets.all(0),
onPressed: () {
if (isDesktop) {
printDocument();
} else {}
},
icon: Icon(
Icons.print,
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
),
),
// IconButton( // IconButton(
// iconSize: 30, // iconSize: 30,
// padding: const EdgeInsets.all(0), // padding: const EdgeInsets.all(0),
// onPressed: () { // onPressed: () {
// html.window.open( // printDocument();
// widget.arguments.link,
// // '${AppEnviroment.baseFileUrl}/mih/$filePath',
// 'download');
// }, // },
// icon: Icon( // icon: Icon(
// Icons.download, // Icons.print,
// color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), // 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(),
),
),
], ],
); );
} }