Thread
#compose
    Nat Strangerweather

    Nat Strangerweather

    1 year ago
    I am finally starting with Navigation but I am stuck with a basic problem:
    Scaffold(
                scaffoldState = scaffoldState,
                drawerContent = {
                    HomePageDrawer()
                },
    For HomePageDrawer() I get : "No value passed for parameter 'navController'". What am I supposed to put for parameter navController? Whatever I try gives me a nullpointer... Basically I have some items in my drawer and I want to navigate to other screens from them...
    i

    Ian Lake

    1 year ago
    The Getting Started part of the guide (https://developer.android.com/jetpack/compose/navigation#getting-started) states that you should be using
    rememberNavController()
    outside of your
    Scaffold
    I.e., in a place where every Composable that needs to access it can access it
    Nat Strangerweather

    Nat Strangerweather

    1 year ago
    I'm using it in my navigation composable:
    @Composable
    fun ApplicationNavigation() {
        val navController = rememberNavController()
        androidx.navigation.compose.NavHost(
            navController = navController,
            startDestination = "homepage"
        ) {
            composable("homepage") {
                HomePage()
            }
            composable("drawer"){
                HomePageDrawer(navController)
            }
            composable("placeholder"){
                PlaceHolder()
            }
        }
    But how can I refer to it in my HomePage Scaffold? I'm a bit confused.
    Hmm, I'll try to do what you suggested and as the doc indicates, thanks.
    i

    Ian Lake

    1 year ago
    Just pass in
    navController
    n

    Nikola Drljaca

    1 year ago
    You could also consider passing a lambda instead of passing the
    navController
    , that way you can keep all navigation related code in one place and not pass the
    navController
    around
    Nat Strangerweather

    Nat Strangerweather

    1 year ago
    @Nikola Drljaca Thanks for this, I'm interested in your idea. Would you be able to show me how it would look, if you have the time? Maybe with my example above?
    n

    Nikola Drljaca

    1 year ago
    Well, here is a quick example of something thats similar to what I use. For your example, I think you can pass the lambda down your composable tree to wherever you need to call
    navigate()
    . Maybe the parent of the scaffold can have a lambda and pass it to the
    HomePageDrawer()
    . Anyway, here's a gist https://gist.github.com/nikolaDrljaca/06013137c325638ac6b71ca3ac76c681
    Of course, this might not be the "proper" way to do it, but to me it seemed cleaner than passing the
    navController
    everywhere.
    Nat Strangerweather

    Nat Strangerweather

    1 year ago
    Thanks for this, really appreciate it
    i

    Ian Lake

    1 year ago
    Yep, that's actually the recommended practice to make your composables separately testable (from a bit farther down that exact same page I linked earlier): https://developer.android.com/jetpack/compose/navigation#testing
    Nat Strangerweather

    Nat Strangerweather

    1 year ago
    Oh excellent, thanks, I really need to start reading the doc more carefully! 😉