231 lines
8.7 KiB
Dart
231 lines
8.7 KiB
Dart
import 'package:auto_size_text/auto_size_text.dart';
|
|
import 'package:manager_app/Components/image_input_container.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/Slider/slider_config.dart';
|
|
import 'package:manager_app/Screens/Configurations/Section/SubSection/WebOrVideo/web_video_config.dart';
|
|
import 'package:manager_app/app_context.dart';
|
|
import 'package:manager_app/constants.dart';
|
|
import 'package:managerapi/api.dart';
|
|
|
|
import '../Map/map_config.dart';
|
|
import 'menu_config.dart';
|
|
|
|
void showEditSubSection(SectionDTO subSectionDTO, Function getResult, AppContext appContext, BuildContext context) {
|
|
|
|
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("Modifier sous section", style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w400)),
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
StringInputContainer(
|
|
label: "Nom :",
|
|
initialValue: subSectionDTO.label,
|
|
onChanged: (String name) {
|
|
subSectionDTO.label = name;
|
|
},
|
|
),
|
|
ImageInputContainer(
|
|
label: "Image :",
|
|
initialValue: subSectionDTO.imageId,
|
|
color: kPrimaryColor,
|
|
onChanged: (ResourceDTO resource) {
|
|
subSectionDTO.imageId = resource.id;
|
|
subSectionDTO.imageSource = resource.type == ResourceType.imageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id;
|
|
},
|
|
isSmall: true,
|
|
),
|
|
],
|
|
),
|
|
Container(
|
|
height: size.height * 0.33,
|
|
width: double.infinity,
|
|
child: ListView(
|
|
scrollDirection: Axis.horizontal,
|
|
children: getTranslations(context, appContext, subSectionDTO),
|
|
),
|
|
),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
color: kWhite,
|
|
borderRadius: BorderRadius.circular(20),
|
|
border: Border.all(width: 0.5, color: kSecond)
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: getSpecificData(subSectionDTO, context, appContext),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
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: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
fontSize: 20,
|
|
),
|
|
),
|
|
),
|
|
Align(
|
|
alignment: AlignmentDirectional.bottomEnd,
|
|
child: Container(
|
|
width: subSectionDTO != null ? 220: 150,
|
|
height: 70,
|
|
child: RoundedButton(
|
|
text: "Sauvegarder",
|
|
icon: Icons.check,
|
|
color: kPrimaryColor,
|
|
textColor: kWhite,
|
|
press: () {
|
|
getResult(subSectionDTO);
|
|
Navigator.of(context).pop();
|
|
},
|
|
fontSize: 20,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
), context: context
|
|
);
|
|
}
|
|
|
|
getSpecificData(SectionDTO sectionDTO, BuildContext context, AppContext appContext) {
|
|
switch(sectionDTO.type) {
|
|
case SectionType.map:
|
|
return MapConfig(
|
|
initialValue: sectionDTO.data,
|
|
onChanged: (String data) {
|
|
//print("Received info in parent");
|
|
//print(data);
|
|
sectionDTO.data = data;
|
|
},
|
|
);
|
|
case SectionType.slider:
|
|
return Container(
|
|
width: MediaQuery.of(context).size.width * 0.5,
|
|
height: MediaQuery.of(context).size.height * 0.5,
|
|
child: SliderConfig(
|
|
initialValue: sectionDTO.data,
|
|
onChanged: (String data) {
|
|
//print("Received info in parent");
|
|
//print(data);
|
|
sectionDTO.data = data;
|
|
},
|
|
),
|
|
);
|
|
case SectionType.video:
|
|
case SectionType.web:
|
|
return WebOrVideoConfig(
|
|
label: sectionDTO.type == SectionType.video ? "Url de la vidéo:": "Url du site web:",
|
|
initialValue: sectionDTO.data,
|
|
onChanged: (String data) {
|
|
sectionDTO.data = data;
|
|
},
|
|
);
|
|
case SectionType.menu:
|
|
return MenuConfig(
|
|
initialValue: sectionDTO.data,
|
|
onChanged: (String data) {
|
|
//print("Received info in parent");
|
|
//print(data);
|
|
sectionDTO.data = data;
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
getTranslations(BuildContext context, AppContext appContext, SectionDTO subSectionDTO) {
|
|
List<Widget> translations = <Widget>[];
|
|
ManagerAppContext managerAppContext = appContext.getContext();
|
|
for(var language in managerAppContext.selectedConfiguration.languages) {
|
|
translations.add(
|
|
SingleChildScrollView(
|
|
child: 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: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
TextFormInputContainer(
|
|
label: "Titre:",
|
|
color: kWhite,
|
|
isTitle: true,
|
|
maxLines: 1,
|
|
initialValue: subSectionDTO.title.where((element) => element.language == language).first.value,
|
|
onChanged: (value) {
|
|
subSectionDTO.title.where((element) => element.language == language).first.value = value;
|
|
},
|
|
),
|
|
TextFormInputContainer(
|
|
label: "Description:",
|
|
color: kWhite,
|
|
isTitle: false,
|
|
initialValue: subSectionDTO.description.where((element) => element.language == language).first.value,
|
|
onChanged: (value) {
|
|
subSectionDTO.description.where((element) => element.language == language).first.value = value;
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
)
|
|
);
|
|
}
|
|
return translations;
|
|
}
|
|
|