diff --git a/lib/Helpers/PDFHelper.dart b/lib/Helpers/PDFHelper.dart index 09df479..97bc95c 100644 --- a/lib/Helpers/PDFHelper.dart +++ b/lib/Helpers/PDFHelper.dart @@ -1,11 +1,12 @@ import 'package:manager_api_new/api.dart'; +import 'package:manager_app/Models/managerContext.dart'; import 'dart:convert'; import 'package:pdf/pdf.dart'; import 'package:pdf/widgets.dart' as pw; import 'dart:html' as html; class PDFHelper { - static downloadPDF(List sections) async { + static downloadPDF(ManagerAppContext managerAppContext, List sections) async { var sectionsArticle = sections.where((section) => section.type == SectionType.Article || section.type == SectionType.Quizz); // TODO HERE Support more section types if(sectionsArticle.length > 0) { //final font = await rootBundle.load("fonts/OpenSans-Medium.ttf"); @@ -25,7 +26,7 @@ class PDFHelper { pw.Text(section.label!.replaceAll(RegExp("[^A-Za-z0-9---():!éàèëêäâç' ]"), '')), //style: pw.TextStyle(font: ttf, fontSize: 30) pw.Padding(padding: const pw.EdgeInsets.only(top: 20)), pw.BarcodeWidget( - data: section.id!, + data: "${managerAppContext.host!.replaceFirst("api", "web")}/${managerAppContext.instanceId}/${managerAppContext.selectedConfiguration!.id}/${section.id!}", width: 150, height: 150, barcode: pw.Barcode.qrCode(), diff --git a/lib/Screens/Configurations/Section/SubSection/Article/download_pdf.dart b/lib/Screens/Configurations/Section/SubSection/Article/download_pdf.dart index 3e0d120..90fddef 100644 --- a/lib/Screens/Configurations/Section/SubSection/Article/download_pdf.dart +++ b/lib/Screens/Configurations/Section/SubSection/Article/download_pdf.dart @@ -1,7 +1,10 @@ import 'package:flutter/material.dart'; import 'package:manager_app/Helpers/PDFHelper.dart'; +import 'package:manager_app/Models/managerContext.dart'; +import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:manager_api_new/api.dart'; +import 'package:provider/provider.dart'; class DownloadPDF extends StatefulWidget { final List sections; @@ -23,11 +26,14 @@ class _DownloadPDFState extends State { @override Widget build(BuildContext context) { + final appContext = Provider.of(context); + ManagerAppContext managerAppContext = appContext.getContext(); + return InkWell( onTap: () async { try { - PDFHelper.downloadPDF(widget.sections); + PDFHelper.downloadPDF(managerAppContext, widget.sections); } catch(e) { print(e); } diff --git a/lib/Screens/Configurations/Section/section_detail_screen.dart b/lib/Screens/Configurations/Section/section_detail_screen.dart index e16998b..7c037b2 100644 --- a/lib/Screens/Configurations/Section/section_detail_screen.dart +++ b/lib/Screens/Configurations/Section/section_detail_screen.dart @@ -85,6 +85,8 @@ class _SectionDetailScreenState extends State { } Widget bodySection(SectionDTO? sectionDTO, Size size, AppContext appContext, BuildContext context, GlobalKey globalKey) { + ManagerAppContext managerAppContext = appContext.getContext(); + return SingleChildScrollView( child: Column( //mainAxisAlignment: MainAxisAlignment.spaceAround, @@ -183,7 +185,7 @@ class _SectionDetailScreenState extends State { key: globalKey, child: QrImageView( padding: EdgeInsets.only(left: 5.0, top: 5.0, bottom: 5.0, right: 5.0), - data: sectionDTO!.id!, + data: "${managerAppContext.host!.replaceFirst("api", "web")}/${managerAppContext.instanceId}/${managerAppContext.selectedConfiguration!.id}/${sectionDTO!.id!}", version: QrVersions.auto, size: 50.0, ), diff --git a/lib/Screens/Configurations/configuration_detail_screen.dart b/lib/Screens/Configurations/configuration_detail_screen.dart index e6f5159..f924d5a 100644 --- a/lib/Screens/Configurations/configuration_detail_screen.dart +++ b/lib/Screens/Configurations/configuration_detail_screen.dart @@ -63,6 +63,7 @@ class _ConfigurationDetailScreenState extends State { } Widget bodyConfiguration(ConfigurationDTO configurationDTO, Size size, AppContext appContext, BuildContext context) { + ManagerAppContext managerAppContext = appContext.getContext(); return Column( //mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ @@ -244,7 +245,7 @@ class _ConfigurationDetailScreenState extends State { textColor: Colors.white, fontSize: 15, press: () { - PDFHelper.downloadPDF(sections!); + PDFHelper.downloadPDF(managerAppContext, sections!); }, ), CheckInputContainer(