From b5387880b101f0f09c95f90716b23c1490bc3748 Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Wed, 26 May 2021 18:14:16 +0200 Subject: [PATCH] Add filter type in resource screen --- .../configuration_detail_screen.dart | 2 +- lib/Screens/Resources/resource_body_grid.dart | 53 ++++++++++++++++++- lib/constants.dart | 1 + 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/lib/Screens/Configurations/configuration_detail_screen.dart b/lib/Screens/Configurations/configuration_detail_screen.dart index 5aa12fe..8604b69 100644 --- a/lib/Screens/Configurations/configuration_detail_screen.dart +++ b/lib/Screens/Configurations/configuration_detail_screen.dart @@ -219,7 +219,7 @@ class _ConfigurationDetailScreenState extends State { child: Icon( getSectionIcon(element.type), color: kPrimaryColor, - size: 30.0, + size: 25, ), ), ], diff --git a/lib/Screens/Resources/resource_body_grid.dart b/lib/Screens/Resources/resource_body_grid.dart index c79aefa..ae894c4 100644 --- a/lib/Screens/Resources/resource_body_grid.dart +++ b/lib/Screens/Resources/resource_body_grid.dart @@ -1,6 +1,7 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:manager_app/Components/fetch_resource_icon.dart'; +import 'package:manager_app/Components/multi_select_container.dart'; import 'package:manager_app/Components/string_input_container.dart'; import 'package:manager_app/Screens/Resources/new_resource_popup.dart'; import 'package:manager_app/Screens/Resources/show_resource_popup.dart'; @@ -23,12 +24,15 @@ class ResourceBodyGrid extends StatefulWidget { } class _ResourceBodyGridState extends State { - String filter; + List filterType; + String filterSearch = ''; + List selectedTypes; List resourcesToShow; @override void initState() { resourcesToShow = widget.resources; + filterType = [resource_types[0], resource_types[1], resource_types[2], resource_types[3]]; super.initState(); } @@ -52,7 +56,23 @@ class _ResourceBodyGridState extends State { label: "Recherche:", onChanged: (String value) { setState(() { - resourcesToShow = value.isEmpty ? widget.resources: widget.resources.where((ResourceDTO resource) => resource.label.toUpperCase().contains(value.toUpperCase())).toList(); + filterSearch = value; + filterResource(); + }); + }, + ), + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: MultiSelectContainer( + label: "Type :", + initialValue: filterType, + values: resource_types, + isMultiple: true, + onChanged: (result) { + setState(() { + selectedTypes = result; + filterResource(); }); }, ), @@ -151,6 +171,35 @@ class _ResourceBodyGridState extends State { ); } } + + void filterResource() { + resourcesToShow = filterSearch.isEmpty ? widget.resources: widget.resources.where((ResourceDTO resource) => resource.label.toUpperCase().contains(filterSearch.toUpperCase())).toList(); + + resource_types.forEach((type) { + switch(type) { + case "image": + if (!selectedTypes.contains(type)) { + resourcesToShow = resourcesToShow.where((resource) => resource.type != ResourceType.image).toList(); + } + break; + case "image url": + if (!selectedTypes.contains(type)) { + resourcesToShow = resourcesToShow.where((resource) => resource.type != ResourceType.imageUrl).toList(); + } + break; + case "video": + if (!selectedTypes.contains(type)) { + resourcesToShow = resourcesToShow.where((resource) => resource.type != ResourceType.video).toList(); + } + break; + case "video url": + if (!selectedTypes.contains(type)) { + resourcesToShow = resourcesToShow.where((resource) => resource.type != ResourceType.videoUrl).toList(); + } + break; + } + }); + } } boxDecoration(dynamic resourceDetailDTO, appContext) { diff --git a/lib/constants.dart b/lib/constants.dart index 08cc0a1..760a0d2 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -15,6 +15,7 @@ const kBlack = Color(0xFF000000); const List section_types = ["Map", "Slider", "Video", "Web", "Menu"]; const List map_types = ["none", "normal", "satellite", "terrain", "hybrid"]; const List languages = ["FR", "NL", "EN", "DE"]; +const List resource_types = ["image", "image url", "video", "video url"]; /* const kTextStyle = TextStyle(