今天閱讀「適用於 Android 開發人員的 Jetpack Compose」第三章「架構與狀態」的「Navigation 最佳做法」、「Navigation」
dependencies {
implementation "androidx.navigation:navigation-compose:{latest_version}"
}
rememberNavController()
函式即可取得NavController
val navController = rememberNavController()
route
composable(route = Overview.route) {
Overview.screen()
}
composable(route = Accounts.route) {
Accounts.screen()
}
composable(route = Bills.route) {
Bills.screen()
}
"route/{argument}"
的格式
composable (
route = "${SingleAccount.route}/{${SingleAccount.accountTypeArg}}"
) {
//...
}
arguments
composable (
arguments = listOf(navArgument(SingleAccount.accountTypeArg) {
type = NavType.StringType
}
)
) {
//...
}
dependencies {
androidTestImplementation "androidx.navigation:navigation-testing:$rootProject.composeNavigationVersion"
}