diff --git a/assets/fonts/OpenSans-Medium.ttf b/assets/fonts/OpenSans-Medium.ttf new file mode 100644 index 0000000..faa5386 Binary files /dev/null and b/assets/fonts/OpenSans-Medium.ttf differ diff --git a/lib/Helpers/PDFHelper.dart b/lib/Helpers/PDFHelper.dart new file mode 100644 index 0000000..d132048 --- /dev/null +++ b/lib/Helpers/PDFHelper.dart @@ -0,0 +1,73 @@ +import 'package:flutter/services.dart'; +import 'package:managerapi/api.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 { + var sectionsArticle = sections.where((section) => section.type == SectionType.article); + if(sectionsArticle.length > 0) { + final font = await rootBundle.load("fonts/OpenSans-Medium.ttf"); + final ttf = pw.Font.ttf(font); + final pdf = pw.Document(); + + pdf.addPage(pw.MultiPage( + pageFormat: PdfPageFormat.a4, + build: (pw.Context context) { + return [ + for(var section in sectionsArticle) + pw.Center( + child: + pw.Column( + children: [ + pw.Text(section.label, style: pw.TextStyle(font: ttf, fontSize: 30)), + pw.Padding(padding: const pw.EdgeInsets.only(top: 20)), + pw.BarcodeWidget( + data: section.id, + width: 150, + height: 150, + barcode: pw.Barcode.qrCode(), + drawText: false, + ), + pw.Padding(padding: const pw.EdgeInsets.only(bottom: 30)), + ] + ) + ) + ]; + })); + + /*pdf.addPage(pw.Page( + pageFormat: PdfPageFormat.a4, + build: (pw.Context context) { + return + pw.Center( + child: pw.Column( + children: [ + pw.Text(section.label, style: pw.TextStyle(font: ttf, fontSize: 30)), + pw.Padding(padding: const pw.EdgeInsets.only(top: 10)), + pw.BarcodeWidget( + data: section.id, + width: 150, + height: 150, + barcode: pw.Barcode.qrCode(), + drawText: false, + ), + ], + ) + ); + }));*/ + + + + var test = await pdf.save(); + final content = base64Encode(test); + final fileName = sectionsArticle.length > 1 ? 'QRCodes' : sectionsArticle.first.label; + final anchor = html.AnchorElement( + href: "data:application/octet-stream;charset=utf-16le;base64,$content") + ..setAttribute("download", '$fileName.pdf') + ..click(); + } + } +} \ No newline at end of file diff --git a/lib/Screens/Configurations/Section/SubSection/Article/article_config.dart b/lib/Screens/Configurations/Section/SubSection/Article/article_config.dart index 792dd41..e073f93 100644 --- a/lib/Screens/Configurations/Section/SubSection/Article/article_config.dart +++ b/lib/Screens/Configurations/Section/SubSection/Article/article_config.dart @@ -99,7 +99,7 @@ class _ArticleConfigState extends State { isChecked: articleDTO.isContentTop, onChanged: (value) { setState(() { - print(value); + //print(value); articleDTO.isContentTop = value; widget.onChanged(jsonEncode(articleDTO).toString()); }); diff --git a/lib/Screens/Configurations/Section/SubSection/Article/download_pdf.dart b/lib/Screens/Configurations/Section/SubSection/Article/download_pdf.dart new file mode 100644 index 0000000..4b6b8ef --- /dev/null +++ b/lib/Screens/Configurations/Section/SubSection/Article/download_pdf.dart @@ -0,0 +1,47 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:manager_app/Helpers/PDFHelper.dart'; +import 'package:manager_app/app_context.dart'; +import 'package:manager_app/constants.dart'; +import 'package:managerapi/api.dart'; +import 'package:provider/provider.dart'; + +class DownloadPDF extends StatefulWidget { + final List sections; + const DownloadPDF({ + Key key, + this.sections, + }) : super(key: key); + + @override + _DownloadPDFState createState() => _DownloadPDFState(); +} + +class _DownloadPDFState extends State { + + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + final appContext = Provider.of(context); + Size size = MediaQuery.of(context).size; + + return + InkWell( + onTap: () async { + try { + PDFHelper.downloadPDF(widget.sections); + } catch(e) { + print(e); + } + }, + child: Padding( + padding: const EdgeInsets.only(left: 5.0), + child: Icon(Icons.cloud_download, color: kPrimaryColor) + ), + ); + } +} \ No newline at end of file diff --git a/lib/Screens/Configurations/Section/SubSection/Quizz/quizz_config.dart b/lib/Screens/Configurations/Section/SubSection/Quizz/quizz_config.dart index f01da78..a58dc44 100644 --- a/lib/Screens/Configurations/Section/SubSection/Quizz/quizz_config.dart +++ b/lib/Screens/Configurations/Section/SubSection/Quizz/quizz_config.dart @@ -89,9 +89,7 @@ class _QuizzConfigState extends State { if (result != null) { setState(() { - print("BAAAD"); quizzDTO.badLevel = result; - print(quizzDTO.badLevel); widget.onChanged(jsonEncode(quizzDTO).toString()); }); } @@ -216,7 +214,6 @@ class _QuizzConfigState extends State { right: 10, child: InkWell( onTap: () async { - print("new question"); QuestionDTO result = await showNewOrUpdateQuestionQuizz(null, appContext, context, "Question"); if (result != null) { diff --git a/lib/Screens/Configurations/Section/section_detail_screen.dart b/lib/Screens/Configurations/Section/section_detail_screen.dart index a91550b..570aa29 100644 --- a/lib/Screens/Configurations/Section/section_detail_screen.dart +++ b/lib/Screens/Configurations/Section/section_detail_screen.dart @@ -17,6 +17,7 @@ import 'package:provider/provider.dart'; import 'package:intl/intl.dart'; import 'SubSection/Article/article_config.dart'; +import 'SubSection/Article/download_pdf.dart'; import 'SubSection/Map/map_config.dart'; import 'SubSection/Menu/menu_config.dart'; import 'SubSection/Quizz/quizz_config.dart'; @@ -97,6 +98,8 @@ class _SectionDetailScreenState extends State { ), ), Text(sectionDTO != null ? sectionDTO.label : "", style: TextStyle(fontSize: 30, fontWeight: FontWeight.w400)), + if(sectionDTO.type == SectionType.article) + DownloadPDF(sections: [sectionDTO]), ], ), Padding( @@ -260,7 +263,6 @@ class _SectionDetailScreenState extends State { textColor: Colors.white, fontSize: 15, press: () { - print(sectionDTO); delete(sectionDTO, appContext); }, ), @@ -351,7 +353,7 @@ class _SectionDetailScreenState extends State { initialValue: sectionDTO.data, onChanged: (String data) { print("Received info in parent"); - print(data); + //print(data); sectionDTO.data = data; }, ); @@ -360,17 +362,16 @@ class _SectionDetailScreenState extends State { initialValue: sectionDTO.data, onChanged: (String data) { print("Received info in parent - quizz"); - print(data); + //print(data); sectionDTO.data = data; }, ); case SectionType.article: - print(sectionDTO.data); return ArticleConfig( initialValue: sectionDTO.data, onChanged: (String data) { print("Received info in parent - article"); - print(data); + //print(data); sectionDTO.data = data; save(false, sectionDTO, appContext); }, @@ -381,6 +382,6 @@ class _SectionDetailScreenState extends State { Future getSection(String sectionId, Client client) async { SectionDTO section = await client.sectionApi.sectionGetDetail(sectionId); - print(section); + //print(section); return section; } diff --git a/lib/Screens/Configurations/configuration_detail_screen.dart b/lib/Screens/Configurations/configuration_detail_screen.dart index 9d0358d..3dc909e 100644 --- a/lib/Screens/Configurations/configuration_detail_screen.dart +++ b/lib/Screens/Configurations/configuration_detail_screen.dart @@ -14,6 +14,7 @@ import 'package:manager_app/Components/multi_select_container.dart'; import 'package:manager_app/Components/rounded_button.dart'; import 'package:manager_app/Components/string_input_container.dart'; import 'package:manager_app/Helpers/FileHelper.dart'; +import 'package:manager_app/Helpers/PDFHelper.dart'; import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/Screens/Configurations/section_reorderList.dart'; import 'package:manager_app/app_context.dart'; @@ -223,6 +224,17 @@ class _ConfigurationDetailScreenState extends State { configurationDTO.isMobile = value; }, ), + if(configurationDTO.isMobile) + RoundedButton( + text: "Télécharger les QRCodes", + icon: Icons.download_outlined, + color: Colors.grey, + textColor: Colors.white, + fontSize: 15, + press: () { + PDFHelper.downloadPDF(sections); + }, + ) ], ) ], diff --git a/lib/Screens/Configurations/configurations_screen.dart b/lib/Screens/Configurations/configurations_screen.dart index f43854f..6e4c508 100644 --- a/lib/Screens/Configurations/configurations_screen.dart +++ b/lib/Screens/Configurations/configurations_screen.dart @@ -137,7 +137,7 @@ Future> getConfigurations(dynamic appContext) async { List configurations = await appContext.getContext().clientAPI.configurationApi.configurationGet(); print("number of configurations " + configurations.length.toString()); configurations.forEach((element) { - print(element); + //print(element); }); return configurations; } diff --git a/lib/Screens/Devices/devices_screen.dart b/lib/Screens/Devices/devices_screen.dart index 2489130..1541a7f 100644 --- a/lib/Screens/Devices/devices_screen.dart +++ b/lib/Screens/Devices/devices_screen.dart @@ -226,7 +226,7 @@ Future> getDevices(dynamic appContext) async { List devices = await appContext.getContext().clientAPI.deviceApi.deviceGet(); print("number of devices " + devices.length.toString()); devices.forEach((element) { - print(element); + //print(element); }); return devices; } diff --git a/lib/Screens/Main/components/body.dart b/lib/Screens/Main/components/body.dart index 80e29c7..1537229 100644 --- a/lib/Screens/Main/components/body.dart +++ b/lib/Screens/Main/components/body.dart @@ -32,7 +32,7 @@ class _BodyState extends State { MenuSection configurations = new MenuSection(name: "Configurations", type: "configurations", order: 1); MenuSection resources = new MenuSection(name: "Ressources", type: "resources", order: 2); - Menu menu = new Menu(title: "Manager"); + Menu menu = new Menu(title: "MyMuseum"); @override Widget build(BuildContext context) { diff --git a/lib/Screens/Resources/resource_body_grid.dart b/lib/Screens/Resources/resource_body_grid.dart index c14f863..1cfc530 100644 --- a/lib/Screens/Resources/resource_body_grid.dart +++ b/lib/Screens/Resources/resource_body_grid.dart @@ -34,7 +34,7 @@ class _ResourceBodyGridState extends State { @override void initState() { resourcesToShow = widget.resources; - filterType = [resource_types[0], resource_types[1], resource_types[2]]; // resource_types[3] + filterType = [resource_types[0], resource_types[1]];//, resource_types[2]]; // resource_types[3] selectedTypes = resource_types; super.initState(); } diff --git a/lib/constants.dart b/lib/constants.dart index 153de07..a52be9a 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -16,7 +16,7 @@ const kSuccess = Color(0xFF8bc34a); const List section_types = ["Map", "Slider", "Video", "Web", "Menu", "Quizz", "Article"]; const List map_types = ["none", "normal", "satellite", "terrain", "hybrid"]; const List languages = ["FR", "NL", "EN", "DE"]; -const List resource_types = ["image", "image url", "video url"]; // "video", +const List resource_types = ["image", "image url"]; // "video url" , "video", /* const kTextStyle = TextStyle( diff --git a/lib/main.dart b/lib/main.dart index 33b846a..dd8cbe9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -49,7 +49,7 @@ class _MyAppState extends State { child: MaterialApp( scrollBehavior: MyCustomScrollBehavior(), debugShowCheckedModeBanner: false, - title: 'Manager App', + title: 'MyMuseum App', initialRoute: widget.initialRoute, /*supportedLocales: [ const Locale('en', 'US'), diff --git a/pubspec.lock b/pubspec.lock index f583881..43632f3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,13 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "3.3.0" args: dependency: transitive description: @@ -29,6 +36,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + barcode: + dependency: transitive + description: + name: barcode + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" boolean_selector: dependency: transitive description: @@ -184,6 +198,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.4" + image: + dependency: transitive + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.3" intl: dependency: transitive description: @@ -261,6 +282,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" + path_parsing: + dependency: transitive + description: + name: path_parsing + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.1" + pdf: + dependency: "direct main" + description: + name: pdf + url: "https://pub.dartlang.org" + source: hosted + version: "3.6.4" pedantic: dependency: transitive description: @@ -268,6 +303,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.11.1" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "4.4.0" plugin_platform_interface: dependency: transitive description: @@ -413,6 +455,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.5.2" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "5.3.1" sdks: dart: ">=2.15.0 <3.0.0" flutter: ">=2.10.0" diff --git a/pubspec.yaml b/pubspec.yaml index 42e2ba8..8b20374 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,7 +41,7 @@ dependencies: #path_provider: ^2.0.2 encrypt: ^5.0.0 qr_flutter: ^4.0.0 - pdf: ^3.8.1 + pdf: ^3.6.0 #msix: ^2.1.3 #window_size: # git: @@ -92,6 +92,11 @@ msix_config: architecture: x64 capabilities: 'internetClient' + fonts: + - family: OpenSans + fonts: + - asset: fonts/OpenSans-Medium.ttf + # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware.