2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-05-01 06:56:50 +00:00

Improves search filtering of part results

This commit is contained in:
Oliver Walters 2021-03-04 23:18:21 +11:00
parent ce4338f244
commit fe2913529b
2 changed files with 58 additions and 36 deletions

View File

@ -283,32 +283,8 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
children: detailTiles()
);
case 1:
return Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
getCategoryDescriptionCard(extra: false),
ListTile(
title: Text(
I18N.of(context).parts,
style: TextStyle(fontWeight: FontWeight.bold),
),
trailing: Text(
"${partCount}",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Divider(height: 3),
Expanded(
child: PaginatedPartList(
{"category": "${category?.pk ?? null}"},
onTotalChanged: (int total) {
setState(() {
partCount = total;
});
},
)
)
],
return PaginatedPartList(
{"category": "${category?.pk ?? null}"},
);
case 2:
return ListView(
@ -410,6 +386,8 @@ class _PaginatedPartListState extends State<PaginatedPartList> {
super.dispose();
}
int resultCount = 0;
Future<void> _fetchPage(int pageKey) async {
try {
@ -445,6 +423,10 @@ class _PaginatedPartListState extends State<PaginatedPartList> {
onTotalChanged(page.count);
}
setState(() {
resultCount = page.count;
});
} catch (error) {
print("Error! - ${error.toString()}");
_pagingController.error = error;
@ -484,13 +466,43 @@ class _PaginatedPartListState extends State<PaginatedPartList> {
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
PaginatedSearch(
callback: updateSearchTerm,
results: resultCount
),
Expanded(
child: CustomScrollView(
shrinkWrap: true,
physics: ClampingScrollPhysics(),
scrollDirection: Axis.vertical,
slivers: [
PagedSliverList.separated(
pagingController: _pagingController,
builderDelegate: PagedChildBuilderDelegate<InvenTreePart>(
itemBuilder: (context, item, index) {
return _buildPart(context, item);
},
noItemsFoundIndicatorBuilder: (context) {
return NoResultsWidget("No parts found");
},
),
separatorBuilder: (context, index) => const Divider(height: 1),
)
],
)
)
],
);
return CustomScrollView(
shrinkWrap: true,
physics: ClampingScrollPhysics(),
scrollDirection: Axis.vertical,
slivers: <Widget>[
// TODO: Introduce searching within the list
//PaginatedSearch(callback: updateSearchTerm),
PaginatedSearch(callback: updateSearchTerm),
PagedSliverList.separated(
pagingController: _pagingController,
builderDelegate: PagedChildBuilderDelegate<InvenTreePart>(

View File

@ -9,17 +9,28 @@ class PaginatedSearch extends StatelessWidget {
Function callback;
PaginatedSearch({this.callback});
int results = 0;
PaginatedSearch({this.callback, this.results});
@override
Widget build(BuildContext context) {
return SliverToBoxAdapter(
child: TextField(
onChanged: callback,
decoration: InputDecoration(
hintText: "Search",
),
)
return ListTile(
leading: FaIcon(FontAwesomeIcons.search),
title: TextField(
onChanged: (value) {
if (callback != null) {
callback(value);
}
},
decoration: InputDecoration(
hintText: "Search parts",
),
),
trailing: Text(
"${results}",
style: TextStyle(fontWeight: FontWeight.bold),
),
);
}
}
@ -41,4 +52,3 @@ class NoResultsWidget extends StatelessWidget {
}
}