The project is simple: Login screen and a forgot password screen. You can navigate from Login to ForgotPassword.

I feel like I overcomplicated things, but I don't know if (and how) it can be simplified.

The code: LoginRoute.kt

fun LoginRoute(
    viewModel: LoginViewModel = hiltViewModel(),
    navController: NavHostController,
) {
    val uiState by viewModel.uiState.collectAsStateWithLifecycle()

        uiState = uiState,
        onLoginClicked = {
        onForgotPasswordClicked = {


class LoginNavigationFactory @Inject constructor() : NavigationFactory {

    override fun create(builder: NavGraphBuilder, navController: NavHostController) {
        builder.composable(NavigationDestination.Login.route) {
            LoginRoute(navController = navController)
        builder.composable(NavigationDestination.ForgotPassword.route) {

Do I really need to pass navController as an argument to the Routes? If I don't do it and simply do rememberNavController in the composable, it gives me NullPointers.


1 Answer 1


I pass in a delegate and handle navigation at the top. I find this better practice

  • 2
    \$\begingroup\$ Welcome to code review! While it seems that short answers are acceptable are you able to expand this answer, perhaps explaining reasons for the suggestion? \$\endgroup\$ Commented Mar 7, 2023 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.