PDF QRCode download + code clean
This commit is contained in:
parent
11766b2fac
commit
98e066c712
BIN
assets/fonts/OpenSans-Medium.ttf
Normal file
BIN
assets/fonts/OpenSans-Medium.ttf
Normal file
Binary file not shown.
73
lib/Helpers/PDFHelper.dart
Normal file
73
lib/Helpers/PDFHelper.dart
Normal file
@ -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<SectionDTO> 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 <pw.Widget> [
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -99,7 +99,7 @@ class _ArticleConfigState extends State<ArticleConfig> {
|
|||||||
isChecked: articleDTO.isContentTop,
|
isChecked: articleDTO.isContentTop,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
print(value);
|
//print(value);
|
||||||
articleDTO.isContentTop = value;
|
articleDTO.isContentTop = value;
|
||||||
widget.onChanged(jsonEncode(articleDTO).toString());
|
widget.onChanged(jsonEncode(articleDTO).toString());
|
||||||
});
|
});
|
||||||
|
|||||||
@ -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<SectionDTO> sections;
|
||||||
|
const DownloadPDF({
|
||||||
|
Key key,
|
||||||
|
this.sections,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_DownloadPDFState createState() => _DownloadPDFState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DownloadPDFState extends State<DownloadPDF> {
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final appContext = Provider.of<AppContext>(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)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -89,9 +89,7 @@ class _QuizzConfigState extends State<QuizzConfig> {
|
|||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
setState(() {
|
setState(() {
|
||||||
print("BAAAD");
|
|
||||||
quizzDTO.badLevel = result;
|
quizzDTO.badLevel = result;
|
||||||
print(quizzDTO.badLevel);
|
|
||||||
widget.onChanged(jsonEncode(quizzDTO).toString());
|
widget.onChanged(jsonEncode(quizzDTO).toString());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -216,7 +214,6 @@ class _QuizzConfigState extends State<QuizzConfig> {
|
|||||||
right: 10,
|
right: 10,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
print("new question");
|
|
||||||
QuestionDTO result = await showNewOrUpdateQuestionQuizz(null, appContext, context, "Question");
|
QuestionDTO result = await showNewOrUpdateQuestionQuizz(null, appContext, context, "Question");
|
||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import 'package:provider/provider.dart';
|
|||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
import 'SubSection/Article/article_config.dart';
|
import 'SubSection/Article/article_config.dart';
|
||||||
|
import 'SubSection/Article/download_pdf.dart';
|
||||||
import 'SubSection/Map/map_config.dart';
|
import 'SubSection/Map/map_config.dart';
|
||||||
import 'SubSection/Menu/menu_config.dart';
|
import 'SubSection/Menu/menu_config.dart';
|
||||||
import 'SubSection/Quizz/quizz_config.dart';
|
import 'SubSection/Quizz/quizz_config.dart';
|
||||||
@ -97,6 +98,8 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(sectionDTO != null ? sectionDTO.label : "", style: TextStyle(fontSize: 30, fontWeight: FontWeight.w400)),
|
Text(sectionDTO != null ? sectionDTO.label : "", style: TextStyle(fontSize: 30, fontWeight: FontWeight.w400)),
|
||||||
|
if(sectionDTO.type == SectionType.article)
|
||||||
|
DownloadPDF(sections: [sectionDTO]),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
@ -260,7 +263,6 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
|
|||||||
textColor: Colors.white,
|
textColor: Colors.white,
|
||||||
fontSize: 15,
|
fontSize: 15,
|
||||||
press: () {
|
press: () {
|
||||||
print(sectionDTO);
|
|
||||||
delete(sectionDTO, appContext);
|
delete(sectionDTO, appContext);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -351,7 +353,7 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
|
|||||||
initialValue: sectionDTO.data,
|
initialValue: sectionDTO.data,
|
||||||
onChanged: (String data) {
|
onChanged: (String data) {
|
||||||
print("Received info in parent");
|
print("Received info in parent");
|
||||||
print(data);
|
//print(data);
|
||||||
sectionDTO.data = data;
|
sectionDTO.data = data;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -360,17 +362,16 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
|
|||||||
initialValue: sectionDTO.data,
|
initialValue: sectionDTO.data,
|
||||||
onChanged: (String data) {
|
onChanged: (String data) {
|
||||||
print("Received info in parent - quizz");
|
print("Received info in parent - quizz");
|
||||||
print(data);
|
//print(data);
|
||||||
sectionDTO.data = data;
|
sectionDTO.data = data;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
case SectionType.article:
|
case SectionType.article:
|
||||||
print(sectionDTO.data);
|
|
||||||
return ArticleConfig(
|
return ArticleConfig(
|
||||||
initialValue: sectionDTO.data,
|
initialValue: sectionDTO.data,
|
||||||
onChanged: (String data) {
|
onChanged: (String data) {
|
||||||
print("Received info in parent - article");
|
print("Received info in parent - article");
|
||||||
print(data);
|
//print(data);
|
||||||
sectionDTO.data = data;
|
sectionDTO.data = data;
|
||||||
save(false, sectionDTO, appContext);
|
save(false, sectionDTO, appContext);
|
||||||
},
|
},
|
||||||
@ -381,6 +382,6 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
|
|||||||
|
|
||||||
Future<SectionDTO> getSection(String sectionId, Client client) async {
|
Future<SectionDTO> getSection(String sectionId, Client client) async {
|
||||||
SectionDTO section = await client.sectionApi.sectionGetDetail(sectionId);
|
SectionDTO section = await client.sectionApi.sectionGetDetail(sectionId);
|
||||||
print(section);
|
//print(section);
|
||||||
return section;
|
return section;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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/rounded_button.dart';
|
||||||
import 'package:manager_app/Components/string_input_container.dart';
|
import 'package:manager_app/Components/string_input_container.dart';
|
||||||
import 'package:manager_app/Helpers/FileHelper.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/Models/managerContext.dart';
|
||||||
import 'package:manager_app/Screens/Configurations/section_reorderList.dart';
|
import 'package:manager_app/Screens/Configurations/section_reorderList.dart';
|
||||||
import 'package:manager_app/app_context.dart';
|
import 'package:manager_app/app_context.dart';
|
||||||
@ -223,6 +224,17 @@ class _ConfigurationDetailScreenState extends State<ConfigurationDetailScreen> {
|
|||||||
configurationDTO.isMobile = value;
|
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);
|
||||||
|
},
|
||||||
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|||||||
@ -137,7 +137,7 @@ Future<List<ConfigurationDTO>> getConfigurations(dynamic appContext) async {
|
|||||||
List<ConfigurationDTO> configurations = await appContext.getContext().clientAPI.configurationApi.configurationGet();
|
List<ConfigurationDTO> configurations = await appContext.getContext().clientAPI.configurationApi.configurationGet();
|
||||||
print("number of configurations " + configurations.length.toString());
|
print("number of configurations " + configurations.length.toString());
|
||||||
configurations.forEach((element) {
|
configurations.forEach((element) {
|
||||||
print(element);
|
//print(element);
|
||||||
});
|
});
|
||||||
return configurations;
|
return configurations;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -226,7 +226,7 @@ Future<List<DeviceDTO>> getDevices(dynamic appContext) async {
|
|||||||
List<DeviceDTO> devices = await appContext.getContext().clientAPI.deviceApi.deviceGet();
|
List<DeviceDTO> devices = await appContext.getContext().clientAPI.deviceApi.deviceGet();
|
||||||
print("number of devices " + devices.length.toString());
|
print("number of devices " + devices.length.toString());
|
||||||
devices.forEach((element) {
|
devices.forEach((element) {
|
||||||
print(element);
|
//print(element);
|
||||||
});
|
});
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ class _BodyState extends State<Body> {
|
|||||||
MenuSection configurations = new MenuSection(name: "Configurations", type: "configurations", order: 1);
|
MenuSection configurations = new MenuSection(name: "Configurations", type: "configurations", order: 1);
|
||||||
MenuSection resources = new MenuSection(name: "Ressources", type: "resources", order: 2);
|
MenuSection resources = new MenuSection(name: "Ressources", type: "resources", order: 2);
|
||||||
|
|
||||||
Menu menu = new Menu(title: "Manager");
|
Menu menu = new Menu(title: "MyMuseum");
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|||||||
@ -34,7 +34,7 @@ class _ResourceBodyGridState extends State<ResourceBodyGrid> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
resourcesToShow = widget.resources;
|
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;
|
selectedTypes = resource_types;
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ const kSuccess = Color(0xFF8bc34a);
|
|||||||
const List<String> section_types = ["Map", "Slider", "Video", "Web", "Menu", "Quizz", "Article"];
|
const List<String> section_types = ["Map", "Slider", "Video", "Web", "Menu", "Quizz", "Article"];
|
||||||
const List<String> map_types = ["none", "normal", "satellite", "terrain", "hybrid"];
|
const List<String> map_types = ["none", "normal", "satellite", "terrain", "hybrid"];
|
||||||
const List<String> languages = ["FR", "NL", "EN", "DE"];
|
const List<String> languages = ["FR", "NL", "EN", "DE"];
|
||||||
const List<String> resource_types = ["image", "image url", "video url"]; // "video",
|
const List<String> resource_types = ["image", "image url"]; // "video url" , "video",
|
||||||
|
|
||||||
/*
|
/*
|
||||||
const kTextStyle = TextStyle(
|
const kTextStyle = TextStyle(
|
||||||
|
|||||||
@ -49,7 +49,7 @@ class _MyAppState extends State<MyApp> {
|
|||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
scrollBehavior: MyCustomScrollBehavior(),
|
scrollBehavior: MyCustomScrollBehavior(),
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
title: 'Manager App',
|
title: 'MyMuseum App',
|
||||||
initialRoute: widget.initialRoute,
|
initialRoute: widget.initialRoute,
|
||||||
/*supportedLocales: [
|
/*supportedLocales: [
|
||||||
const Locale('en', 'US'),
|
const Locale('en', 'US'),
|
||||||
|
|||||||
49
pubspec.lock
49
pubspec.lock
@ -1,6 +1,13 @@
|
|||||||
# Generated by pub
|
# Generated by pub
|
||||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||||
packages:
|
packages:
|
||||||
|
archive:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: archive
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "3.3.0"
|
||||||
args:
|
args:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -29,6 +36,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0"
|
version: "2.1.0"
|
||||||
|
barcode:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: barcode
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.0"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -184,6 +198,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.4"
|
version: "3.1.4"
|
||||||
|
image:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: image
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "3.1.3"
|
||||||
intl:
|
intl:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -261,6 +282,20 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.0"
|
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:
|
pedantic:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -268,6 +303,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.11.1"
|
version: "1.11.1"
|
||||||
|
petitparser:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: petitparser
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "4.4.0"
|
||||||
plugin_platform_interface:
|
plugin_platform_interface:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -413,6 +455,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.5.2"
|
version: "2.5.2"
|
||||||
|
xml:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: xml
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "5.3.1"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.15.0 <3.0.0"
|
dart: ">=2.15.0 <3.0.0"
|
||||||
flutter: ">=2.10.0"
|
flutter: ">=2.10.0"
|
||||||
|
|||||||
@ -41,7 +41,7 @@ dependencies:
|
|||||||
#path_provider: ^2.0.2
|
#path_provider: ^2.0.2
|
||||||
encrypt: ^5.0.0
|
encrypt: ^5.0.0
|
||||||
qr_flutter: ^4.0.0
|
qr_flutter: ^4.0.0
|
||||||
pdf: ^3.8.1
|
pdf: ^3.6.0
|
||||||
#msix: ^2.1.3
|
#msix: ^2.1.3
|
||||||
#window_size:
|
#window_size:
|
||||||
# git:
|
# git:
|
||||||
@ -92,6 +92,11 @@ msix_config:
|
|||||||
architecture: x64
|
architecture: x64
|
||||||
capabilities: 'internetClient'
|
capabilities: 'internetClient'
|
||||||
|
|
||||||
|
fonts:
|
||||||
|
- family: OpenSans
|
||||||
|
fonts:
|
||||||
|
- asset: fonts/OpenSans-Medium.ttf
|
||||||
|
|
||||||
# An image asset can refer to one or more resolution-specific "variants", see
|
# An image asset can refer to one or more resolution-specific "variants", see
|
||||||
# https://flutter.dev/assets-and-images/#resolution-aware.
|
# https://flutter.dev/assets-and-images/#resolution-aware.
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user