2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-13 10:45:29 +00:00

Allow model class to be filtered

- Each subclass should provide a custom filtering function
This commit is contained in:
Oliver Walters
2020-04-03 14:27:39 +11:00
parent ee7ab5308e
commit 728597fcdc
4 changed files with 50 additions and 2 deletions

View File

@ -28,6 +28,17 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
List<InvenTreeStockLocation> _sublocations = List<InvenTreeStockLocation>();
String _locationFilter = '';
List<InvenTreeStockLocation> get sublocations {
if (_locationFilter.isEmpty || _sublocations.isEmpty) {
return _sublocations;
} else {
return _sublocations.where((loc) => loc.filter(_locationFilter)).toList();
}
}
List<InvenTreeStockItem> _items = List<InvenTreeStockItem>();
String get _title {
@ -86,7 +97,17 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
textAlign: TextAlign.left,
style: TextStyle(fontWeight: FontWeight.bold),
),
Expanded(child: SublocationList(_sublocations)),
TextField(
decoration: InputDecoration(
hintText: "Filter locations",
),
onChanged: (text) {
setState(() {
_locationFilter = text.trim().toLowerCase();
});
},
),
Expanded(child: SublocationList(sublocations)),
Divider(),
Text(
"Stock Items - ${_items.length}",