manager-app/lib/Screens/Configurations/Section/section_detail_screen.dart
Thomas Fransolet 205f1ec933 Misc
2026-05-09 00:23:04 +02:00

895 lines
38 KiB
Dart

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/l10n/app_localizations.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/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<SectionDetailScreen> {
late SectionDTO sectionDTO;
Object? sectionDetailDTO;
String? lastLoadedSectionId;
final GlobalKey globalKey = GlobalKey();
late Future<Object?> _sectionFuture;
Future<Object?> _loadSection() {
final appContext = Provider.of<AppContext>(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<AppContext>(context);
return FutureBuilder(
future: _sectionFuture,
builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
Object? rawSectionData = snapshot.data;
var nullableSection = SectionDTO.fromJson(rawSectionData);
if (nullableSection != null) {
sectionDTO = nullableSection;
if (sectionDetailDTO == null || lastLoadedSectionId != widget.id) {
_initializeSectionDetail(rawSectionData);
lastLoadedSectionId = widget.id;
}
return _buildBody(rawSectionData, appContext);
} else {
return Center(child: Text(AppLocalizations.of(context)!.sectionLoadError));
}
} else if (snapshot.connectionState == ConnectionState.none) {
return Center(child: Text(AppLocalizations.of(context)!.noData));
}
return const Center(child: CommonLoader());
},
);
}
// ── Main layout ──
Widget _buildBody(Object? rawSectionData, AppContext appContext) {
final managerCtx = appContext.getContext() as ManagerAppContext;
final canEdit = managerCtx.canEdit;
final l = AppLocalizations.of(context)!;
return Column(
children: [
_buildHeader(appContext, l),
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
children: [
_cardIdentity(appContext, l),
const SizedBox(height: 12),
_cardQR(appContext, l),
const SizedBox(height: 12),
_cardTypeConfig(rawSectionData, appContext),
const SizedBox(height: 80),
],
),
),
),
_buildFooter(appContext, canEdit, l),
],
);
}
// ── Header ──
Widget _buildHeader(AppContext appContext, AppLocalizations l) {
final typeName = getSectionTypeName(sectionDTO.type);
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
color: kWhite,
border: Border(bottom: BorderSide(color: kSecond, width: 1)),
),
child: Row(
children: [
IconButton(
icon: const Icon(Icons.arrow_back, color: kPrimaryColor),
onPressed: () {
ManagerAppContext ctx = appContext.getContext();
ctx.selectedSection = null;
appContext.setContext(ctx);
},
),
const SizedBox(width: 8),
Icon(getSectionIcon(sectionDTO.type), color: kPrimaryColor, size: 22),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
sectionDTO.label ?? '',
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
overflow: TextOverflow.ellipsis,
),
Text(
DateFormat('dd/MM/yyyy').format(sectionDTO.dateCreation!),
style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w300, color: Colors.grey),
),
],
),
),
Chip(
label: Text(typeName.toUpperCase()),
backgroundColor: kPrimaryColor.withValues(alpha: 0.1),
labelStyle: const TextStyle(color: kPrimaryColor, fontWeight: FontWeight.w600, fontSize: 11),
side: BorderSide.none,
visualDensity: VisualDensity.compact,
),
const SizedBox(width: 8),
DownloadPDF(sections: [sectionDTO]),
],
),
);
}
// ── Footer ──
Widget _buildFooter(AppContext appContext, bool canEdit, AppLocalizations l) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
decoration: const BoxDecoration(
color: kWhite,
boxShadow: [BoxShadow(color: kSecond, blurRadius: 8, offset: Offset(0, -2))],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
OutlinedButton.icon(
icon: const Icon(Icons.undo, size: 16),
label: Text(l.cancel),
onPressed: () => cancel(appContext),
),
if (canEdit) ...[
const SizedBox(width: 8),
ElevatedButton.icon(
icon: const Icon(Icons.delete, size: 16, color: kWhite),
label: Text(l.delete, style: const TextStyle(color: kWhite)),
style: ElevatedButton.styleFrom(backgroundColor: kError),
onPressed: () => delete(appContext),
),
const SizedBox(width: 8),
ElevatedButton.icon(
icon: const Icon(Icons.done, size: 16, color: kWhite),
label: Text(l.save, style: const TextStyle(color: kWhite)),
style: ElevatedButton.styleFrom(backgroundColor: kPrimaryColor),
onPressed: () => save(false, appContext),
),
],
],
),
);
}
// ── Card Identité ──
Widget _cardIdentity(AppContext appContext, AppLocalizations l) {
return Card(
elevation: 0,
color: kWhite,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(l.identifierLabel.replaceAll(':', '').trim(),
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: kTitleTextColor)),
const SizedBox(height: 12),
LayoutBuilder(
builder: (context, constraints) {
final isWide = constraints.maxWidth > kBreakpointMobile;
final fields = Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
StringInputContainer(
label: l.identifierLabel,
initialValue: sectionDTO.label,
onChanged: (String value) => sectionDTO.label = value,
),
const SizedBox(height: 12),
MultiStringInputContainer(
label: l.displayTitleLabel,
modalLabel: l.messageTitle,
color: kPrimaryColor,
initialValue: sectionDTO.title!,
onGetResult: (value) {
if (sectionDTO.title! != value) {
sectionDTO.title = value;
save(true, appContext);
}
},
maxLines: 1,
isHTML: true,
isTitle: true,
),
],
);
final image = ResourceInputContainer(
label: l.imageLabel,
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;
}
},
);
if (isWide) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(flex: 3, child: fields),
const SizedBox(width: 16),
Expanded(flex: 2, child: image),
],
);
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
fields,
const SizedBox(height: 12),
image,
],
);
},
),
],
),
),
);
}
// ── Card QR / Beacon ──
Widget _cardQR(AppContext appContext, AppLocalizations l) {
final managerCtx = appContext.getContext() as ManagerAppContext;
final qrData = "${managerCtx.host!.replaceFirst("api", "web")}/${managerCtx.instanceId}/${managerCtx.selectedConfiguration!.id}/${sectionDTO.id!}";
return Card(
elevation: 0,
color: kWhite,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Theme(
data: Theme.of(context).copyWith(dividerColor: Colors.transparent),
child: ExpansionTile(
leading: const Icon(Icons.qr_code_2, color: kPrimaryColor),
title: const Text("QR Code / Identifiant",
style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: kTitleTextColor)),
childrenPadding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
children: [
Wrap(
spacing: 24,
runSpacing: 12,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
InkWell(
onTap: () async {
var image = await _captureAndSharePng(globalKey, sectionDTO.id!);
await readAndWriteFiles(image);
if (context.mounted) {
showNotification(kSuccess, kWhite, l.qrCodeCopied, context, null);
}
},
child: SizedBox(
width: 120,
height: 120,
child: RepaintBoundary(
key: globalKey,
child: QrImageView(
padding: const EdgeInsets.all(5.0),
data: qrData,
version: QrVersions.auto,
size: 50.0,
),
),
),
),
SelectableText(sectionDTO.id!, style: const TextStyle(fontSize: 13)),
],
),
const SizedBox(height: 12),
Wrap(
spacing: 16,
runSpacing: 8,
children: [
CheckInputContainer(
label: l.beaconLabel,
isChecked: sectionDTO.isBeacon!,
onChanged: (value) {
setState(() {
sectionDTO.isBeacon = value;
save(false, appContext);
});
},
),
if (sectionDTO.isBeacon!)
NumberInputContainer(
label: l.beaconIdLabel,
initialValue: sectionDTO.beaconId ?? 0,
isSmall: true,
onChanged: (value) {
try {
sectionDTO.beaconId = int.parse(value);
} catch (e) {
showNotification(Colors.orange, kWhite, l.beaconMustBeNumber, context, null);
}
},
),
],
),
],
),
),
);
}
// ── Card Type Config ──
Widget _cardTypeConfig(Object? rawSectionData, AppContext appContext) {
final typeName = getSectionTypeName(sectionDTO.type);
return Card(
elevation: 0,
color: kWhite,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Configuration $typeName",
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: kTitleTextColor)),
const SizedBox(height: 12),
getSpecificData(rawSectionData, appContext),
],
),
),
);
}
// ── Actions ──
Future<void> 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<void> delete(AppContext appContext) async {
showConfirmationDialog(
AppLocalizations.of(context)!.sectionDeleteConfirm, () {}, () async {
ManagerAppContext managerAppContext = appContext.getContext();
await managerAppContext.clientAPI!.sectionApi!
.sectionDelete(sectionDTO.id!);
managerAppContext.selectedSection = null;
appContext.setContext(managerAppContext);
}, context);
}
Future<void> 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,
AppLocalizations.of(context)!.sectionTranslationSaved, context, null);
} else {
showNotification(kSuccess, kWhite,
AppLocalizations.of(context)!.sectionSavedSuccess, context, null);
}
}
// ── Type-specific config widget ──
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: AppLocalizations.of(context)!.videoUrlLabel,
initialValue: sectionDetailDTO as VideoDTO,
onChanged: (VideoDTO updatedWebDTO) {
sectionDetailDTO = updatedWebDTO;
},
);
case SectionType.Web:
return WebConfig(
label: AppLocalizations.of(context)!.webUrlLabel,
initialValue: sectionDetailDTO as WebDTO,
onChanged: (WebDTO updatedWebDTO) {
sectionDetailDTO = updatedWebDTO;
},
);
case SectionType.Menu:
return MenuConfig(
initialValue: sectionDetailDTO as MenuDTO,
onChanged: (String 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;
},
);
}
}
// ── Section detail initialization ──
_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;
}
}
// ── Sync sectionDTO fields back to detail DTO before save ──
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<Object?> getSection(String sectionId, Client client) async {
try {
Object? section = await client.sectionApi!.sectionGetDetail(sectionId);
return section;
} catch (e) {
print(e);
return null;
}
}
Future<Uint8List?> _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<void> readAndWriteFiles(Uint8List? image) async {
await Pasteboard.writeImage(image);
final files = await Pasteboard.files();
print(files);
}