manager-app/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart
2023-12-27 18:11:25 +01:00

216 lines
9.1 KiB
Dart

import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:manager_app/Components/dropDown_input_container.dart';
import 'package:manager_app/Components/multi_string_input_container.dart';
import 'package:manager_app/Components/rounded_button.dart';
import 'package:manager_app/Components/string_input_container.dart';
import 'package:manager_app/Components/text_form_input_container.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 = new GeoPointDTO();
if (inputGeoPointDTO != null) {
geoPointDTO = inputGeoPointDTO;
} else {
geoPointDTO.title = <TranslationDTO>[];
geoPointDTO.description = <TranslationDTO>[];
geoPointDTO.contents = <ContentGeoPoint>[];
ManagerAppContext managerAppContext = appContext.getContext();
managerAppContext.selectedConfiguration!.languages!.forEach((element) {
var translationDTO = new TranslationDTO();
translationDTO.language = element;
translationDTO.value = "";
geoPointDTO.title!.add(translationDTO);
geoPointDTO.description!.add(translationDTO);
});
}
Size size = MediaQuery.of(context).size;
showDialog(
builder: (BuildContext context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))
),
content: Container(
width: size.width *0.8,
child: SingleChildScrollView(
child: Column(
children: [
Text("Point géographique", style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w400)),
Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
SizedBox(
height: 100,
child: StringInputContainer(
isSmall: true,
label: "Latitude (#.#):",
initialValue: geoPointDTO.latitude,
onChanged: (value) {
geoPointDTO.latitude = value;
},
),
),
SizedBox(
height: 100,
child: StringInputContainer(
isSmall: true,
label: "Longitude (#.#):",
initialValue: geoPointDTO.longitude,
onChanged: (value) {
geoPointDTO.longitude = value;
},
),
)
],
),
Container(
height: size.height * 0.2,
width: double.infinity,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
constraints: BoxConstraints(minHeight: 50, maxHeight: 80),
child: MultiStringInputContainer(
label: "Titre affiché:",
modalLabel: "Titre",
fontSize: 20,
isHTML: true,
color: kPrimaryColor,
initialValue: geoPointDTO.title != null ? geoPointDTO.title! : [],
onGetResult: (value) {
if (geoPointDTO.title != value) {
geoPointDTO.title = value;
}
},
maxLines: 1,
isTitle: true
),
),
Container(
constraints: BoxConstraints(minHeight: 50, maxHeight: 80),
child: MultiStringInputContainer(
label: "Description affichée:",
modalLabel: "Description",
fontSize: 20,
isHTML: true,
color: kPrimaryColor,
initialValue: geoPointDTO.description != null ? geoPointDTO.description! : [],
onGetResult: (value) {
if (geoPointDTO.description != value) {
geoPointDTO.description = value;
}
},
maxLines: 1,
isTitle: false
),
),
if(mapDTO.categories != null && mapDTO.categories!.isNotEmpty)
Container(
constraints: BoxConstraints(minHeight: 50, maxHeight: 80),
child: DropDownInputContainer(
label: "Choisir une catégorie:",
categories: mapDTO.categories!,
initialValue: geoPointDTO.categorie,
onChange: (CategorieDTO? value) {
if(value != null && value.order != -1)
{
geoPointDTO.categorie = value;
} else
{
geoPointDTO.categorie = null;
}
},
),
),
],
),
),
Container(
height: size.height * 0.33,
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), // changes position of shadow
),
],
),
child: GeoPointContentList(
contents: geoPointDTO.contents!,
onChanged: (List<ContentGeoPoint> contentsOutput) {
geoPointDTO.contents = contentsOutput;
},
),
),
],
),
],
),
),
),
actions: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Align(
alignment: AlignmentDirectional.bottomEnd,
child: Container(
width: 175,
height: 70,
child: RoundedButton(
text: "Annuler",
icon: Icons.undo,
color: kSecond,
press: () {
if (inputGeoPointDTO != null) {
geoPointDTO.contents = inputGeoPointDTO.contents;
}
Navigator.of(context).pop();
},
fontSize: 20,
),
),
),
Align(
alignment: AlignmentDirectional.bottomEnd,
child: Container(
width: geoPointDTO != null ? 220: 150,
height: 70,
child: RoundedButton(
text: geoPointDTO != null ? "Sauvegarder" : "Créer",
icon: Icons.check,
color: kPrimaryColor,
textColor: kWhite,
press: () {
if (geoPointDTO.latitude != null && geoPointDTO.longitude != null) {
getResult(geoPointDTO);
Navigator.of(context).pop();
}
},
fontSize: 20,
),
),
),
],
),
],
), context: context
);
}