Skip to content

Commit

Permalink
On the product page: ensure to refresh the screen if the product is a…
Browse files Browse the repository at this point in the history
…dded/removed to a list (#4486)
  • Loading branch information
g123k authored Aug 9, 2023
1 parent de837d3 commit 69b3b43
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class _ProductPageState extends State<ProductPage>
context,
<String>{widget.product.barcode!},
);
if (refreshed != null && refreshed) {
if (refreshed == true) {
setState(() {});
}
}
Expand Down
17 changes: 12 additions & 5 deletions packages/smooth_app/lib/pages/product_list_user_dialog_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class ProductListUserDialogHelper {
builder: (BuildContext context) => _UserEmptyLists(daoProductList),
);
if (newListCreated != null && newListCreated) {
showUserAddProductsDialog(context, barcodes);
return showUserAddProductsDialog(context, barcodes);
}
return false;
}
Expand All @@ -216,6 +216,8 @@ class ProductListUserDialogHelper {
lists: lists.toSet(),
selectedLists: selectedLists.toSet(),
onListsSubmitted: (Set<String> newSelectedLists) async {
bool hasChanged = false;

for (final String list in lists) {
// Nothing changed
if (selectedLists.contains(list) &&
Expand All @@ -226,6 +228,7 @@ class ProductListUserDialogHelper {
// List got selected
if (!selectedLists.contains(list) &&
newSelectedLists.contains(list)) {
hasChanged = true;
await daoProductList.bulkSet(
ProductList.user(list),
barcodes.toList(),
Expand All @@ -235,13 +238,16 @@ class ProductListUserDialogHelper {
// List got unselected
if (selectedLists.contains(list) &&
!newSelectedLists.contains(list)) {
hasChanged = true;
await daoProductList.bulkSet(
ProductList.user(list),
barcodes.toList(),
include: false,
);
}
}

return hasChanged;
},
),
);
Expand All @@ -260,7 +266,7 @@ class _UserLists extends StatefulWidget {

final Set<String> lists;
final Set<String> selectedLists;
final void Function(Set<String> selectedLists) onListsSubmitted;
final Future<bool> Function(Set<String> selectedLists) onListsSubmitted;

@override
State<_UserLists> createState() => _UserListsState();
Expand All @@ -285,9 +291,10 @@ class _UserListsState extends State<_UserLists> {
negativeAction: _cancelButton(appLocalizations, context),
positiveAction: SmoothActionButton(
text: appLocalizations.save,
onPressed: () {
widget.onListsSubmitted.call(selectedLists);
Navigator.of(context).pop();
onPressed: () async {
Navigator.of(context).pop(
await widget.onListsSubmitted(selectedLists),
);
},
),
body: Column(
Expand Down

0 comments on commit 69b3b43

Please sign in to comment.