From fb5973d0162c29e10eb26b835ef32c83a439316a Mon Sep 17 00:00:00 2001 From: Fransolet Thomas Date: Fri, 10 Mar 2023 17:42:31 +0100 Subject: [PATCH] View audio title on audio selection + add possibility to choose null on select resource --- lib/Components/audio_input_container.dart | 16 ++++++++-------- lib/Components/image_input_container.dart | 4 ++-- .../Section/SubSection/Map/map_config.dart | 9 +++++++-- .../SubSection/Menu/showEditSubSection.dart | 9 +++++++-- .../Quizz/new_update_question_quizz.dart | 10 +++++++--- .../SubSection/Quizz/new_update_score_quizz.dart | 10 +++++++--- .../Slider/new_update_image_slider.dart | 10 +++++++--- .../Section/section_detail_screen.dart | 9 +++++++-- .../configuration_detail_screen.dart | 9 +++++++-- lib/Screens/Resources/resource_body_grid.dart | 4 ++-- lib/Screens/Resources/resources_screen.dart | 10 ++++++++-- 11 files changed, 69 insertions(+), 31 deletions(-) diff --git a/lib/Components/audio_input_container.dart b/lib/Components/audio_input_container.dart index 63bc28b..5969e93 100644 --- a/lib/Components/audio_input_container.dart +++ b/lib/Components/audio_input_container.dart @@ -64,7 +64,7 @@ class _AudioInputContainerState extends State { height: size.width *0.08, child: InkWell( onTap: () async { - var result = await showSelectResourceModal( + ResourceDTO result = await showSelectResourceModal( "Sélectionner une ressource", 1, [ResourceType.Audio], @@ -73,12 +73,12 @@ class _AudioInputContainerState extends State { if (result != null) { setState(() { - resourceIdToShow = result.id; + resourceIdToShow = result.id != null ? result.id : null; }); widget.onChanged(result); } }, - child: getElement(widget.initialValue, context, widget.isSmall), + child: getElement(context), ), ), ), @@ -88,18 +88,18 @@ class _AudioInputContainerState extends State { ); } - getElement(String initialValue, BuildContext context, bool isSmall) { + getElement(BuildContext context) { if (resourceIdToShow != null) { Size size = MediaQuery.of(context).size; final appContext = Provider.of(context); return FutureBuilder( future: getResource(resourceIdToShow, appContext), - builder: (context, AsyncSnapshot snapshot) { + builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { if (snapshot.data != null) { return Container( decoration: boxDecoration(snapshot.data, appContext), - child: Center(child: AutoSizeText("Audio")), + child: Center(child: AutoSizeText(snapshot.data.label, textAlign: TextAlign.center)), ); } else { return Text("No data"); @@ -139,8 +139,8 @@ class _AudioInputContainerState extends State { Future getResource(String resourceIdToShow, dynamic appContext) async { // Just in resource tab detail not here - //ResourceDTO resource = await appContext.getContext().clientAPI.resourceApi.resourceGetDetail(resourceIdToShow); - return new ResourceDTO(); + ResourceDTO resource = await appContext.getContext().clientAPI.resourceApi.resourceGetDetail(resourceIdToShow); + return resource; } boxDecoration(ResourceDTO resourceDTO, appContext) { diff --git a/lib/Components/image_input_container.dart b/lib/Components/image_input_container.dart index d8de679..f762652 100644 --- a/lib/Components/image_input_container.dart +++ b/lib/Components/image_input_container.dart @@ -64,7 +64,7 @@ class _ImageInputContainerState extends State { height: size.width *0.08, child: InkWell( onTap: () async { - var result = await showSelectResourceModal( + ResourceDTO result = await showSelectResourceModal( "Sélectionner une ressource", 1, [ResourceType.Image, ResourceType.ImageUrl], @@ -73,7 +73,7 @@ class _ImageInputContainerState extends State { if (result != null) { setState(() { - resourceIdToShow = result.id; + resourceIdToShow = result.id != null ? result.id : null; }); widget.onChanged(result); } diff --git a/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart b/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart index a8dcf26..0d3fd5a 100644 --- a/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart +++ b/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart @@ -91,8 +91,13 @@ class _MapConfigState extends State { color: kPrimaryColor, imageFit: BoxFit.contain, onChanged: (ResourceDTO resource) { - mapDTO.iconSource = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; - mapDTO.iconResourceId = resource.id; + if(resource.id == null) { + mapDTO.iconSource = null; + mapDTO.iconResourceId = null; + } else { + mapDTO.iconResourceId = resource.id; + mapDTO.iconSource = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + } widget.onChanged(jsonEncode(mapDTO).toString()); }, isSmall: true diff --git a/lib/Screens/Configurations/Section/SubSection/Menu/showEditSubSection.dart b/lib/Screens/Configurations/Section/SubSection/Menu/showEditSubSection.dart index e22fb71..a238b88 100644 --- a/lib/Screens/Configurations/Section/SubSection/Menu/showEditSubSection.dart +++ b/lib/Screens/Configurations/Section/SubSection/Menu/showEditSubSection.dart @@ -47,8 +47,13 @@ void showEditSubSection(SectionDTO subSectionDTO, Function getResult, AppContext 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; + if(resource.id == null) { + subSectionDTO.imageId = null; + subSectionDTO.imageSource = null; + } else { + subSectionDTO.imageId = resource.id; + subSectionDTO.imageSource = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + } }, isSmall: true, ), diff --git a/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_question_quizz.dart b/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_question_quizz.dart index a21e442..7d84916 100644 --- a/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_question_quizz.dart +++ b/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_question_quizz.dart @@ -54,9 +54,13 @@ Future showNewOrUpdateQuestionQuizz(QuestionDTO inputQuestionDTO, A initialValue: questionDTO.resourceId, color: kPrimaryColor, onChanged: (ResourceDTO resource) { - var result = resource; - questionDTO.source_ = result.type == ResourceType.ImageUrl ? result.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ result.id; - questionDTO.resourceId = result.id; + if(resource.id == null) { + questionDTO.resourceId = null; + questionDTO.source_ = null; + } else { + questionDTO.resourceId = resource.id; + questionDTO.source_ = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + } }, isSmall: true ), diff --git a/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_score_quizz.dart b/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_score_quizz.dart index 6b8e9e1..019d196 100644 --- a/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_score_quizz.dart +++ b/lib/Screens/Configurations/Section/SubSection/Quizz/new_update_score_quizz.dart @@ -48,9 +48,13 @@ Future showNewOrUpdateScoreQuizz(LevelDTO inputLevelDTO, AppContext ap initialValue: levelDTO.resourceId, color: kPrimaryColor, onChanged: (ResourceDTO resource) { - var result = resource; - levelDTO.source_ = result.type == ResourceType.ImageUrl ? result.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ result.id; - levelDTO.resourceId = result.id; + if(resource.id == null) { + levelDTO.resourceId = null; + levelDTO.source_ = null; + } else { + levelDTO.resourceId = resource.id; + levelDTO.source_ = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + } }, isSmall: true ), diff --git a/lib/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.dart b/lib/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.dart index 1ac1845..49bef14 100644 --- a/lib/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.dart +++ b/lib/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.dart @@ -54,9 +54,13 @@ Future showNewOrUpdateImageSlider(ImageDTO inputImageDTO, AppContext a initialValue: imageDTO.resourceId, color: kPrimaryColor, onChanged: (ResourceDTO resource) { - var result = resource; - imageDTO.source_ = result.type == ResourceType.ImageUrl ? result.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ result.id; - imageDTO.resourceId = result.id; + if(resource.id == null) { + imageDTO.resourceId = null; + imageDTO.source_ = null; + } else { + imageDTO.resourceId = resource.id; + imageDTO.source_ = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + } }, isSmall: true ), diff --git a/lib/Screens/Configurations/Section/section_detail_screen.dart b/lib/Screens/Configurations/Section/section_detail_screen.dart index 595dcb8..98c37bc 100644 --- a/lib/Screens/Configurations/Section/section_detail_screen.dart +++ b/lib/Screens/Configurations/Section/section_detail_screen.dart @@ -248,8 +248,13 @@ class _SectionDetailScreenState extends State { initialValue: sectionDTO != null ? sectionDTO.imageId : "", color: kPrimaryColor, onChanged: (ResourceDTO resource) { - sectionDTO.imageId = resource.id; - sectionDTO.imageSource = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + if(resource.id == null) { + sectionDTO.imageId = null; + sectionDTO.imageSource = null; + } else { + sectionDTO.imageId = resource.id; + sectionDTO.imageSource = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + } }, ), ], diff --git a/lib/Screens/Configurations/configuration_detail_screen.dart b/lib/Screens/Configurations/configuration_detail_screen.dart index 131f957..018b640 100644 --- a/lib/Screens/Configurations/configuration_detail_screen.dart +++ b/lib/Screens/Configurations/configuration_detail_screen.dart @@ -286,8 +286,13 @@ class _ConfigurationDetailScreenState extends State { initialValue: configurationDTO != null ? configurationDTO.imageId : "", color: kPrimaryColor, onChanged: (ResourceDTO resource) { - configurationDTO.imageId = resource.id; - configurationDTO.imageSource = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + if(resource.id == null) { + configurationDTO.imageId = null; + configurationDTO.imageSource = null; + } else { + configurationDTO.imageId = resource.id; + configurationDTO.imageSource = resource.type == ResourceType.ImageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + } }, ), ]) diff --git a/lib/Screens/Resources/resource_body_grid.dart b/lib/Screens/Resources/resource_body_grid.dart index a6121ee..c60958d 100644 --- a/lib/Screens/Resources/resource_body_grid.dart +++ b/lib/Screens/Resources/resource_body_grid.dart @@ -174,7 +174,7 @@ class _ResourceBodyGridState extends State { ); } else { return Icon( - Icons.add, + Icons.close, color: kTextLightColor, size: 80.0, ); @@ -190,7 +190,7 @@ class _ResourceBodyGridState extends State { boxDecoration(dynamic resourceDetailDTO, appContext) { return BoxDecoration( - color: resourceDetailDTO.id == null ? kSuccess : kBackgroundColor, + color: resourceDetailDTO.id == null ? kSecond : kBackgroundColor, shape: BoxShape.rectangle, borderRadius: BorderRadius.circular(30.0), image: resourceDetailDTO.id != null && (resourceDetailDTO.type == ResourceType.Image || resourceDetailDTO.data != null && resourceDetailDTO.type == ResourceType.ImageUrl)? new DecorationImage( diff --git a/lib/Screens/Resources/resources_screen.dart b/lib/Screens/Resources/resources_screen.dart index 2ef6050..37ccdd3 100644 --- a/lib/Screens/Resources/resources_screen.dart +++ b/lib/Screens/Resources/resources_screen.dart @@ -47,8 +47,14 @@ class _ResourcesScreenState extends State { builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { if(snapshot.data != null) { - var tempOutput = new List.from(snapshot.data); - // tempOutput.add(ResourceDTO(id: null)); + List tempOutput = []; + if(!widget.isAddButton) { + tempOutput.add(ResourceDTO()); + tempOutput.addAll(new List.from(snapshot.data)); + } else { + tempOutput = new List.from(snapshot.data); + } + return ResourceBodyGrid( resources: tempOutput, resourceTypesIn: widget.isImage ? resource_types.where((rt) => rt.type == ResourceType.Image || rt.type == ResourceType.ImageUrl).map((rt) => rt.type).toList() : widget.resourceTypes,