From e283b6a34672c65d03792305116df6c32768e07d Mon Sep 17 00:00:00 2001 From: Sorunome Date: Sun, 15 Aug 2021 13:26:16 +0200 Subject: [PATCH] fix: use vrouter.toSegments --- lib/config/routes.dart | 2 +- lib/pages/chat.dart | 2 +- lib/pages/chat_list.dart | 2 +- lib/pages/new_group.dart | 2 +- lib/pages/new_private_chat.dart | 2 +- lib/pages/new_space.dart | 2 +- lib/pages/search.dart | 2 +- lib/pages/user_bottom_sheet.dart | 3 ++- lib/pages/views/chat_details_view.dart | 13 +++++++------ .../views/chat_encryption_settings_view.dart | 2 +- .../views/chat_permissions_settings_view.dart | 4 ++-- lib/pages/views/chat_view.dart | 4 ++-- lib/pages/views/invitation_selection_view.dart | 4 ++-- lib/pages/views/search_view.dart | 3 ++- .../views/settings_multiple_emotes_view.dart | 4 ++-- lib/utils/background_push.dart | 2 +- lib/utils/url_launcher.dart | 15 ++++++++------- lib/widgets/chat_settings_popup_menu.dart | 3 ++- lib/widgets/contacts_list.dart | 8 ++++++-- lib/widgets/encryption_button.dart | 2 +- lib/widgets/list_items/chat_list_item.dart | 2 +- lib/widgets/list_items/public_room_list_item.dart | 2 +- 22 files changed, 47 insertions(+), 38 deletions(-) diff --git a/lib/config/routes.dart b/lib/config/routes.dart index e83f75e2..5a554605 100644 --- a/lib/config/routes.dart +++ b/lib/config/routes.dart @@ -139,7 +139,7 @@ class AppRoutes { nestedRoutes: [ VWidget( path: '', - widget: EmptyPage(), + widget: Chat(), buildTransition: _fadeTransition, ), VWidget( diff --git a/lib/pages/chat.dart b/lib/pages/chat.dart index 6eeb868b..5ee3377d 100644 --- a/lib/pages/chat.dart +++ b/lib/pages/chat.dart @@ -617,7 +617,7 @@ class ChatController extends State { future: room.leave, ); if (result.error == null) { - VRouter.of(context).to('/rooms/${result.result}'); + VRouter.of(context).toSegments(['rooms', result.result]); } } diff --git a/lib/pages/chat_list.dart b/lib/pages/chat_list.dart index 575d2e97..84a42330 100644 --- a/lib/pages/chat_list.dart +++ b/lib/pages/chat_list.dart @@ -60,7 +60,7 @@ class ChatListController extends State { void editSpace(BuildContext context, String spaceId) async { Scaffold.of(context).openEndDrawer(); await Matrix.of(context).client.getRoomById(spaceId).postLoad(); - VRouter.of(context).to('/spaces/$spaceId'); + VRouter.of(context).toSegments(['spaces', spaceId]); } List get spaces => diff --git a/lib/pages/new_group.dart b/lib/pages/new_group.dart index 705afba8..c9021bc9 100644 --- a/lib/pages/new_group.dart +++ b/lib/pages/new_group.dart @@ -32,7 +32,7 @@ class NewGroupController extends State { ), ); if (roomID.error == null) { - VRouter.of(context).to('/rooms/${roomID.result}/invite'); + VRouter.of(context).toSegments(['rooms', roomID.result, 'invite']); } } diff --git a/lib/pages/new_private_chat.dart b/lib/pages/new_private_chat.dart index 19ec40bf..06bf5ef7 100644 --- a/lib/pages/new_private_chat.dart +++ b/lib/pages/new_private_chat.dart @@ -47,7 +47,7 @@ class NewPrivateChatController extends State { ); if (roomID.error == null) { - VRouter.of(context).to('/rooms/${roomID.result}'); + VRouter.of(context).toSegments(['rooms', roomID.result]); } } diff --git a/lib/pages/new_space.dart b/lib/pages/new_space.dart index 02ea4442..a7ce5208 100644 --- a/lib/pages/new_space.dart +++ b/lib/pages/new_space.dart @@ -34,7 +34,7 @@ class NewSpaceController extends State { ), ); if (roomID.error == null) { - VRouter.of(context).to('/rooms/${roomID.result}/details'); + VRouter.of(context).toSegments(['rooms', roomID.result, 'details']); } } diff --git a/lib/pages/search.dart b/lib/pages/search.dart index 88ddb6e6..b1f25492 100644 --- a/lib/pages/search.dart +++ b/lib/pages/search.dart @@ -78,7 +78,7 @@ class SearchController extends State { ), ); if (success.error == null) { - VRouter.of(context).to('/rooms/${success.result}'); + VRouter.of(context).toSegments(['rooms', success.result]); } } diff --git a/lib/pages/user_bottom_sheet.dart b/lib/pages/user_bottom_sheet.dart index cc458dc8..8e048fb9 100644 --- a/lib/pages/user_bottom_sheet.dart +++ b/lib/pages/user_bottom_sheet.dart @@ -88,7 +88,8 @@ class UserBottomSheetController extends State { future: () => widget.user.startDirectChat(), ); if (roomIdResult.error != null) return; - VRouter.of(widget.outerContext).to('/rooms/${roomIdResult.result}'); + VRouter.of(widget.outerContext) + .toSegments(['rooms', roomIdResult.result]); Navigator.of(context, rootNavigator: false).pop(); break; } diff --git a/lib/pages/views/chat_details_view.dart b/lib/pages/views/chat_details_view.dart index 867613ca..16d6df50 100644 --- a/lib/pages/views/chat_details_view.dart +++ b/lib/pages/views/chat_details_view.dart @@ -52,11 +52,11 @@ class ChatDetailsView extends StatelessWidget { SliverAppBar( leading: IconButton( icon: Icon(Icons.close_outlined), - onPressed: () => VRouter.of(context) - .path - .startsWith('/spaces/') - ? VRouter.of(context).pop() - : VRouter.of(context).to('/rooms/${controller.roomId}'), + onPressed: () => + VRouter.of(context).path.startsWith('/spaces/') + ? VRouter.of(context).pop() + : VRouter.of(context) + .toSegments(['rooms', controller.roomId]), ), elevation: Theme.of(context).appBarTheme.elevation, expandedHeight: 300.0, @@ -264,7 +264,8 @@ class ChatDetailsView extends StatelessWidget { .visibilityOfTheChatHistory), subtitle: Text( room.historyVisibility.getLocalizedString( - MatrixLocals(L10n.of(context))), + MatrixLocals(L10n.of(context))) ?? + '', ), ), ), diff --git a/lib/pages/views/chat_encryption_settings_view.dart b/lib/pages/views/chat_encryption_settings_view.dart index 3546d567..b8d15de9 100644 --- a/lib/pages/views/chat_encryption_settings_view.dart +++ b/lib/pages/views/chat_encryption_settings_view.dart @@ -23,7 +23,7 @@ class ChatEncryptionSettingsView extends StatelessWidget { leading: IconButton( icon: Icon(Icons.close_outlined), onPressed: () => - VRouter.of(context).to('/rooms/${controller.roomId}'), + VRouter.of(context).toSegments(['rooms', controller.roomId]), ), title: Text(L10n.of(context).tapOnDeviceToVerify), bottom: PreferredSize( diff --git a/lib/pages/views/chat_permissions_settings_view.dart b/lib/pages/views/chat_permissions_settings_view.dart index e0520654..36e63978 100644 --- a/lib/pages/views/chat_permissions_settings_view.dart +++ b/lib/pages/views/chat_permissions_settings_view.dart @@ -22,8 +22,8 @@ class ChatPermissionsSettingsView extends StatelessWidget { ? null : IconButton( icon: Icon(Icons.close_outlined), - onPressed: () => - VRouter.of(context).to('/rooms/${controller.roomId}'), + onPressed: () => VRouter.of(context) + .toSegments(['rooms', controller.roomId]), ), title: Text(L10n.of(context).editChatPermissions), ), diff --git a/lib/pages/views/chat_view.dart b/lib/pages/views/chat_view.dart index fc49e461..ce161243 100644 --- a/lib/pages/views/chat_view.dart +++ b/lib/pages/views/chat_view.dart @@ -98,8 +98,8 @@ class ChatView extends StatelessWidget { '${controller.room.getUserByMXIDSync(controller.room.directChatMatrixID).mention} ', ), ) - : () => VRouter.of(context) - .to('/rooms/${controller.room.id}/details'), + : () => VRouter.of(context).toSegments( + ['rooms', controller.room.id, 'details']), title: Text( controller.room.getLocalizedDisplayname( MatrixLocals(L10n.of(context))), diff --git a/lib/pages/views/invitation_selection_view.dart b/lib/pages/views/invitation_selection_view.dart index 4b3a3188..47508114 100644 --- a/lib/pages/views/invitation_selection_view.dart +++ b/lib/pages/views/invitation_selection_view.dart @@ -25,8 +25,8 @@ class InvitationSelectionView extends StatelessWidget { ? null : IconButton( icon: Icon(Icons.close_outlined), - onPressed: () => - VRouter.of(context).to('/rooms/${controller.roomId}'), + onPressed: () => VRouter.of(context) + .toSegments(['rooms', controller.roomId]), ), titleSpacing: 0, title: DefaultAppBarSearchField( diff --git a/lib/pages/views/search_view.dart b/lib/pages/views/search_view.dart index 5e600107..7ba4df8f 100644 --- a/lib/pages/views/search_view.dart +++ b/lib/pages/views/search_view.dart @@ -239,7 +239,8 @@ class SearchView extends StatelessWidget { .startDirectChat(foundProfile.userId), ); if (roomID.error == null) { - VRouter.of(context).to('/rooms/${roomID.result}'); + VRouter.of(context) + .toSegments(['rooms', roomID.result]); } }, leading: Avatar( diff --git a/lib/pages/views/settings_multiple_emotes_view.dart b/lib/pages/views/settings_multiple_emotes_view.dart index e1cce3d2..15830099 100644 --- a/lib/pages/views/settings_multiple_emotes_view.dart +++ b/lib/pages/views/settings_multiple_emotes_view.dart @@ -44,8 +44,8 @@ class MultipleEmotesSettingsView extends StatelessWidget { return ListTile( title: Text(packName), onTap: () async { - VRouter.of(context) - .to('/rooms/${room.id}/details/emotes/${keys[i]}'); + VRouter.of(context).toSegments( + ['rooms', room.id, 'details', 'emotes', keys[i]]); }, ); }); diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart index 91f02b13..3434c28b 100644 --- a/lib/utils/background_push.dart +++ b/lib/utils/background_push.dart @@ -283,7 +283,7 @@ class BackgroundPush { if (router == null) { return; } - router.currentState.to('/rooms/$roomId'); + router.currentState.toSegments(['rooms', roomId]); } catch (e, s) { Logs().e('[Push] Failed to open room', e, s); } diff --git a/lib/utils/url_launcher.dart b/lib/utils/url_launcher.dart index da69fcde..0081701e 100644 --- a/lib/utils/url_launcher.dart +++ b/lib/utils/url_launcher.dart @@ -110,10 +110,10 @@ class UrlLauncher { if (room != null) { // we have the room, so....just open it if (event != null) { - VRouter.of(context) - .to('/rooms/${room.id}', queryParameters: {'event': event}); + VRouter.of(context).toSegments(['rooms', room.id], + queryParameters: {'event': event}); } else { - VRouter.of(context).to('/rooms/${room.id}'); + VRouter.of(context).toSegments(['rooms', room.id]); } return; } @@ -138,9 +138,10 @@ class UrlLauncher { context: context, future: () => Future.delayed(const Duration(seconds: 2))); if (event != null) { - VRouter.of(context).to('/rooms/${response.result}/$event'); + VRouter.of(context).toSegments(['rooms', response.result], + queryParameters: {'event': event}); } else { - VRouter.of(context).to('/rooms/${response.result}'); + VRouter.of(context).toSegments(['rooms', response.result]); } } } else { @@ -155,7 +156,7 @@ class UrlLauncher { ); var roomId = matrix.client.getDirectChatFromUserId(user.id); if (roomId != null) { - VRouter.of(context).to('/rooms/$roomId'); + VRouter.of(context).toSegments(['rooms', roomId]); return; } @@ -173,7 +174,7 @@ class UrlLauncher { .result; if (roomId != null) { - VRouter.of(context).to('/rooms/$roomId'); + VRouter.of(context).toSegments(['rooms', roomId]); } } } diff --git a/lib/widgets/chat_settings_popup_menu.dart b/lib/widgets/chat_settings_popup_menu.dart index b8c597b6..b340099e 100644 --- a/lib/widgets/chat_settings_popup_menu.dart +++ b/lib/widgets/chat_settings_popup_menu.dart @@ -95,7 +95,8 @@ class _ChatSettingsPopupMenuState extends State { widget.room.setPushRuleState(PushRuleState.notify)); break; case 'details': - VRouter.of(context).to('/rooms/${widget.room.id}/details'); + VRouter.of(context) + .toSegments(['rooms', widget.room.id, 'details']); break; } }, diff --git a/lib/widgets/contacts_list.dart b/lib/widgets/contacts_list.dart index 4a997cfc..3751d747 100644 --- a/lib/widgets/contacts_list.dart +++ b/lib/widgets/contacts_list.dart @@ -102,8 +102,12 @@ class _ContactListTile extends StatelessWidget { fontWeight: FontWeight.bold, ) : null), - onTap: () => VRouter.of(context).to( - '/rooms/${Matrix.of(context).client.getDirectChatFromUserId(contact.senderId)}'), + onTap: () => VRouter.of(context).toSegments([ + 'rooms', + Matrix.of(context) + .client + .getDirectChatFromUserId(contact.senderId) + ]), ); }); } diff --git a/lib/widgets/encryption_button.dart b/lib/widgets/encryption_button.dart index 0c8f9535..3d044ced 100644 --- a/lib/widgets/encryption_button.dart +++ b/lib/widgets/encryption_button.dart @@ -21,7 +21,7 @@ class _EncryptionButtonState extends State { void _enableEncryptionAction() async { if (widget.room.encrypted) { - VRouter.of(context).to('/rooms/${widget.room.id}/encryption'); + VRouter.of(context).toSegments(['rooms', widget.room.id, 'encryption']); return; } if (widget.room.joinRules == JoinRules.public) { diff --git a/lib/widgets/list_items/chat_list_item.dart b/lib/widgets/list_items/chat_list_item.dart index ee7af093..d34bf9ee 100644 --- a/lib/widgets/list_items/chat_list_item.dart +++ b/lib/widgets/list_items/chat_list_item.dart @@ -112,7 +112,7 @@ class ChatListItem extends StatelessWidget { } Matrix.of(context).shareContent = null; } - VRouter.of(context).to('/rooms/${room.id}'); + VRouter.of(context).toSegments(['rooms', room.id]); } } } diff --git a/lib/widgets/list_items/public_room_list_item.dart b/lib/widgets/list_items/public_room_list_item.dart index 5870f9d0..3fb3b44f 100644 --- a/lib/widgets/list_items/public_room_list_item.dart +++ b/lib/widgets/list_items/public_room_list_item.dart @@ -18,7 +18,7 @@ class PublicRoomListItem extends StatelessWidget { future: () => _joinRoomAndWait(context), ); if (success.error == null) { - VRouter.of(context).toNamed('/rooms/${success.result}'); + VRouter.of(context).toSegments(['rooms', success.result]); } }