3
  • I have displayed a snackbar with Floating Action Button but Snackbar shows up above the FAB and it want it show it below the FAB.
  • As per the guidelines snackbar must be above FAB but in the app as per the funtionality I have to display it below.
  • I also tried with Modifier.offset() but Snackbar is sticked with FAB offset.
  • There is a simliar question here here but that doesn't answer the question.

Here is some snippet of my code:

@Composable
fun snackBarDemo() {
    val coroutineScope = rememberCoroutineScope()
    val snackBarHostState = remember { SnackbarHostState() }
    val drawerState = rememberDrawerState(DrawerValue.Closed)
    val scaffoldState = rememberScaffoldState(drawerState, snackbarHostState)

    Scaffold(
        scaffoldState = scaffoldState,
        drawerContent = {},
        floatingActionButton = {
            FloatingActionButton(
                onClick = {
                    coroutineScope.launch {
                        scaffoldState.snackbarHostState.showSnackbar("Hello this is my snackbar")
                    }
                }) {
                Icon(
                    painter = painterResource(id = R.drawable.icon),
                    contentDescription = null,
                    modifier = Modifier.padding(start = 5.dp, top = 2.dp)
                )
            }
        }
    ) {}
}
Sumit Shukla
  • 4,116
  • 5
  • 38
  • 57

0 Answers0