When using a scaffold with a conditional FAB, I fi...
# compose
s
When using a scaffold with a conditional FAB, I find I have to cast to compile:
Copy code
floatingActionButton = if (condition) { 
    @Composable {
        FloatingActionButton(onClick = {backStack.push(Routing.EditDrink(null))}) {
            Icon(Icons.Default.Add)
        }
    } as @Composable() () -> Unit
} else null
Or I get an "Expected type was Nothing?" error, but when casting the cast shows as a useless cast. Am I doing something stupid?
😅 2
d
What is the declaration of
floatingActionButton
?
s
Copy code
floatingActionButton: @Composable (() -> Unit)? = null,
d
Shouldn't that be
floatingActionButton: (@Composable () -> Unit)? = null
?
m
Hello! I don't think parenthesis matter, I will try it, thanks. In the mean time, do you really need to return null? you can do
Copy code
floatingActionButton = {
    if (condition) { 
        FloatingActionButton(onClick = {backStack.push(Routing.EditDrink(null))}) {
            Icon(Icons.Default.Add)
        }
}
and it should work just fine
👍 1
s
That worked perfectly, thanks!
d
Do the parenthesis not matter?
s
I don't think so - they're just there for grouping for the nullibility. Other than that it's just
@Composable (() -> Unit)
vs
@Composable () -> Unit
, and in both cases the
@Composable
applies to the whole function type