import 'package:flutter/material.dart'; import 'package:location_picker_flutter_map/location_picker_flutter_map.dart'; import 'package:manager_app/Components/dropDown_input_container_categories.dart'; import 'package:manager_app/Components/common_loader.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/Components/string_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 = []; geoPointDTO.description = []; geoPointDTO.contents = []; 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.85, child: SingleChildScrollView( child: Column( children: [ Text("Point géographique", style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w400)), Column( children: [ Container( width: size.width *0.75, height: 350, child: FlutterLocationPicker( initZoom: 14, initPosition: geoPointDTO.latitude == null && geoPointDTO.longitude == null ? LatLong(50.429333, 4.891434) : LatLong(double.parse(geoPointDTO.latitude!), double.parse(geoPointDTO.longitude!)), minZoomLevel: 0, maxZoomLevel: 17, markerIcon: const Icon( Icons.location_pin, color: kPrimaryColor, size: 50, ), loadingWidget: CommonLoader(iconSize: 40.0), searchBarHintColor: kPrimaryColor, mapLoadingBackgroundColor: kSecond, zoomButtonsBackgroundColor: kPrimaryColor, zoomButtonsColor: Colors.white, locationButtonBackgroundColor: kPrimaryColor, locationButtonsColor: Colors.white, countryFilter: "be, fr", trackMyPosition: false, searchBarHintText: "Chercher une localisation", searchBarTextColor: Colors.black, searchBarBackgroundColor: Colors.white, showSelectLocationButton : true, selectLocationButtonText: "Choisir cette localisation", selectedLocationButtonTextstyle: const TextStyle(fontSize: 18, color: kPrimaryColor), mapLanguage: 'fr', onError: (e) => print(e), selectLocationButtonLeadingIcon: const Icon(Icons.check, color: kPrimaryColor), onPicked: (pickedData) { geoPointDTO.latitude = pickedData.latLong.latitude.toString(); geoPointDTO.longitude = pickedData.latLong.longitude.toString(); }, onChanged: (pickedData) { /*print("onChanged"); print(pickedData.latLong.latitude); print(pickedData.latLong.longitude); print(pickedData.address); print(pickedData.addressData);*/ }, showContributorBadgeForOSM: false, ), ), /*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: 100, 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! : [], isMandatory: false, onGetResult: (value) { if (geoPointDTO.description != value) { geoPointDTO.description = value; } }, maxLines: 1, isTitle: false ), ), Container( constraints: BoxConstraints(minHeight: 50, maxHeight: 80), child: MultiStringInputContainer( label: "Site:", modalLabel: "Site web", fontSize: 20, isHTML: true, color: kPrimaryColor, initialValue: geoPointDTO.site != null ? geoPointDTO.site! : [], isMandatory: false, onGetResult: (value) { if (geoPointDTO.site != value) { geoPointDTO.site = value; } }, maxLines: 1, isTitle: true ), ), ], ), ), Container( height: 100, width: double.infinity, child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Container( constraints: BoxConstraints(minHeight: 50, maxHeight: 80), child: MultiStringInputContainer( label: "Prix:", modalLabel: "Prix", fontSize: 20, isHTML: true, color: kPrimaryColor, initialValue: geoPointDTO.prices != null ? geoPointDTO.prices! : [], isMandatory: false, onGetResult: (value) { if (geoPointDTO.prices != value) { geoPointDTO.prices = value; } }, maxLines: 1, isTitle: false ), ), Container( constraints: BoxConstraints(minHeight: 50, maxHeight: 80), child: MultiStringInputContainer( label: "Téléphone:", modalLabel: "Téléphone", fontSize: 20, isHTML: true, color: kPrimaryColor, initialValue: geoPointDTO.phone != null ? geoPointDTO.phone! : [], isMandatory: false, onGetResult: (value) { if (geoPointDTO.phone != value) { geoPointDTO.phone = value; } }, maxLines: 1, isTitle: true ), ), Container( constraints: BoxConstraints(minHeight: 50, maxHeight: 80), child: MultiStringInputContainer( label: "Email:", modalLabel: "Email", fontSize: 20, isHTML: true, color: kPrimaryColor, initialValue: geoPointDTO.email != null ? geoPointDTO.email! : [], isMandatory: false, onGetResult: (value) { if (geoPointDTO.email != value) { geoPointDTO.email = value; } }, maxLines: 1, isTitle: true ), ), ], ), ), Container( height: 100, width: double.infinity, child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ ResourceInputContainer( label: "Image principal:", initialValue: geoPointDTO.imageResourceId != null ? geoPointDTO.imageResourceId : null, color: kPrimaryColor, onChanged: (ResourceDTO resource) { if(resource.id == null) { geoPointDTO.imageResourceId = null; geoPointDTO.imageUrl = null; } else { geoPointDTO.imageResourceId = resource.id; geoPointDTO.imageUrl = resource.url; } }, ), if(mapDTO.categories != null && mapDTO.categories!.isNotEmpty) Container( constraints: BoxConstraints(minHeight: 50, maxHeight: 80), child: DropDownInputContainerCategories( label: "Choisir une 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; } }, ), ), ], ), ), 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 contentsOutput) { geoPointDTO.contents = contentsOutput; }, ), ), ], ), ], ), ), ), actions: [ 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 ); }