mirror of
https://github.com/inventree/inventree-app.git
synced 2025-05-01 15:06:49 +00:00
Improves search filtering of part results
This commit is contained in:
parent
ce4338f244
commit
fe2913529b
@ -283,32 +283,8 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
children: detailTiles()
|
children: detailTiles()
|
||||||
);
|
);
|
||||||
case 1:
|
case 1:
|
||||||
return Column(
|
return PaginatedPartList(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
{"category": "${category?.pk ?? null}"},
|
||||||
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;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
case 2:
|
case 2:
|
||||||
return ListView(
|
return ListView(
|
||||||
@ -410,6 +386,8 @@ class _PaginatedPartListState extends State<PaginatedPartList> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int resultCount = 0;
|
||||||
|
|
||||||
Future<void> _fetchPage(int pageKey) async {
|
Future<void> _fetchPage(int pageKey) async {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -445,6 +423,10 @@ class _PaginatedPartListState extends State<PaginatedPartList> {
|
|||||||
onTotalChanged(page.count);
|
onTotalChanged(page.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
resultCount = page.count;
|
||||||
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
print("Error! - ${error.toString()}");
|
print("Error! - ${error.toString()}");
|
||||||
_pagingController.error = error;
|
_pagingController.error = error;
|
||||||
@ -484,13 +466,43 @@ class _PaginatedPartListState extends State<PaginatedPartList> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
return CustomScrollView(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
physics: ClampingScrollPhysics(),
|
physics: ClampingScrollPhysics(),
|
||||||
scrollDirection: Axis.vertical,
|
scrollDirection: Axis.vertical,
|
||||||
slivers: <Widget>[
|
slivers: <Widget>[
|
||||||
// TODO: Introduce searching within the list
|
// TODO: Introduce searching within the list
|
||||||
//PaginatedSearch(callback: updateSearchTerm),
|
PaginatedSearch(callback: updateSearchTerm),
|
||||||
PagedSliverList.separated(
|
PagedSliverList.separated(
|
||||||
pagingController: _pagingController,
|
pagingController: _pagingController,
|
||||||
builderDelegate: PagedChildBuilderDelegate<InvenTreePart>(
|
builderDelegate: PagedChildBuilderDelegate<InvenTreePart>(
|
||||||
|
@ -9,17 +9,28 @@ class PaginatedSearch extends StatelessWidget {
|
|||||||
|
|
||||||
Function callback;
|
Function callback;
|
||||||
|
|
||||||
PaginatedSearch({this.callback});
|
int results = 0;
|
||||||
|
|
||||||
|
PaginatedSearch({this.callback, this.results});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SliverToBoxAdapter(
|
return ListTile(
|
||||||
child: TextField(
|
leading: FaIcon(FontAwesomeIcons.search),
|
||||||
onChanged: callback,
|
title: TextField(
|
||||||
decoration: InputDecoration(
|
onChanged: (value) {
|
||||||
hintText: "Search",
|
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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user