diff --git a/lib/backend/room.dart b/lib/backend/room.dart index a6eaad8..112f92e 100644 --- a/lib/backend/room.dart +++ b/lib/backend/room.dart @@ -319,15 +319,14 @@ class RoomMember { final String id; final String serverTag; final bool isAdmin; + final bool isInvitePending; const RoomMember( - {required this.id, required this.serverTag, required this.isAdmin}); + {required this.id, required this.serverTag, required this.isAdmin, this.isInvitePending=false}); factory RoomMember.fromJSON(dynamic json) { return RoomMember( - id: json['name'], - serverTag: json['server'], - isAdmin: json['admin'] == 1); + id: json['name'], serverTag: json['server'], isAdmin: json['admin'], isInvitePending: json['confirmed']); } String get humanReadableName { diff --git a/lib/screens/room/about/members.dart b/lib/screens/room/about/members.dart index 97d4716..82745c6 100644 --- a/lib/screens/room/about/members.dart +++ b/lib/screens/room/about/members.dart @@ -96,8 +96,8 @@ class _ManageRoomMembersPageState extends State { return Scaffold( appBar: AppBar( - title: Text( - AppLocalizations.of(context)!.roomMembersTitle(list.length)), + title: + Text(AppLocalizations.of(context)!.roomMembersTitle(list.length)), //actions: [ // // NOTE: Maybe add a search icon // // and general search functionality here @@ -166,29 +166,46 @@ class _ManageRoomMembersPageState extends State { leading: const Icon( Icons.supervisor_account), title: Text(item.isAdmin - ? AppLocalizations.of(context)!.removeAdminTitle - : AppLocalizations.of(context)!.makeAdminTitle), + ? AppLocalizations.of( + context)! + .removeAdminTitle + : AppLocalizations.of( + context)! + .makeAdminTitle), subtitle: Text(item.isAdmin - ? AppLocalizations.of(context)!.removeAdminSubtitle - : AppLocalizations.of(context)!.makeAdminSubtitle), + ? AppLocalizations.of( + context)! + .removeAdminSubtitle + : AppLocalizations.of( + context)! + .makeAdminSubtitle), onTap: () { // make user admin showDialog( context: context, builder: - (context) => + (ctx) => AlertDialog( icon: const Icon( Icons .supervisor_account), - title: Text(item - .isAdmin - ? AppLocalizations.of(context)!.removeAdminTitle - : AppLocalizations.of(context)!.makeAdminTitle), + title: Text(item.isAdmin + ? AppLocalizations.of( + context)! + .removeAdminTitle + : AppLocalizations.of( + context)! + .makeAdminTitle), content: Text(item .isAdmin - ? AppLocalizations.of(context)!.removeAdminConfirm(item.humanReadableName) - : AppLocalizations.of(context)!.makeAdminConfirm(item.humanReadableName)), + ? AppLocalizations.of( + context)! + .removeAdminConfirm(item + .humanReadableName) + : AppLocalizations.of( + context)! + .makeAdminConfirm( + item.humanReadableName)), actions: [ TextButton( onPressed: @@ -196,10 +213,12 @@ class _ManageRoomMembersPageState extends State { // close popup // NOTE: cancel only closes the dialog // whilst OK closes both - Navigator.of(context) + Navigator.of(ctx) .pop(); }, - child: Text(AppLocalizations.of(context)!.cancel), + child: Text( + AppLocalizations.of(context)! + .cancel), ), FilledButton( onPressed: @@ -208,6 +227,8 @@ class _ManageRoomMembersPageState extends State { final scaffMgr = ScaffoldMessenger.of(context); final nav = + Navigator.of(ctx); + final nav2 = Navigator.of(context); final user = context.read(); @@ -228,10 +249,13 @@ class _ManageRoomMembersPageState extends State { after: () { // close popup nav.pop(); - nav.pop(); + // close bottom sheet + nav2.pop(); }); }, - child: Text(AppLocalizations.of(context)!.ok), + child: Text( + AppLocalizations.of(context)! + .ok), ) ], )); @@ -249,8 +273,14 @@ class _ManageRoomMembersPageState extends State { ListTile( leading: const Icon( Icons.person_remove), - title: Text(AppLocalizations.of(context)!.kickUserTitle), - subtitle: Text(AppLocalizations.of(context)!.kickUserSubtitle), + title: Text( + AppLocalizations.of( + context)! + .kickUserTitle), + subtitle: Text( + AppLocalizations.of( + context)! + .kickUserSubtitle), onTap: () { // remove user from room showDialog( @@ -261,10 +291,13 @@ class _ManageRoomMembersPageState extends State { icon: const Icon( Icons .person_remove), - title: Text( - AppLocalizations.of(context)!.kickUserTitle), - content: Text( - AppLocalizations.of(context)!.kichUserConfirm(item.humanReadableName)), + title: Text(AppLocalizations.of( + context)! + .kickUserTitle), + content: Text(AppLocalizations.of( + context)! + .kichUserConfirm( + item.humanReadableName)), actions: [ TextButton( onPressed: @@ -277,7 +310,8 @@ class _ManageRoomMembersPageState extends State { .pop(); }, child: Text( - AppLocalizations.of(context)!.cancel), + AppLocalizations.of(context)! + .cancel), ), FilledButton( onPressed: @@ -287,6 +321,8 @@ class _ManageRoomMembersPageState extends State { ScaffoldMessenger.of(ctx); final nav = Navigator.of(ctx); + final nav2 = + Navigator.of(context); final user = context.read(); @@ -305,11 +341,13 @@ class _ManageRoomMembersPageState extends State { after: () { // close popup nav.pop(); - nav.pop(); + // close bottom sheet + nav2.pop(); }); }, child: Text( - AppLocalizations.of(context)!.ok), + AppLocalizations.of(context)! + .ok), ) ], )); @@ -321,7 +359,8 @@ class _ManageRoomMembersPageState extends State { ), ), FilledButton( - child: Text(AppLocalizations.of(context)!.close), + child: Text( + AppLocalizations.of(context)!.close), onPressed: () { Navigator.of(context).pop(); }, diff --git a/lib/screens/room/pages/categories.dart b/lib/screens/room/pages/categories.dart index beafb7d..8617c71 100644 --- a/lib/screens/room/pages/categories.dart +++ b/lib/screens/room/pages/categories.dart @@ -45,9 +45,12 @@ class _RoomCategoriesPageState extends State { final resp = json['data'] .map((raw) => RoomCategory.fromJSON(raw)) .toList(); - setState(() { - list = resp; - }); + + if (mounted) { + setState(() { + list = resp; + }); + } }); } @@ -72,9 +75,7 @@ class _RoomCategoriesPageState extends State { RoomPermission.editRoomContent != 0)) ? ReorderableDragStartListener( - index: index, - child: const Icon(Icons.drag_handle) - ) + index: index, child: const Icon(Icons.drag_handle)) : null, title: Text(item.name), onTap: () { @@ -201,11 +202,9 @@ class _RoomCategoriesPageState extends State { }, itemCount: list.length, onReorder: (int oldIndex, int newIndex) { - if (!((widget.info?.isAdmin ?? false) || (widget.info?.isOwner ?? false) || - ((widget.info?.permissions)! & - RoomPermission.editRoomContent != + ((widget.info?.permissions)! & RoomPermission.editRoomContent != 0))) { // user is not allowed to edit or delete categories return; @@ -235,9 +234,9 @@ class _RoomCategoriesPageState extends State { ), floatingActionButton: ((widget.info?.isAdmin ?? false) || (widget.info?.isOwner ?? false) || - ((widget.info?.permissions)! & - RoomPermission.editRoomContent != - 0))?FloatingActionButton.extended( + ((widget.info?.permissions)! & RoomPermission.editRoomContent != + 0)) + ? FloatingActionButton.extended( icon: const Icon(Icons.add), label: Text(AppLocalizations.of(context)!.newCategoryShort), tooltip: AppLocalizations.of(context)!.newCategoryLong, @@ -248,7 +247,8 @@ class _RoomCategoriesPageState extends State { 'id': widget.room!.id, }); }, - ):null, + ) + : null, ); } } diff --git a/lib/screens/room/pages/list.dart b/lib/screens/room/pages/list.dart index e11c63e..ef825d8 100644 --- a/lib/screens/room/pages/list.dart +++ b/lib/screens/room/pages/list.dart @@ -58,12 +58,14 @@ class _ShoppingListPageState extends State { // TODO: cache items - setState(() { - list = l; - cart = c; + if (mounted) { + setState(() { + list = l; + cart = c; - sortAll(); - }); + sortAll(); + }); + } }); } @@ -125,11 +127,14 @@ class _ShoppingListPageState extends State { for (int i = 0; i < resp.length; i++) { map[resp[i].id] = i; } - setState(() { - weights = map; - categories = resp; - sortAll(); - }); + + if (mounted) { + setState(() { + weights = map; + categories = resp; + sortAll(); + }); + } }); } @@ -149,9 +154,11 @@ class _ShoppingListPageState extends State { .map((raw) => RoomProduct.fromJSON(raw)) .toList(); - setState(() { - products = resp; - }); + if (mounted) { + setState(() { + products = resp; + }); + } }); } @@ -352,7 +359,9 @@ class ShoppingListItem extends StatelessWidget { enabled: !inCart, title: Text(name), subtitle: Text(description), - trailing: CategoryChip(category: category,), + trailing: CategoryChip( + category: category, + ), onTap: () { if (onTap != null) { onTap!(); @@ -396,8 +405,9 @@ class ShoppingListItemInfo extends StatelessWidget { selected: item.category, enabled: false), ProductPicker( - label:AppLocalizations.of(context)!.selectLinkedProductLabel, - help:AppLocalizations.of(context)!.selectLinkedProductHelp, + label: + AppLocalizations.of(context)!.selectLinkedProductLabel, + help: AppLocalizations.of(context)!.selectLinkedProductHelp, products: products, selected: item.link, enabled: false) diff --git a/lib/screens/room/pages/products.dart b/lib/screens/room/pages/products.dart index 1c5d89b..1c9fdbd 100644 --- a/lib/screens/room/pages/products.dart +++ b/lib/screens/room/pages/products.dart @@ -37,9 +37,11 @@ class _RoomProductsPageState extends State { // TODO: cache products - setState(() { - products = resp; - }); + if (mounted) { + setState(() { + products = resp; + }); + } }); }