Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Categorize recent items #149 #404

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions kitchenowl/lib/pages/household_page/shoppinglist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ class _ShoppinglistPageState extends State<ShoppinglistPage> {
shoppingList: state.selectedShoppinglist,
onRefresh: cubit.refresh,
isLoading: state is LoadingShoppinglistCubitState,
splitByCategories: !(state.sorting !=
ShoppinglistSorting.category ||
state is LoadingShoppinglistCubitState &&
state.listItems.isEmpty),
),
],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class SliverCategoryItemGridList<T extends Item> extends StatefulWidget {
final bool isLoading;
final bool? allRaised;
final Widget Function(T)? extraOption;
final bool isSubTitle;
final bool splitByCategories;

const SliverCategoryItemGridList({
super.key,
Expand All @@ -35,6 +37,8 @@ class SliverCategoryItemGridList<T extends Item> extends StatefulWidget {
this.isLoading = false,
this.allRaised,
this.extraOption,
this.isSubTitle = false,
this.splitByCategories = false,
});

@override
Expand All @@ -48,6 +52,53 @@ class _SliverCategoryItemGridListState<T extends Item>

@override
Widget build(BuildContext context) {
TextStyle? titleTextStyle = Theme.of(context).textTheme.titleLarge;
if (widget.isSubTitle)
titleTextStyle = titleTextStyle?.apply(fontStyle: FontStyle.italic, fontWeightDelta: -1);

List<Widget> list = [];
final categoryLength = widget.categories?.length ?? 0;

if (widget.splitByCategories) {
for (int i = 0; i < categoryLength + 1; i++) {
Category? category = i < categoryLength
? widget.categories![i]
: null;
final List<T> items = widget.items
.where((e) => e.category == category)
.toList();
if (items.isEmpty) continue;

list.add(SliverCategoryItemGridList(
name: category?.name ??
AppLocalizations.of(context)!.uncategorized,
items: items,
categories: widget.categories,
shoppingList: widget.shoppingList,
selected: widget.selected,
isLoading: widget.isLoading,
onRefresh: widget.onRefresh,
onPressed: widget.onPressed,
isSubTitle: true,
allRaised: widget.allRaised,
extraOption: widget.extraOption,
));
}
}
else
list.add(SliverItemGridList<T>(
onRefresh: widget.onRefresh,
onPressed: widget.onPressed,
onLongPressed: widget.onLongPressed,
items: widget.items,
categories: widget.categories,
shoppingList: widget.shoppingList,
selected: widget.selected,
isLoading: widget.isLoading,
allRaised: widget.allRaised,
extraOption: widget.extraOption,
));

return SliverMainAxisGroup(
slivers: [
SliverToBoxAdapter(
Expand All @@ -64,7 +115,7 @@ class _SliverCategoryItemGridListState<T extends Item>
Expanded(
child: Text(
widget.name,
style: Theme.of(context).textTheme.titleLarge,
style: titleTextStyle,
),
),
IconButton(
Expand All @@ -86,18 +137,7 @@ class _SliverCategoryItemGridListState<T extends Item>
duration: widget.animationDuration,
child: !isExpanded
? const SliverToBoxAdapter(child: SizedBox())
: SliverItemGridList<T>(
onRefresh: widget.onRefresh,
onPressed: widget.onPressed,
onLongPressed: widget.onLongPressed,
items: widget.items,
categories: widget.categories,
shoppingList: widget.shoppingList,
selected: widget.selected,
isLoading: widget.isLoading,
allRaised: widget.allRaised,
extraOption: widget.extraOption,
),
: MultiSliver(children: list),
),
],
);
Expand Down