diff --git a/lib/Components/dropDown_input_container.dart b/lib/Components/dropDown_input_container.dart index e528bba..04072c4 100644 --- a/lib/Components/dropDown_input_container.dart +++ b/lib/Components/dropDown_input_container.dart @@ -1,18 +1,17 @@ import 'package:flutter/material.dart'; -import 'package:flutter_widget_from_html/flutter_widget_from_html.dart'; -import 'package:manager_api_new/api.dart'; import 'package:manager_app/constants.dart'; class DropDownInputContainer extends StatefulWidget { final String label; - final List categories; - final CategorieDTO? initialValue; - final ValueChanged? onChange; + final List values; + final String? initialValue; + final ValueChanged? onChange; + const DropDownInputContainer({ Key? key, required this.label, - required this.categories, - required this.initialValue, + required this.values, + this.initialValue, this.onChange, }) : super(key: key); @@ -21,56 +20,49 @@ class DropDownInputContainer extends StatefulWidget { } class _DropDownInputContainerState extends State { - List categoriesToShow = []; - CategorieDTO? selectedCategorieDTO; + late String? selectedValue; @override void initState() { - if(widget.initialValue != null) { - selectedCategorieDTO = widget.categories.firstWhere((element) => element.order == widget.initialValue!.order); - } - List label = []; - label.add(TranslationDTO(language: "FR", value: "Aucune catégorie")); - categoriesToShow.add(CategorieDTO(order: -1, label: label)); - categoriesToShow.addAll(widget.categories); super.initState(); + selectedValue = widget.initialValue; } @override Widget build(BuildContext context) { - /*final appContext = Provider.of(context); - Size size = MediaQuery.of(context).size;*/ - return Row( children: [ Align( - alignment: AlignmentDirectional.centerStart, - child: Text(widget.label, style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300)) + alignment: AlignmentDirectional.centerStart, + child: Text( + widget.label, + style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300), + ), ), Padding( padding: const EdgeInsets.all(8.0), - child: DropdownButton( - value: selectedCategorieDTO, + child: DropdownButton( + value: selectedValue, icon: const Icon(Icons.arrow_downward), iconSize: 24, elevation: 16, - style: const TextStyle(color: kWhite), + style: const TextStyle(color: Colors.black), underline: Container( height: 2, color: kPrimaryColor, ), - onChanged: (CategorieDTO? newValue) { + onChanged: (String? newValue) { setState(() { - selectedCategorieDTO = newValue!; - widget.onChange!(selectedCategorieDTO!); + selectedValue = newValue; + widget.onChange!(selectedValue!); }); }, - items: categoriesToShow.map>((CategorieDTO value) { - return DropdownMenuItem( + items: widget.values.map>((String value) { + return DropdownMenuItem( value: value, - child: HtmlWidget( - value.label == null ? "" : value.label![0].value!, - textStyle: TextStyle(fontSize: 15, color: Colors.black, fontWeight: FontWeight.w400) + child: Text( + value, + style: TextStyle(fontSize: 15), ), ); }).toList(), @@ -79,5 +71,4 @@ class _DropDownInputContainerState extends State { ], ); } - -} \ No newline at end of file +} diff --git a/lib/Components/dropDown_input_container_categories.dart b/lib/Components/dropDown_input_container_categories.dart new file mode 100644 index 0000000..7c9346d --- /dev/null +++ b/lib/Components/dropDown_input_container_categories.dart @@ -0,0 +1,83 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_widget_from_html/flutter_widget_from_html.dart'; +import 'package:manager_api_new/api.dart'; +import 'package:manager_app/constants.dart'; + +class DropDownInputContainerCategories extends StatefulWidget { + final String label; + final List categories; + final CategorieDTO? initialValue; + final ValueChanged? onChange; + const DropDownInputContainerCategories({ + Key? key, + required this.label, + required this.categories, + required this.initialValue, + this.onChange, + }) : super(key: key); + + @override + _DropDownInputContainerCategoriesState createState() => _DropDownInputContainerCategoriesState(); +} + +class _DropDownInputContainerCategoriesState extends State { + List categoriesToShow = []; + CategorieDTO? selectedCategorieDTO; + + @override + void initState() { + if(widget.initialValue != null) { + selectedCategorieDTO = widget.categories.firstWhere((element) => element.order == widget.initialValue!.order); + } + List label = []; + label.add(TranslationDTO(language: "FR", value: "Aucune catégorie")); + categoriesToShow.add(CategorieDTO(order: -1, label: label)); + categoriesToShow.addAll(widget.categories); + super.initState(); + } + + @override + Widget build(BuildContext context) { + /*final appContext = Provider.of(context); + Size size = MediaQuery.of(context).size;*/ + + return Row( + children: [ + Align( + alignment: AlignmentDirectional.centerStart, + child: Text(widget.label, style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300)) + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: DropdownButton( + value: selectedCategorieDTO, + icon: const Icon(Icons.arrow_downward), + iconSize: 24, + elevation: 16, + style: const TextStyle(color: kWhite), + underline: Container( + height: 2, + color: kPrimaryColor, + ), + onChanged: (CategorieDTO? newValue) { + setState(() { + selectedCategorieDTO = newValue!; + widget.onChange!(selectedCategorieDTO!); + }); + }, + items: categoriesToShow.map>((CategorieDTO value) { + return DropdownMenuItem( + value: value, + child: HtmlWidget( + value.label == null ? "" : value.label![0].value!, + textStyle: TextStyle(fontSize: 15, color: Colors.black, fontWeight: FontWeight.w400) + ), + ); + }).toList(), + ), + ), + ], + ); + } + +} \ No newline at end of file diff --git a/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart b/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart index d1f2f25..a4e03d8 100644 --- a/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart +++ b/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart @@ -2,6 +2,7 @@ import 'package:diacritic/diacritic.dart'; import 'package:flutter/material.dart'; import 'package:flutter_widget_from_html/flutter_widget_from_html.dart'; import 'package:manager_app/Components/category_input_container.dart'; +import 'package:manager_app/Components/dropDown_input_container.dart'; import 'package:manager_app/Components/fetch_section_icon.dart'; import 'package:manager_app/Components/resource_input_container.dart'; import 'package:manager_app/Components/multi_select_container.dart'; @@ -179,29 +180,22 @@ class _MapConfigState extends State { children: [ if(mapDTO.mapProvider == MapProvider.Google) // Map Type - MultiSelectContainer( + DropDownInputContainer( label: "Type:", - initialValue: [mapType], //mapDTO.mapType.toString() - isMultiple: false, values: map_types, - onChanged: (value) { - var tempOutput = new List.from(value); - print("Type MAP"); - print(value); - mapDTO.mapType = MapTypeApp.fromJson(tempOutput[0]); + initialValue: mapType, + onChange: (String? value) { + mapDTO.mapType = MapTypeApp.fromJson(value); widget.onChanged(jsonEncode(mapDTO).toString()); }, ), if(mapDTO.mapProvider == MapProvider.MapBox) - MultiSelectContainer( + DropDownInputContainer( label: "Type:", - initialValue: [mapTypeMapBox], //mapDTO.mapType.toString() - isMultiple: false, values: map_types_mapBox, - onChanged: (value) { - var tempOutput = new List.from(value); - print(value); - mapDTO.mapTypeMapbox = MapTypeMapBox.fromJson(tempOutput[0]); + initialValue: mapTypeMapBox, + onChange: (String? value) { + mapDTO.mapTypeMapbox = MapTypeMapBox.fromJson(value); widget.onChanged(jsonEncode(mapDTO).toString()); }, ), diff --git a/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart b/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart index 2d8340b..7cd5fdb 100644 --- a/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart +++ b/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:location_picker_flutter_map/location_picker_flutter_map.dart'; -import 'package:manager_app/Components/dropDown_input_container.dart'; +import 'package:manager_app/Components/dropDown_input_container_categories.dart'; import 'package:manager_app/Components/loading_common.dart'; import 'package:manager_app/Components/multi_string_input_container.dart'; import 'package:manager_app/Components/rounded_button.dart'; @@ -38,7 +38,7 @@ void showNewOrUpdateGeoPoint(MapDTO mapDTO, GeoPointDTO? inputGeoPointDTO, Funct borderRadius: BorderRadius.all(Radius.circular(20.0)) ), content: Container( - width: size.width *0.8, + width: size.width *0.85, child: SingleChildScrollView( child: Column( children: [ @@ -121,8 +121,7 @@ void showNewOrUpdateGeoPoint(MapDTO mapDTO, GeoPointDTO? inputGeoPointDTO, Funct ], ),*/ Container( - height: size.height * 0.2, - width: double.infinity, + height: 100, child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ @@ -163,10 +162,104 @@ void showNewOrUpdateGeoPoint(MapDTO mapDTO, GeoPointDTO? inputGeoPointDTO, Funct 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: false + ), + ), + ], + ), + ), + 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: false + ), + ), + 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: false + ), + ), + ], + ), + ), + Container( + height: 100, + width: double.infinity, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ if(mapDTO.categories != null && mapDTO.categories!.isNotEmpty) Container( constraints: BoxConstraints(minHeight: 50, maxHeight: 80), - child: DropDownInputContainer( + child: DropDownInputContainerCategories( label: "Choisir une catégorie:", categories: mapDTO.categories!, initialValue: geoPointDTO.categorie, diff --git a/lib/Screens/Configurations/new_section_popup.dart b/lib/Screens/Configurations/new_section_popup.dart index e664617..bfe46c7 100644 --- a/lib/Screens/Configurations/new_section_popup.dart +++ b/lib/Screens/Configurations/new_section_popup.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:manager_app/Components/dropDown_input_container.dart'; import 'package:manager_app/Components/message_notification.dart'; import 'package:manager_app/Components/multi_select_container.dart'; import 'package:manager_app/Components/rounded_button.dart'; @@ -24,8 +25,8 @@ void showNewSection(String configurationId, AppContext appContext, BuildContext ), content: SingleChildScrollView( child: SizedBox( - width: size.width*0.4, - height: size.height*0.4, + width: 750, + height: 250, child: Container( constraints: BoxConstraints(minHeight: 300, minWidth: 300), child: Column( @@ -43,7 +44,15 @@ void showNewSection(String configurationId, AppContext appContext, BuildContext }, ), ), - MultiSelectContainer( + DropDownInputContainer( + label: "Type:", + values: isMobile ? section_types.where((sectionType) => sectionType == "Article" || sectionType == "Quizz").toList(): isSubSection ? section_types.where((sectionType) => sectionType != "Menu" && sectionType != "Article").toList(): section_types.where((sectionType) => sectionType != "Article").toList(), // Todo get menu by enum type + initialValue: isMobile ? "Article" : "Map", + onChange: (String? value) { + sectionDTO.type = SectionType.fromJson(value); + }, + ), + /*MultiSelectContainer( label: "Type:", initialValue: isMobile ? ["Article"] : ["Map"], isMultiple: false, @@ -52,7 +61,7 @@ void showNewSection(String configurationId, AppContext appContext, BuildContext var tempOutput = new List.from(value); sectionDTO.type = SectionType.fromJson(tempOutput[0]); }, - ), + ),*/ ], ), ],