355 lines
16 KiB
Dart
355 lines
16 KiB
Dart
import 'dart:convert';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manager_app/Components/geometry_input_container.dart';
|
|
import 'package:manager_app/Components/dropDown_input_container_categories.dart';
|
|
import 'package:manager_app/Components/multi_string_input_container.dart';
|
|
import 'package:manager_app/Components/resource_input_container.dart';
|
|
import 'package:manager_app/Components/rounded_button.dart';
|
|
import 'package:manager_app/Models/managerContext.dart';
|
|
import 'package:manager_app/Screens/Configurations/Section/SubSection/Map/geopoint_image_list.dart';
|
|
import 'package:manager_app/app_context.dart';
|
|
import 'package:manager_app/constants.dart';
|
|
import 'package:manager_api_new/api.dart';
|
|
|
|
void showNewOrUpdateGeoPoint(MapDTO mapDTO, GeoPointDTO? inputGeoPointDTO,
|
|
Function getResult, AppContext appContext, BuildContext context) {
|
|
GeoPointDTO geoPointDTO = GeoPointDTO();
|
|
if (inputGeoPointDTO != null) {
|
|
geoPointDTO =
|
|
GeoPointDTO.fromJson(jsonDecode(jsonEncode(inputGeoPointDTO)))!;
|
|
} else {
|
|
geoPointDTO.title = <TranslationDTO>[];
|
|
geoPointDTO.description = <TranslationDTO>[];
|
|
geoPointDTO.contents = <ContentDTO>[];
|
|
geoPointDTO.schedules = <TranslationDTO>[];
|
|
geoPointDTO.prices = <TranslationDTO>[];
|
|
geoPointDTO.phone = <TranslationDTO>[];
|
|
geoPointDTO.email = <TranslationDTO>[];
|
|
geoPointDTO.site = <TranslationDTO>[];
|
|
|
|
ManagerAppContext managerAppContext = appContext.getContext();
|
|
managerAppContext.selectedConfiguration!.languages!.forEach((element) {
|
|
var translationDTO = TranslationDTO();
|
|
translationDTO.language = element;
|
|
translationDTO.value = "";
|
|
geoPointDTO.title!.add(translationDTO);
|
|
geoPointDTO.description!.add(translationDTO);
|
|
geoPointDTO.schedules!.add(translationDTO);
|
|
geoPointDTO.prices!.add(translationDTO);
|
|
geoPointDTO.phone!.add(translationDTO);
|
|
geoPointDTO.email!.add(translationDTO);
|
|
geoPointDTO.site!.add(translationDTO);
|
|
});
|
|
}
|
|
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return StatefulBuilder(
|
|
builder: (context, setState) {
|
|
final double screenWidth = MediaQuery.of(context).size.width;
|
|
final double screenHeight = MediaQuery.of(context).size.height;
|
|
final double dialogWidth = screenWidth * 0.88;
|
|
final double contentWidth =
|
|
dialogWidth - 48; // 24px padding each side
|
|
final double thirdWidth = (contentWidth - 40) / 3;
|
|
|
|
return Dialog(
|
|
shape:
|
|
RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
|
child: Container(
|
|
width: dialogWidth,
|
|
constraints: BoxConstraints(maxHeight: screenHeight * 0.9),
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Titre du dialog
|
|
Text(
|
|
"Point géographique / Zone",
|
|
style: TextStyle(
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.w500,
|
|
color: kPrimaryColor),
|
|
),
|
|
SizedBox(height: 16),
|
|
// Corps scrollable
|
|
Flexible(
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Géométrie
|
|
GeometryInputContainer(
|
|
label: "Géométrie (Point/Ligne/Zone) :",
|
|
initialGeometry: geoPointDTO.geometry,
|
|
initialColor: geoPointDTO.polyColor,
|
|
onSave: (geometry, color) {
|
|
setState(() {
|
|
geoPointDTO.geometry = geometry;
|
|
geoPointDTO.polyColor = color;
|
|
});
|
|
},
|
|
),
|
|
SizedBox(height: 12),
|
|
// Ligne 1 : Titre | Description | Site
|
|
Row(
|
|
children: [
|
|
SizedBox(
|
|
width: thirdWidth,
|
|
child: MultiStringInputContainer(
|
|
label: "Titre :",
|
|
modalLabel: "Titre",
|
|
fontSize: 16,
|
|
isHTML: true,
|
|
color: kPrimaryColor,
|
|
initialValue: geoPointDTO.title ?? [],
|
|
onGetResult: (value) {
|
|
geoPointDTO.title = value;
|
|
},
|
|
maxLines: 1,
|
|
isTitle: true,
|
|
),
|
|
),
|
|
SizedBox(width: 20),
|
|
SizedBox(
|
|
width: thirdWidth,
|
|
child: MultiStringInputContainer(
|
|
label: "Description :",
|
|
modalLabel: "Description",
|
|
fontSize: 16,
|
|
isHTML: true,
|
|
color: kPrimaryColor,
|
|
initialValue: geoPointDTO.description ?? [],
|
|
isMandatory: false,
|
|
onGetResult: (value) {
|
|
geoPointDTO.description = value;
|
|
},
|
|
maxLines: 1,
|
|
isTitle: false,
|
|
),
|
|
),
|
|
SizedBox(width: 20),
|
|
SizedBox(
|
|
width: thirdWidth,
|
|
child: MultiStringInputContainer(
|
|
label: "Site :",
|
|
modalLabel: "Site web",
|
|
fontSize: 16,
|
|
isHTML: true,
|
|
color: kPrimaryColor,
|
|
initialValue: geoPointDTO.site ?? [],
|
|
isMandatory: false,
|
|
onGetResult: (value) {
|
|
geoPointDTO.site = value;
|
|
},
|
|
maxLines: 1,
|
|
isTitle: true,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 12),
|
|
// Ligne 2 : Prix | Tel | Email
|
|
Row(
|
|
children: [
|
|
SizedBox(
|
|
width: thirdWidth,
|
|
child: MultiStringInputContainer(
|
|
label: "Prix :",
|
|
modalLabel: "Prix",
|
|
fontSize: 16,
|
|
isHTML: true,
|
|
color: kPrimaryColor,
|
|
initialValue: geoPointDTO.prices ?? [],
|
|
isMandatory: false,
|
|
onGetResult: (value) {
|
|
geoPointDTO.prices = value;
|
|
},
|
|
maxLines: 1,
|
|
isTitle: false,
|
|
),
|
|
),
|
|
SizedBox(width: 20),
|
|
SizedBox(
|
|
width: thirdWidth,
|
|
child: MultiStringInputContainer(
|
|
label: "Tel :",
|
|
modalLabel: "Téléphone",
|
|
fontSize: 16,
|
|
isHTML: true,
|
|
color: kPrimaryColor,
|
|
initialValue: geoPointDTO.phone ?? [],
|
|
isMandatory: false,
|
|
onGetResult: (value) {
|
|
geoPointDTO.phone = value;
|
|
},
|
|
maxLines: 1,
|
|
isTitle: true,
|
|
),
|
|
),
|
|
SizedBox(width: 20),
|
|
SizedBox(
|
|
width: thirdWidth,
|
|
child: MultiStringInputContainer(
|
|
label: "Email :",
|
|
modalLabel: "Email",
|
|
fontSize: 16,
|
|
isHTML: true,
|
|
color: kPrimaryColor,
|
|
initialValue: geoPointDTO.email ?? [],
|
|
isMandatory: false,
|
|
onGetResult: (value) {
|
|
geoPointDTO.email = value;
|
|
},
|
|
maxLines: 1,
|
|
isTitle: true,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 12),
|
|
// Ligne 3 : Horaires | Image | Catégorie
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
SizedBox(
|
|
width: thirdWidth,
|
|
child: MultiStringInputContainer(
|
|
label: "Horaires :",
|
|
modalLabel: "Horaires d'ouverture",
|
|
fontSize: 16,
|
|
isHTML: true,
|
|
color: kPrimaryColor,
|
|
initialValue: geoPointDTO.schedules ?? [],
|
|
isMandatory: false,
|
|
onGetResult: (value) {
|
|
geoPointDTO.schedules = value;
|
|
},
|
|
maxLines: 1,
|
|
isTitle: false,
|
|
),
|
|
),
|
|
SizedBox(width: 20),
|
|
SizedBox(
|
|
width: thirdWidth,
|
|
child: ResourceInputContainer(
|
|
label: "Image :",
|
|
initialValue: geoPointDTO.imageResourceId,
|
|
color: kPrimaryColor,
|
|
onChanged: (ResourceDTO resource) {
|
|
if (resource.id == null) {
|
|
geoPointDTO.imageResourceId = null;
|
|
geoPointDTO.imageUrl = null;
|
|
} else {
|
|
geoPointDTO.imageResourceId = resource.id;
|
|
geoPointDTO.imageUrl = resource.url;
|
|
}
|
|
},
|
|
),
|
|
),
|
|
SizedBox(width: 20),
|
|
if (mapDTO.categories != null &&
|
|
mapDTO.categories!.isNotEmpty)
|
|
SizedBox(
|
|
width: thirdWidth,
|
|
child: DropDownInputContainerCategories(
|
|
label: "Catégorie :",
|
|
categories: mapDTO.categories!,
|
|
initialValue: geoPointDTO.categorieId,
|
|
onChange: (CategorieDTO? value) {
|
|
if (value != null && value.order != -1) {
|
|
geoPointDTO.categorieId = value.id;
|
|
} else {
|
|
geoPointDTO.categorieId = null;
|
|
}
|
|
},
|
|
),
|
|
)
|
|
else
|
|
SizedBox(width: thirdWidth),
|
|
],
|
|
),
|
|
SizedBox(height: 12),
|
|
// Liste de contenus
|
|
Container(
|
|
height: screenHeight * 0.28,
|
|
decoration: BoxDecoration(
|
|
color: kWhite,
|
|
shape: BoxShape.rectangle,
|
|
border: Border.all(width: 1.5, color: kSecond),
|
|
borderRadius: BorderRadius.circular(10.0),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: kSecond,
|
|
spreadRadius: 0.5,
|
|
blurRadius: 5,
|
|
offset: Offset(0, 1.5),
|
|
),
|
|
],
|
|
),
|
|
child: GeoPointContentList(
|
|
contents: geoPointDTO.contents!,
|
|
onChanged: (List<ContentDTO> contentsOutput) {
|
|
geoPointDTO.contents = contentsOutput;
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 16),
|
|
// Boutons
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
SizedBox(
|
|
height: 46,
|
|
child: RoundedButton(
|
|
text: "Annuler",
|
|
icon: Icons.undo,
|
|
color: kSecond,
|
|
press: () {
|
|
if (inputGeoPointDTO != null) {
|
|
geoPointDTO.contents = inputGeoPointDTO.contents;
|
|
}
|
|
Navigator.of(context).pop();
|
|
},
|
|
fontSize: 15,
|
|
horizontal: 24,
|
|
),
|
|
),
|
|
SizedBox(width: 12),
|
|
SizedBox(
|
|
height: 46,
|
|
child: RoundedButton(
|
|
text:
|
|
geoPointDTO.id != null ? "Sauvegarder" : "Créer",
|
|
icon: Icons.check,
|
|
color: kPrimaryColor,
|
|
textColor: kWhite,
|
|
press: () {
|
|
if (geoPointDTO.geometry != null &&
|
|
geoPointDTO.geometry!.coordinates != null) {
|
|
getResult(geoPointDTO);
|
|
Navigator.of(context).pop();
|
|
}
|
|
},
|
|
fontSize: 15,
|
|
horizontal: 24,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|