https://kotlinlang.org logo
#compose
Title
# compose
s

subashz

11/03/2020, 6:11 PM
Got this weird error ??
Copy code
FloatingActionButton(
        onClick = {
            LaunchedTask {
                scaffoldState.snackbarHostState.showSnackbar(
                    "Hello World..",
                    "",
                    SnackbarDuration.Short
                )
            }
        }
@Composable invocations can only happen from the context of a @Composable function
But it works if I extract LaunchedTask to root of @Composable fuctions ?? Isn't FloatingActionButton also inside the composable function blocks ??
a

Afzal Najam

11/03/2020, 6:15 PM
The onClick isn't a composable
You could set a state and in the snackbar composable, show or hide based on that state, though
s

subashz

11/03/2020, 6:15 PM
yep, ur right.. Thanks.