From eba0790f7c40a89d9514616023382459e2e3149b Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 5 Apr 2023 09:23:41 +0200 Subject: [PATCH] More bug fixes (see description) - Fixed bug where opening room would show null-error, for a couple of seconds. This was caused by the FAB not checking if widget.info!=null - Added try&catch for item category, to prevent index-out-of-bounds when the item uses a category that no longer exists - Renamed add/remove Articles to fit the new name: ShoppingListItem --- lib/backend/permissions.dart | 8 ++++---- lib/backend/request.dart | 1 + lib/screens/room/pages/categories.dart | 5 +++-- lib/screens/room/pages/list.dart | 19 ++++++++++++------- lib/screens/room/pages/products.dart | 4 ++-- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/backend/permissions.dart b/lib/backend/permissions.dart index 0e78859..d5d6f5a 100644 --- a/lib/backend/permissions.dart +++ b/lib/backend/permissions.dart @@ -62,11 +62,11 @@ class ServerPermission { } class RoomPermission { - static int get addArticles { + static int get addShoppingListItems { return oB("0000001"); } - static int get removeArticles { + static int get removeShoppingListItems { return oB("0000010"); } @@ -92,8 +92,8 @@ class RoomPermission { static List get asList { return [ - addArticles, - removeArticles, + addShoppingListItems, + removeShoppingListItems, editRoomContent, changeMeta, ota, diff --git a/lib/backend/request.dart b/lib/backend/request.dart index cbb7ffc..cb966ec 100644 --- a/lib/backend/request.dart +++ b/lib/backend/request.dart @@ -31,6 +31,7 @@ Future postWithCreadentials( required User credentials}) async { Map headers = { "Content-Type": "application/json", + 'Connection': 'keep-alive', 'Authorization': 'Digest name=${credentials.username} server=${target.tag} accountKey=${credentials.password}' }; diff --git a/lib/screens/room/pages/categories.dart b/lib/screens/room/pages/categories.dart index 8617c71..b14fc35 100644 --- a/lib/screens/room/pages/categories.dart +++ b/lib/screens/room/pages/categories.dart @@ -178,6 +178,7 @@ class _RoomCategoriesPageState extends State { credentials: user), onOK: (_) async { // TODO: remove cached category + fetchCategories(); }, after: () { // close popup @@ -232,10 +233,10 @@ class _RoomCategoriesPageState extends State { }); }, ), - floatingActionButton: ((widget.info?.isAdmin ?? false) || + floatingActionButton: (widget.info != null && ((widget.info?.isAdmin ?? false) || (widget.info?.isOwner ?? false) || ((widget.info?.permissions)! & RoomPermission.editRoomContent != - 0)) + 0))) ? FloatingActionButton.extended( icon: const Icon(Icons.add), label: Text(AppLocalizations.of(context)!.newCategoryShort), diff --git a/lib/screens/room/pages/list.dart b/lib/screens/room/pages/list.dart index ef825d8..17fc8a8 100644 --- a/lib/screens/room/pages/list.dart +++ b/lib/screens/room/pages/list.dart @@ -200,12 +200,15 @@ class _ShoppingListPageState extends State { itemBuilder: (context, index) { final item = list[index]; + RoomCategory cat = RoomCategory.other(context); + try { + cat = categories[item.category!]; + }catch(_){} + return ShoppingListItem( name: item.name, description: item.description, - category: (item.category != null) - ? categories[item.category!] - : RoomCategory.other(context), + category: cat, key: Key(item.id.toString()), inCart: item.state != 0, onDismiss: () { @@ -294,10 +297,12 @@ class _ShoppingListPageState extends State { }, ) ]), - floatingActionButton: ((widget.info?.isAdmin ?? false) || - (widget.info?.isOwner ?? false) || - ((widget.info?.permissions)! & RoomPermission.editRoomContent != - 0)) + floatingActionButton: (widget.info != null && + ((widget.info?.isAdmin ?? false) || + (widget.info?.isOwner ?? false) || + ((widget.info?.permissions)! & + RoomPermission.addShoppingListItems != + 0))) ? FloatingActionButton.extended( icon: const Icon(Icons.add), label: Text(AppLocalizations.of(context)!.newItemShort), diff --git a/lib/screens/room/pages/products.dart b/lib/screens/room/pages/products.dart index 1c9fdbd..b0f80d4 100644 --- a/lib/screens/room/pages/products.dart +++ b/lib/screens/room/pages/products.dart @@ -81,10 +81,10 @@ class _RoomProductsPageState extends State { ); }, ), - floatingActionButton: ((widget.info?.isAdmin ?? false) || + floatingActionButton: (widget.info != null && ((widget.info?.isAdmin ?? false) || (widget.info?.isOwner ?? false) || ((widget.info?.permissions)! & RoomPermission.editRoomContent != - 0)) + 0))) ? FloatingActionButton.extended( icon: const Icon(Icons.add), label: Text(AppLocalizations.of(context)!.newProductShort),