Add filter type in resource screen

This commit is contained in:
Thomas Fransolet 2021-05-26 18:14:16 +02:00
parent 019402b4c0
commit b5387880b1
3 changed files with 53 additions and 3 deletions

View File

@ -219,7 +219,7 @@ class _ConfigurationDetailScreenState extends State<ConfigurationDetailScreen> {
child: Icon( child: Icon(
getSectionIcon(element.type), getSectionIcon(element.type),
color: kPrimaryColor, color: kPrimaryColor,
size: 30.0, size: 25,
), ),
), ),
], ],

View File

@ -1,6 +1,7 @@
import 'package:auto_size_text/auto_size_text.dart'; import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:manager_app/Components/fetch_resource_icon.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/Components/string_input_container.dart';
import 'package:manager_app/Screens/Resources/new_resource_popup.dart'; import 'package:manager_app/Screens/Resources/new_resource_popup.dart';
import 'package:manager_app/Screens/Resources/show_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<ResourceBodyGrid> { class _ResourceBodyGridState extends State<ResourceBodyGrid> {
String filter; List<String> filterType;
String filterSearch = '';
List<String> selectedTypes;
List<ResourceDTO> resourcesToShow; List<ResourceDTO> resourcesToShow;
@override @override
void initState() { void initState() {
resourcesToShow = widget.resources; resourcesToShow = widget.resources;
filterType = [resource_types[0], resource_types[1], resource_types[2], resource_types[3]];
super.initState(); super.initState();
} }
@ -52,7 +56,23 @@ class _ResourceBodyGridState extends State<ResourceBodyGrid> {
label: "Recherche:", label: "Recherche:",
onChanged: (String value) { onChanged: (String value) {
setState(() { 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<ResourceBodyGrid> {
); );
} }
} }
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) { boxDecoration(dynamic resourceDetailDTO, appContext) {

View File

@ -15,6 +15,7 @@ const kBlack = Color(0xFF000000);
const List<String> section_types = ["Map", "Slider", "Video", "Web", "Menu"]; const List<String> section_types = ["Map", "Slider", "Video", "Web", "Menu"];
const List<String> map_types = ["none", "normal", "satellite", "terrain", "hybrid"]; const List<String> map_types = ["none", "normal", "satellite", "terrain", "hybrid"];
const List<String> languages = ["FR", "NL", "EN", "DE"]; const List<String> languages = ["FR", "NL", "EN", "DE"];
const List<String> resource_types = ["image", "image url", "video", "video url"];
/* /*
const kTextStyle = TextStyle( const kTextStyle = TextStyle(