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
This commit is contained in:
Jakob Meier 2023-04-05 09:23:41 +02:00
parent 5b398eb2ae
commit eba0790f7c
No known key found for this signature in database
GPG key ID: 66BDC7E6A01A6152
5 changed files with 22 additions and 15 deletions

View file

@ -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<int> get asList {
return [
addArticles,
removeArticles,
addShoppingListItems,
removeShoppingListItems,
editRoomContent,
changeMeta,
ota,

View file

@ -31,6 +31,7 @@ Future<Response> postWithCreadentials(
required User credentials}) async {
Map<String, String> headers = {
"Content-Type": "application/json",
'Connection': 'keep-alive',
'Authorization':
'Digest name=${credentials.username} server=${target.tag} accountKey=${credentials.password}'
};

View file

@ -178,6 +178,7 @@ class _RoomCategoriesPageState extends State<RoomCategoriesPage> {
credentials: user),
onOK: (_) async {
// TODO: remove cached category
fetchCategories();
},
after: () {
// close popup
@ -232,10 +233,10 @@ class _RoomCategoriesPageState extends State<RoomCategoriesPage> {
});
},
),
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),

View file

@ -200,12 +200,15 @@ class _ShoppingListPageState extends State<ShoppingListPage> {
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<ShoppingListPage> {
},
)
]),
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),

View file

@ -81,10 +81,10 @@ class _RoomProductsPageState extends State<RoomProductsPage> {
);
},
),
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),