Created
June 2, 2022 17:43
-
-
Save Debdutta-Panda/b9ad204383502b5287f3800307e12a78 to your computer and use it in GitHub Desktop.
Use navigateUp to go back
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun PageB(navController: NavHostController) { | |
Column( | |
modifier = Modifier.fillMaxSize(), | |
horizontalAlignment = Alignment.CenterHorizontally, | |
verticalArrangement = Arrangement.Center | |
){ | |
Text( | |
"Page B", | |
color = Color(0xfff44336), | |
fontSize = 24.sp, | |
fontWeight = FontWeight.Bold | |
) | |
Button( | |
onClick = { | |
//navController.navigate("page_a")//not good to go back | |
navController.navigateUp()//use navigateUp instead | |
}, | |
colors = ButtonDefaults.buttonColors( | |
backgroundColor = Color(0xfff44336), | |
contentColor = Color.White | |
) | |
) { | |
Text("Go back to Page A") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment