manager-app/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart

211 lines
8.2 KiB
Dart

import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.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(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.images = <ImageGeoPoint>[];
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.7,
child: SingleChildScrollView(
child: Column(
children: [
Text("Point géographique", style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w400)),
Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
StringInputContainer(
label: "Latitude :",
initialValue: geoPointDTO.latitude,
onChanged: (value) {
geoPointDTO.latitude = value;
},
),
StringInputContainer(
label: "Longitude :",
initialValue: geoPointDTO.longitude,
onChanged: (value) {
geoPointDTO.longitude = value;
},
)
],
),
Container(
height: size.height * 0.33,
width: double.infinity,
child: ListView(
scrollDirection: Axis.horizontal,
children: getTranslations(context, appContext, geoPointDTO),
),
),
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: GeoPointImageList(
images: geoPointDTO.images,
onChanged: (List<ImageGeoPoint> imagesOutput) {
geoPointDTO.images = imagesOutput;
},
),
),
],
),
],
),
),
),
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.images = inputGeoPointDTO.images;
}
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
);
}
getTranslations(BuildContext context, AppContext appContext, GeoPointDTO geoPointDTO) {
List<Widget> translations = <Widget>[];
ManagerAppContext managerAppContext = appContext.getContext();
for(var language in managerAppContext.selectedConfiguration.languages) {
translations.add(
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
width: MediaQuery.of(context).size.width *0.05,
height: MediaQuery.of(context).size.height *0.2,
decoration: BoxDecoration(
border: Border(
right: BorderSide(width: 1.5, color: kSecond),
),
),
child: Center(child: AutoSizeText(language.toUpperCase()))
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Container(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextFormInputContainer(
label: "Titre:",
color: kWhite,
isTitle: true,
initialValue: geoPointDTO.title.where((element) => element.language == language).first.value,
onChanged: (value) {
geoPointDTO.title.where((element) => element.language == language).first.value = value;
},
),
TextFormInputContainer(
label: "Description:",
color: kWhite,
isTitle: false,
initialValue: geoPointDTO.description.where((element) => element.language == language).first.value,
onChanged: (value) {
geoPointDTO.description.where((element) => element.language == language).first.value = value;
},
),
],
),
),
),
)
],
),
)
);
}
return translations;
}