goToChat function
- dynamic localContext,
- String roomId
helper to figure out how to route to the specific chat room
Implementation
void goToChat(BuildContext localContext, String roomId) {
final currentUri = mainProviderContainer.read(currentRoutingLocation);
if (!currentUri.startsWith(chatRoomUriMatcher)) {
// we are not in a chat room. just a regular push routing
// will do
navigateOnRightBranch(
localContext,
ShellBranch.chatsShell,
(navContext) => navContext
.pushNamed(Routes.chatroom.name, pathParameters: {'roomId': roomId}),
);
return;
}
// we are in a chat page
if (roomId == mainProviderContainer.read(selectedChatIdProvider)) {
// we are on the same page, nothing to be done
return;
}
// we are on a different chat page. Push replace the current screen
(rootNavKey.currentContext ?? localContext).pushReplacementNamed(
Routes.chatroom.name,
pathParameters: {'roomId': roomId},
);
}