I want to hide the navigationIcon but when I pass null
or Unit
the icon space remains visible, as can be seen in the image below.
@Composable
fun DefaultScaffold(
title: String? = null,
icon: ImageVector? = null,
content: @Composable() () -> Unit
) {
Scaffold(
topBar = {
TopAppBar(
title = {
if (title != null) {
Text(text = "My Title")
}
},
navigationIcon = {
if (icon != null) {
IconButton(
onClick = {}
) {
Icon(imageVector = Icons.Filled.Close, contentDescription = null)
}
} else Unit
}
)
}
) {
content()
}
}
Remove the parentheses that surround your conditional statement, then return
null
instead ofUnit
when you don't want to show the icon space.So, it will become