Skip to content

Instantly share code, notes, and snippets.

@hieuwu
Created August 1, 2023 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hieuwu/f39deaea525e04b25a969eaf0d1af41d to your computer and use it in GitHub Desktop.
Save hieuwu/f39deaea525e04b25a969eaf0d1af41d to your computer and use it in GitHub Desktop.
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AddProductScreen(
modifier: Modifier = Modifier,
navController: NavController,
viewModel: AddProductViewModel = hiltViewModel(),
) {
Scaffold(
topBar = {
TopAppBar(
navigationIcon = {
IconButton(onClick = {
navController.navigateUp()
}) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = null,
tint = MaterialTheme.colorScheme.onPrimary
)
}
},
backgroundColor = MaterialTheme.colorScheme.primary,
title = {
Text(
text = stringResource(R.string.add_product_text_screen_title),
color = MaterialTheme.colorScheme.onPrimary,
)
},
)
}
) { padding ->
val navigateAddProductSuccess =
viewModel.navigateAddProductSuccess.collectAsState(initial = null).value
val isLoading =
viewModel.isLoading.collectAsState(initial = null).value
if (isLoading == true) {
LoadingScreen(message = "Adding Product",
onCancelSelected = {
navController.navigateUp()
})
} else {
SuccessScreen(
message = "Product added",
onMoreAction = {
viewModel.onAddMoreProductSelected()
},
onNavigateBack = {
navController.navigateUp()
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment