import 'dart:convert'; import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:manager_app/Components/check_input_container.dart'; import 'package:manager_app/Components/confirmation_dialog.dart'; import 'package:manager_app/Components/fetch_section_icon.dart'; import 'package:manager_app/Components/resource_input_container.dart'; import 'package:manager_app/Components/common_loader.dart'; import 'package:manager_app/Components/message_notification.dart'; import 'package:manager_app/Components/multi_string_input_container.dart'; import 'package:manager_app/Components/number_input_container.dart'; import 'package:manager_app/Components/rounded_button.dart'; import 'package:manager_app/Components/string_input_container.dart'; import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/Screens/Configurations/Section/SubSection/Video/video_config.dart'; import 'package:manager_app/Screens/Configurations/Section/SubSection/WebOrVideo/web_config.dart'; import 'package:manager_app/app_context.dart'; import 'package:manager_app/client.dart'; import 'package:manager_app/constants.dart'; import 'package:manager_api_new/api.dart'; import 'package:provider/provider.dart'; import 'package:intl/intl.dart'; import 'SubSection/Agenda/agenda_config.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/PDF/PDF_config.dart'; import 'SubSection/Game/game_config.dart'; import 'SubSection/Quizz/quizz_config.dart'; import 'SubSection/Slider/slider_config.dart'; import 'package:qr_flutter/qr_flutter.dart'; import 'package:pasteboard/pasteboard.dart'; import 'dart:html' as html; import 'SubSection/Weather/weather_config.dart'; import 'SubSection/Event/event_config.dart'; class SectionDetailScreen extends StatefulWidget { final String id; SectionDetailScreen({Key? key, required this.id}) : super(key: key); @override _SectionDetailScreenState createState() => _SectionDetailScreenState(); } class _SectionDetailScreenState extends State { late SectionDTO sectionDTO; Object? sectionDetailDTO; String? lastLoadedSectionId; final GlobalKey globalKey = GlobalKey(); late Future _sectionFuture; Future _loadSection() { final appContext = Provider.of(context, listen: false); return getSection( widget.id, (appContext.getContext() as ManagerAppContext).clientAPI!); } @override void initState() { super.initState(); _sectionFuture = _loadSection(); } @override void didUpdateWidget(SectionDetailScreen oldWidget) { super.didUpdateWidget(oldWidget); if (oldWidget.id != widget.id) { sectionDetailDTO = null; lastLoadedSectionId = null; _sectionFuture = _loadSection(); } } @override Widget build(BuildContext context) { final appContext = Provider.of(context); Size size = MediaQuery.of(context).size; Object? rawSectionData; return FutureBuilder( future: _sectionFuture, builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { rawSectionData = snapshot.data; var nullableSection = SectionDTO.fromJson(rawSectionData); if (nullableSection != null) { sectionDTO = nullableSection; // Only initialize sectionDetailDTO if it's not already loaded for this section if (sectionDetailDTO == null || lastLoadedSectionId != widget.id) { _initializeSectionDetail(rawSectionData); lastLoadedSectionId = widget.id; } return Stack( fit: StackFit.expand, children: [ bodySection( rawSectionData, size, appContext, context), Align( alignment: AlignmentDirectional.bottomCenter, child: Container( height: 80, child: getButtons(sectionDTO, appContext), ), ) ], ); } else { return Center( child: Text( "Une erreur est survenue lors de la récupération de la section")); } } else if (snapshot.connectionState == ConnectionState.none) { return Text("No data"); } else { return Center( child: Container( height: size.height * 0.2, child: CommonLoader())); } }); } Widget bodySection(Object? rawSectionDTO, Size size, AppContext appContext, BuildContext context) { ManagerAppContext managerAppContext = appContext.getContext(); //SectionDTO? sectionDTO = SectionDTO.fromJson(rawSectionDTO); return SingleChildScrollView( child: Column( //mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Container( //color: Colors.orangeAccent, height: 82, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Align( alignment: AlignmentDirectional.bottomStart, child: Padding( padding: const EdgeInsets.all(3.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Padding( padding: const EdgeInsets.all(8.0), child: Icon( getSectionIcon(sectionDTO.type), color: kPrimaryColor, size: 25, ), ), Text(sectionDTO.label!, style: TextStyle( fontSize: 30, fontWeight: FontWeight.w400)), //if((appContext.getContext() as ManagerAppContext).selectedConfiguration!.isMobile!) DownloadPDF(sections: [sectionDTO]), ], ), Padding( padding: const EdgeInsets.all(5.0), child: Text( DateFormat('dd/MM/yyyy') .format(sectionDTO.dateCreation!), style: TextStyle( fontSize: 15, fontWeight: FontWeight.w200)), ), ], ), )), Padding( padding: const EdgeInsets.all(5.0), child: Align( alignment: AlignmentDirectional.centerEnd, child: InkWell( onTap: () { ManagerAppContext managerAppContext = appContext.getContext(); managerAppContext.selectedSection = null; appContext.setContext(managerAppContext); }, child: Container( child: Icon( Icons.arrow_back, color: kPrimaryColor, size: 50.0, ))), ), ) ], ), ), // TITLE Container( //color: Colors.blue, child: Padding( padding: const EdgeInsets.all(5.0), child: Container( child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ //if((appContext.getContext() as ManagerAppContext).selectedConfiguration!.isMobile!) Column( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ InkWell( onTap: () async { var image = await _captureAndSharePng( globalKey, sectionDTO.id!); await readAndWriteFiles(image); showNotification( kSuccess, kWhite, 'Ce QR code a été copié dans le presse papier', context, null); }, child: Container( width: size.width * 0.1, height: 125, child: RepaintBoundary( key: globalKey, child: QrImageView( padding: EdgeInsets.only( left: 5.0, top: 5.0, bottom: 5.0, right: 5.0), data: "${managerAppContext.host!.replaceFirst("api", "web")}/${managerAppContext.instanceId}/${managerAppContext.selectedConfiguration!.id}/${sectionDTO.id!}", version: QrVersions.auto, size: 50.0, ), ), ), ), SelectableText(sectionDTO.id!, style: new TextStyle(fontSize: 15)) ], ), CheckInputContainer( label: "Beacon :", isChecked: sectionDTO.isBeacon!, onChanged: (value) { setState(() { sectionDTO.isBeacon = value; save(false, appContext); }); }, ), if (sectionDTO.isBeacon!) NumberInputContainer( label: "Identifiant Beacon :", initialValue: sectionDTO.beaconId != null ? sectionDTO.beaconId! : 0, isSmall: true, onChanged: (value) { try { sectionDTO.beaconId = int.parse(value); } catch (e) { print('BeaconId not a number'); showNotification( Colors.orange, kWhite, 'Cela doit être un chiffre', context, null); } }, ), ], ), Column( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox( height: 100, child: StringInputContainer( label: "Identifiant :", initialValue: sectionDTO.label, onChanged: (String value) { sectionDTO.label = value; }, ), ), SizedBox( height: 100, child: MultiStringInputContainer( label: "Titre affiché:", modalLabel: "Titre", color: kPrimaryColor, initialValue: sectionDTO.title!, onGetResult: (value) { if (sectionDTO.title! != value) { sectionDTO.title = value; save(true, appContext); } }, maxLines: 1, isHTML: true, isTitle: true, ), ), /*if(!(appContext.getContext() as ManagerAppContext).selectedConfiguration!.isMobile!) MultiStringInputContainer( label: "Description affichée:", modalLabel: "Description", color: kPrimaryColor, isHTML: true, initialValue: sectionDTO.description!, isMandatory: false, onGetResult: (value) { if (sectionDTO.description != value) { sectionDTO.description = value!; save(true, appContext); } }, maxLines: 2, isTitle: true, ),*/ ], ), Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ ResourceInputContainer( label: "Image :", initialValue: sectionDTO.imageId, color: kPrimaryColor, onChanged: (ResourceDTO resource) { if (resource.id == null) { sectionDTO.imageId = null; sectionDTO.imageSource = null; } else { sectionDTO.imageId = resource.id; sectionDTO.imageSource = resource.url; } }, ), ], ) ], ), ), ], ), ), ), ), // FIELDS SECTION Container( //width: size.width * 0.8, child: Padding( padding: const EdgeInsets.all(10.0), child: getSpecificData(rawSectionDTO, appContext), ), decoration: BoxDecoration( //color: Colors.lightGreen, borderRadius: BorderRadius.circular(30), border: Border.all(width: 1.5, color: kSecond)), ), ], ), ); } getButtons(SectionDTO sectionDTO, AppContext appContext) { return Align( alignment: AlignmentDirectional.bottomCenter, child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ Padding( padding: const EdgeInsets.all(10.0), child: RoundedButton( text: "Annuler", icon: Icons.undo, color: Colors.grey, textColor: Colors.white, fontSize: 15, press: () { cancel(appContext); }, ), ), Padding( padding: const EdgeInsets.all(8.0), child: RoundedButton( text: "Supprimer", icon: Icons.delete, color: kError, textColor: Colors.white, fontSize: 15, press: () { delete(appContext); }, ), ), Padding( padding: const EdgeInsets.all(8.0), child: RoundedButton( text: "Sauvegarder", icon: Icons.done, color: kSuccess, textColor: Colors.white, fontSize: 15, press: () { save(false, appContext); }, ), ), ], ), ); } Future cancel(AppContext appContext) async { ManagerAppContext managerAppContext = appContext.getContext(); Object? rawData = await (appContext.getContext() as ManagerAppContext) .clientAPI! .sectionApi! .sectionGetDetail(sectionDTO.id!); var nullableSection = SectionDTO.fromJson(rawData); if (nullableSection != null) { managerAppContext.selectedSection = nullableSection!; appContext.setContext(managerAppContext); } } Future delete(AppContext appContext) async { showConfirmationDialog( "Êtes-vous sûr de vouloir supprimer cette section ?", () {}, () async { ManagerAppContext managerAppContext = appContext.getContext(); await managerAppContext.clientAPI!.sectionApi! .sectionDelete(sectionDTO.id!); managerAppContext.selectedSection = null; appContext.setContext(managerAppContext); }, context); } Future save(bool isTraduction, AppContext appContext) async { updateSectionDetail(); var sectionResult = await (appContext.getContext() as ManagerAppContext) .clientAPI! .sectionApi! .sectionUpdate(sectionDetailDTO!); SectionDTO? section = SectionDTO.fromJson(sectionResult); ManagerAppContext managerAppContext = appContext.getContext(); managerAppContext.selectedSection = section; appContext.setContext(managerAppContext); if (isTraduction) { showNotification( kSuccess, kWhite, 'Les traductions de la section ont été sauvegardées avec succès', context, null); } else { showNotification(kSuccess, kWhite, 'La section a été sauvegardée avec succès', context, null); } } getSpecificData(Object? rawSectionData, AppContext appContext) { switch (sectionDTO.type) { case SectionType.Map: return MapConfig( initialValue: sectionDetailDTO as MapDTO, onChanged: (MapDTO changedMap) { sectionDetailDTO = changedMap; }, ); case SectionType.Slider: return SliderConfig( initialValue: sectionDetailDTO as SliderDTO, onChanged: (SliderDTO changedSlider) { sectionDetailDTO = changedSlider; }, ); case SectionType.Video: return VideoConfig( label: "Url de la vidéo:", initialValue: sectionDetailDTO as VideoDTO, onChanged: (VideoDTO updatedWebDTO) { sectionDetailDTO = updatedWebDTO; }, ); case SectionType.Web: return WebConfig( label: "Url du site web:", initialValue: sectionDetailDTO as WebDTO, onChanged: (WebDTO updatedWebDTO) { sectionDetailDTO = updatedWebDTO; }, ); case SectionType.Menu: return MenuConfig( initialValue: sectionDetailDTO as MenuDTO, onChanged: (String data) { //sectionDTO.data = data; }, ); case SectionType.Quiz: return QuizzConfig( initialValue: sectionDetailDTO as QuizDTO, onChanged: (QuizDTO updatedQuiz) { sectionDetailDTO = updatedQuiz; }, ); case SectionType.Article: return ArticleConfig( initialValue: sectionDetailDTO as ArticleDTO, onChanged: (ArticleDTO changedArticle) { sectionDetailDTO = changedArticle; }, ); case SectionType.Pdf: return PDFConfig( initialValue: sectionDetailDTO as PdfDTO, onChanged: (PdfDTO changedPDF) { sectionDetailDTO = changedPDF; }, ); case SectionType.Game: return GameConfig( key: ValueKey(sectionDTO.id), initialValue: sectionDetailDTO as GameDTO, onChanged: (GameDTO updatedGame) { sectionDetailDTO = updatedGame; }, ); case SectionType.Agenda: return AgendaConfig( initialValue: sectionDetailDTO as AgendaDTO, onChanged: (AgendaDTO updatedAgenda) { sectionDetailDTO = updatedAgenda; }, ); case SectionType.Weather: return WeatherConfig( initialValue: sectionDetailDTO as WeatherDTO, onChanged: (WeatherDTO updatedWeather) { sectionDetailDTO = updatedWeather; }, ); case SectionType.Event: return EventConfig( initialValue: sectionDetailDTO as SectionEventDTO, onChanged: (SectionEventDTO updatedEvent) { sectionDetailDTO = updatedEvent; }, ); } } _initializeSectionDetail(Object? rawSectionData) { if (rawSectionData == null) return; switch (sectionDTO.type) { case SectionType.Map: sectionDetailDTO = MapDTO.fromJson(rawSectionData)!; break; case SectionType.Slider: sectionDetailDTO = SliderDTO.fromJson(rawSectionData)!; break; case SectionType.Video: sectionDetailDTO = VideoDTO.fromJson(rawSectionData)!; break; case SectionType.Web: sectionDetailDTO = WebDTO.fromJson(rawSectionData)!; break; case SectionType.Menu: sectionDetailDTO = MenuDTO.fromJson(rawSectionData)!; break; case SectionType.Quiz: sectionDetailDTO = QuizDTO.fromJson(rawSectionData)!; break; case SectionType.Article: sectionDetailDTO = ArticleDTO.fromJson(rawSectionData)!; break; case SectionType.Pdf: sectionDetailDTO = PdfDTO.fromJson(rawSectionData)!; break; case SectionType.Game: sectionDetailDTO = GameDTO.fromJson(rawSectionData)!; break; case SectionType.Agenda: sectionDetailDTO = AgendaDTO.fromJson(rawSectionData)!; break; case SectionType.Weather: sectionDetailDTO = WeatherDTO.fromJson(rawSectionData)!; break; case SectionType.Event: sectionDetailDTO = SectionEventDTO.fromJson(rawSectionData)!; break; } } updateSectionDetail() { switch (sectionDTO.type) { case SectionType.Map: (sectionDetailDTO as MapDTO).id = sectionDTO.id; (sectionDetailDTO as MapDTO).order = sectionDTO.order; (sectionDetailDTO as MapDTO).dateCreation = sectionDTO.dateCreation; (sectionDetailDTO as MapDTO).type = sectionDTO.type; (sectionDetailDTO as MapDTO).instanceId = sectionDTO.instanceId; (sectionDetailDTO as MapDTO).configurationId = sectionDTO.configurationId; (sectionDetailDTO as MapDTO).isSubSection = sectionDTO.isSubSection; (sectionDetailDTO as MapDTO).parentId = sectionDTO.parentId; (sectionDetailDTO as MapDTO).label = sectionDTO.label; (sectionDetailDTO as MapDTO).title = sectionDTO.title; (sectionDetailDTO as MapDTO).description = sectionDTO.description; (sectionDetailDTO as MapDTO).imageId = sectionDTO.imageId; (sectionDetailDTO as MapDTO).imageSource = sectionDTO.imageSource; (sectionDetailDTO as MapDTO).isBeacon = sectionDTO.isBeacon; (sectionDetailDTO as MapDTO).beaconId = sectionDTO.beaconId; (sectionDetailDTO as MapDTO).latitude = sectionDTO.latitude; (sectionDetailDTO as MapDTO).longitude = sectionDTO.longitude; (sectionDetailDTO as MapDTO).meterZoneGPS = sectionDTO.meterZoneGPS; break; case SectionType.Slider: (sectionDetailDTO as SliderDTO).id = sectionDTO.id; (sectionDetailDTO as SliderDTO).order = sectionDTO.order; (sectionDetailDTO as SliderDTO).dateCreation = sectionDTO.dateCreation; (sectionDetailDTO as SliderDTO).type = sectionDTO.type; (sectionDetailDTO as SliderDTO).instanceId = sectionDTO.instanceId; (sectionDetailDTO as SliderDTO).configurationId = sectionDTO.configurationId; (sectionDetailDTO as SliderDTO).isSubSection = sectionDTO.isSubSection; (sectionDetailDTO as SliderDTO).parentId = sectionDTO.parentId; (sectionDetailDTO as SliderDTO).label = sectionDTO.label; (sectionDetailDTO as SliderDTO).title = sectionDTO.title; (sectionDetailDTO as SliderDTO).description = sectionDTO.description; (sectionDetailDTO as SliderDTO).imageId = sectionDTO.imageId; (sectionDetailDTO as SliderDTO).imageSource = sectionDTO.imageSource; (sectionDetailDTO as SliderDTO).isBeacon = sectionDTO.isBeacon; (sectionDetailDTO as SliderDTO).beaconId = sectionDTO.beaconId; (sectionDetailDTO as SliderDTO).latitude = sectionDTO.latitude; (sectionDetailDTO as SliderDTO).longitude = sectionDTO.longitude; (sectionDetailDTO as SliderDTO).meterZoneGPS = sectionDTO.meterZoneGPS; break; case SectionType.Video: (sectionDetailDTO as VideoDTO).id = sectionDTO.id; (sectionDetailDTO as VideoDTO).order = sectionDTO.order; (sectionDetailDTO as VideoDTO).dateCreation = sectionDTO.dateCreation; (sectionDetailDTO as VideoDTO).type = sectionDTO.type; (sectionDetailDTO as VideoDTO).instanceId = sectionDTO.instanceId; (sectionDetailDTO as VideoDTO).configurationId = sectionDTO.configurationId; (sectionDetailDTO as VideoDTO).isSubSection = sectionDTO.isSubSection; (sectionDetailDTO as VideoDTO).parentId = sectionDTO.parentId; (sectionDetailDTO as VideoDTO).label = sectionDTO.label; (sectionDetailDTO as VideoDTO).title = sectionDTO.title; (sectionDetailDTO as VideoDTO).description = sectionDTO.description; (sectionDetailDTO as VideoDTO).imageId = sectionDTO.imageId; (sectionDetailDTO as VideoDTO).imageSource = sectionDTO.imageSource; (sectionDetailDTO as VideoDTO).isBeacon = sectionDTO.isBeacon; (sectionDetailDTO as VideoDTO).beaconId = sectionDTO.beaconId; (sectionDetailDTO as VideoDTO).latitude = sectionDTO.latitude; (sectionDetailDTO as VideoDTO).longitude = sectionDTO.longitude; (sectionDetailDTO as VideoDTO).meterZoneGPS = sectionDTO.meterZoneGPS; break; case SectionType.Web: (sectionDetailDTO as WebDTO).id = sectionDTO.id; (sectionDetailDTO as WebDTO).order = sectionDTO.order; (sectionDetailDTO as WebDTO).dateCreation = sectionDTO.dateCreation; (sectionDetailDTO as WebDTO).type = sectionDTO.type; (sectionDetailDTO as WebDTO).instanceId = sectionDTO.instanceId; (sectionDetailDTO as WebDTO).configurationId = sectionDTO.configurationId; (sectionDetailDTO as WebDTO).isSubSection = sectionDTO.isSubSection; (sectionDetailDTO as WebDTO).parentId = sectionDTO.parentId; (sectionDetailDTO as WebDTO).label = sectionDTO.label; (sectionDetailDTO as WebDTO).title = sectionDTO.title; (sectionDetailDTO as WebDTO).description = sectionDTO.description; (sectionDetailDTO as WebDTO).imageId = sectionDTO.imageId; (sectionDetailDTO as WebDTO).imageSource = sectionDTO.imageSource; (sectionDetailDTO as WebDTO).isBeacon = sectionDTO.isBeacon; (sectionDetailDTO as WebDTO).beaconId = sectionDTO.beaconId; (sectionDetailDTO as WebDTO).latitude = sectionDTO.latitude; (sectionDetailDTO as WebDTO).longitude = sectionDTO.longitude; (sectionDetailDTO as WebDTO).meterZoneGPS = sectionDTO.meterZoneGPS; break; case SectionType.Menu: (sectionDetailDTO as MenuDTO).id = sectionDTO.id; (sectionDetailDTO as MenuDTO).order = sectionDTO.order; (sectionDetailDTO as MenuDTO).dateCreation = sectionDTO.dateCreation; (sectionDetailDTO as MenuDTO).type = sectionDTO.type; (sectionDetailDTO as MenuDTO).instanceId = sectionDTO.instanceId; (sectionDetailDTO as MenuDTO).configurationId = sectionDTO.configurationId; (sectionDetailDTO as MenuDTO).isSubSection = sectionDTO.isSubSection; (sectionDetailDTO as MenuDTO).parentId = sectionDTO.parentId; (sectionDetailDTO as MenuDTO).label = sectionDTO.label; (sectionDetailDTO as MenuDTO).title = sectionDTO.title; (sectionDetailDTO as MenuDTO).description = sectionDTO.description; (sectionDetailDTO as MenuDTO).imageId = sectionDTO.imageId; (sectionDetailDTO as MenuDTO).imageSource = sectionDTO.imageSource; (sectionDetailDTO as MenuDTO).isBeacon = sectionDTO.isBeacon; (sectionDetailDTO as MenuDTO).beaconId = sectionDTO.beaconId; (sectionDetailDTO as MenuDTO).latitude = sectionDTO.latitude; (sectionDetailDTO as MenuDTO).longitude = sectionDTO.longitude; (sectionDetailDTO as MenuDTO).meterZoneGPS = sectionDTO.meterZoneGPS; break; case SectionType.Quiz: (sectionDetailDTO as QuizDTO).id = sectionDTO.id; (sectionDetailDTO as QuizDTO).order = sectionDTO.order; (sectionDetailDTO as QuizDTO).dateCreation = sectionDTO.dateCreation; (sectionDetailDTO as QuizDTO).type = sectionDTO.type; (sectionDetailDTO as QuizDTO).instanceId = sectionDTO.instanceId; (sectionDetailDTO as QuizDTO).configurationId = sectionDTO.configurationId; (sectionDetailDTO as QuizDTO).isSubSection = sectionDTO.isSubSection; (sectionDetailDTO as QuizDTO).parentId = sectionDTO.parentId; (sectionDetailDTO as QuizDTO).label = sectionDTO.label; (sectionDetailDTO as QuizDTO).title = sectionDTO.title; (sectionDetailDTO as QuizDTO).description = sectionDTO.description; (sectionDetailDTO as QuizDTO).imageId = sectionDTO.imageId; (sectionDetailDTO as QuizDTO).imageSource = sectionDTO.imageSource; (sectionDetailDTO as QuizDTO).isBeacon = sectionDTO.isBeacon; (sectionDetailDTO as QuizDTO).beaconId = sectionDTO.beaconId; (sectionDetailDTO as QuizDTO).latitude = sectionDTO.latitude; (sectionDetailDTO as QuizDTO).longitude = sectionDTO.longitude; (sectionDetailDTO as QuizDTO).meterZoneGPS = sectionDTO.meterZoneGPS; break; case SectionType.Article: (sectionDetailDTO as ArticleDTO).id = sectionDTO.id; (sectionDetailDTO as ArticleDTO).order = sectionDTO.order; (sectionDetailDTO as ArticleDTO).dateCreation = sectionDTO.dateCreation; (sectionDetailDTO as ArticleDTO).type = sectionDTO.type; (sectionDetailDTO as ArticleDTO).instanceId = sectionDTO.instanceId; (sectionDetailDTO as ArticleDTO).configurationId = sectionDTO.configurationId; (sectionDetailDTO as ArticleDTO).isSubSection = sectionDTO.isSubSection; (sectionDetailDTO as ArticleDTO).parentId = sectionDTO.parentId; (sectionDetailDTO as ArticleDTO).label = sectionDTO.label; (sectionDetailDTO as ArticleDTO).title = sectionDTO.title; (sectionDetailDTO as ArticleDTO).description = sectionDTO.description; (sectionDetailDTO as ArticleDTO).imageId = sectionDTO.imageId; (sectionDetailDTO as ArticleDTO).imageSource = sectionDTO.imageSource; (sectionDetailDTO as ArticleDTO).isBeacon = sectionDTO.isBeacon; (sectionDetailDTO as ArticleDTO).beaconId = sectionDTO.beaconId; (sectionDetailDTO as ArticleDTO).latitude = sectionDTO.latitude; (sectionDetailDTO as ArticleDTO).longitude = sectionDTO.longitude; (sectionDetailDTO as ArticleDTO).meterZoneGPS = sectionDTO.meterZoneGPS; break; case SectionType.Pdf: (sectionDetailDTO as PdfDTO).id = sectionDTO.id; (sectionDetailDTO as PdfDTO).order = sectionDTO.order; (sectionDetailDTO as PdfDTO).dateCreation = sectionDTO.dateCreation; (sectionDetailDTO as PdfDTO).type = sectionDTO.type; (sectionDetailDTO as PdfDTO).instanceId = sectionDTO.instanceId; (sectionDetailDTO as PdfDTO).configurationId = sectionDTO.configurationId; (sectionDetailDTO as PdfDTO).isSubSection = sectionDTO.isSubSection; (sectionDetailDTO as PdfDTO).parentId = sectionDTO.parentId; (sectionDetailDTO as PdfDTO).label = sectionDTO.label; (sectionDetailDTO as PdfDTO).title = sectionDTO.title; (sectionDetailDTO as PdfDTO).description = sectionDTO.description; (sectionDetailDTO as PdfDTO).imageId = sectionDTO.imageId; (sectionDetailDTO as PdfDTO).imageSource = sectionDTO.imageSource; (sectionDetailDTO as PdfDTO).isBeacon = sectionDTO.isBeacon; (sectionDetailDTO as PdfDTO).beaconId = sectionDTO.beaconId; (sectionDetailDTO as PdfDTO).latitude = sectionDTO.latitude; (sectionDetailDTO as PdfDTO).longitude = sectionDTO.longitude; (sectionDetailDTO as PdfDTO).meterZoneGPS = sectionDTO.meterZoneGPS; break; case SectionType.Game: (sectionDetailDTO as GameDTO).id = sectionDTO.id; (sectionDetailDTO as GameDTO).order = sectionDTO.order; (sectionDetailDTO as GameDTO).dateCreation = sectionDTO.dateCreation; (sectionDetailDTO as GameDTO).type = sectionDTO.type; (sectionDetailDTO as GameDTO).instanceId = sectionDTO.instanceId; (sectionDetailDTO as GameDTO).configurationId = sectionDTO.configurationId; (sectionDetailDTO as GameDTO).isSubSection = sectionDTO.isSubSection; (sectionDetailDTO as GameDTO).parentId = sectionDTO.parentId; (sectionDetailDTO as GameDTO).label = sectionDTO.label; (sectionDetailDTO as GameDTO).title = sectionDTO.title; (sectionDetailDTO as GameDTO).description = sectionDTO.description; (sectionDetailDTO as GameDTO).imageId = sectionDTO.imageId; (sectionDetailDTO as GameDTO).imageSource = sectionDTO.imageSource; (sectionDetailDTO as GameDTO).isBeacon = sectionDTO.isBeacon; (sectionDetailDTO as GameDTO).beaconId = sectionDTO.beaconId; (sectionDetailDTO as GameDTO).latitude = sectionDTO.latitude; (sectionDetailDTO as GameDTO).longitude = sectionDTO.longitude; (sectionDetailDTO as GameDTO).meterZoneGPS = sectionDTO.meterZoneGPS; break; case SectionType.Agenda: (sectionDetailDTO as AgendaDTO).id = sectionDTO.id; (sectionDetailDTO as AgendaDTO).order = sectionDTO.order; (sectionDetailDTO as AgendaDTO).dateCreation = sectionDTO.dateCreation; (sectionDetailDTO as AgendaDTO).type = sectionDTO.type; (sectionDetailDTO as AgendaDTO).instanceId = sectionDTO.instanceId; (sectionDetailDTO as AgendaDTO).configurationId = sectionDTO.configurationId; (sectionDetailDTO as AgendaDTO).isSubSection = sectionDTO.isSubSection; (sectionDetailDTO as AgendaDTO).parentId = sectionDTO.parentId; (sectionDetailDTO as AgendaDTO).label = sectionDTO.label; (sectionDetailDTO as AgendaDTO).title = sectionDTO.title; (sectionDetailDTO as AgendaDTO).description = sectionDTO.description; (sectionDetailDTO as AgendaDTO).imageId = sectionDTO.imageId; (sectionDetailDTO as AgendaDTO).imageSource = sectionDTO.imageSource; (sectionDetailDTO as AgendaDTO).isBeacon = sectionDTO.isBeacon; (sectionDetailDTO as AgendaDTO).beaconId = sectionDTO.beaconId; (sectionDetailDTO as AgendaDTO).latitude = sectionDTO.latitude; (sectionDetailDTO as AgendaDTO).longitude = sectionDTO.longitude; (sectionDetailDTO as AgendaDTO).meterZoneGPS = sectionDTO.meterZoneGPS; break; case SectionType.Weather: (sectionDetailDTO as WeatherDTO).id = sectionDTO.id; (sectionDetailDTO as WeatherDTO).order = sectionDTO.order; (sectionDetailDTO as WeatherDTO).dateCreation = sectionDTO.dateCreation; (sectionDetailDTO as WeatherDTO).type = sectionDTO.type; (sectionDetailDTO as WeatherDTO).instanceId = sectionDTO.instanceId; (sectionDetailDTO as WeatherDTO).configurationId = sectionDTO.configurationId; (sectionDetailDTO as WeatherDTO).isSubSection = sectionDTO.isSubSection; (sectionDetailDTO as WeatherDTO).parentId = sectionDTO.parentId; (sectionDetailDTO as WeatherDTO).label = sectionDTO.label; (sectionDetailDTO as WeatherDTO).title = sectionDTO.title; (sectionDetailDTO as WeatherDTO).description = sectionDTO.description; (sectionDetailDTO as WeatherDTO).imageId = sectionDTO.imageId; (sectionDetailDTO as WeatherDTO).imageSource = sectionDTO.imageSource; (sectionDetailDTO as WeatherDTO).isBeacon = sectionDTO.isBeacon; (sectionDetailDTO as WeatherDTO).beaconId = sectionDTO.beaconId; (sectionDetailDTO as WeatherDTO).latitude = sectionDTO.latitude; (sectionDetailDTO as WeatherDTO).longitude = sectionDTO.longitude; (sectionDetailDTO as WeatherDTO).meterZoneGPS = sectionDTO.meterZoneGPS; break; case SectionType.Event: (sectionDetailDTO as SectionEventDTO).id = sectionDTO.id; (sectionDetailDTO as SectionEventDTO).order = sectionDTO.order; (sectionDetailDTO as SectionEventDTO).dateCreation = sectionDTO.dateCreation; (sectionDetailDTO as SectionEventDTO).type = sectionDTO.type; (sectionDetailDTO as SectionEventDTO).instanceId = sectionDTO.instanceId; (sectionDetailDTO as SectionEventDTO).configurationId = sectionDTO.configurationId; (sectionDetailDTO as SectionEventDTO).isSubSection = sectionDTO.isSubSection; (sectionDetailDTO as SectionEventDTO).parentId = sectionDTO.parentId; (sectionDetailDTO as SectionEventDTO).label = sectionDTO.label; (sectionDetailDTO as SectionEventDTO).title = sectionDTO.title; (sectionDetailDTO as SectionEventDTO).description = sectionDTO.description; (sectionDetailDTO as SectionEventDTO).imageId = sectionDTO.imageId; (sectionDetailDTO as SectionEventDTO).imageSource = sectionDTO.imageSource; (sectionDetailDTO as SectionEventDTO).isBeacon = sectionDTO.isBeacon; (sectionDetailDTO as SectionEventDTO).beaconId = sectionDTO.beaconId; (sectionDetailDTO as SectionEventDTO).latitude = sectionDTO.latitude; (sectionDetailDTO as SectionEventDTO).longitude = sectionDTO.longitude; (sectionDetailDTO as SectionEventDTO).meterZoneGPS = sectionDTO.meterZoneGPS; break; } } } Future getSection(String sectionId, Client client) async { try { Object? section = await client.sectionApi!.sectionGetDetail(sectionId); return section; } catch (e) { print(e); return null; } } Future _captureAndSharePng( GlobalKey globalKey, String sectionId) async { try { RenderRepaintBoundary? boundary = globalKey.currentContext!.findRenderObject()! as RenderRepaintBoundary; var image = await boundary.toImage(); ByteData? byteData = await image.toByteData(format: ImageByteFormat.png); Uint8List pngBytes = byteData!.buffer.asUint8List(); final base64data = base64.encode(pngBytes); final a = html.AnchorElement(href: 'data:image/jpeg;base64,$base64data'); a.download = '$sectionId.jpg'; a.click(); return pngBytes; } catch (e) { print(e.toString()); return null; } } Future readAndWriteFiles(Uint8List? image) async { await Pasteboard.writeImage(image); final files = await Pasteboard.files(); print(files); }