Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No method navigate(String) in compose-navigation

I'm trying the new jetpack library "compose-navigation".

According to the docs, to navigate to a route, I should use navigate() method which takes a String.

navController = rememberNavController()

// navigate
navController.navigate("/another_route")

However, no such method exists navigate(String) and I get compile error.

What am I missing?

like image 484
Mahdi-Malv Avatar asked Oct 30 '20 19:10

Mahdi-Malv


1 Answers

navigate(String) is not part of NavController class, but an extension function

To solve the error, "import the function route in the file":

import androidx.navigation.compose.navigate

// and then navigate
navController.navigate("/another_route")

And it'll work fine.

Unfortunately, you don't get the completion that you expect.

like image 125
Mahdi-Malv Avatar answered Nov 20 '22 21:11

Mahdi-Malv