Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Place snackbar above soft keyboard using a scaffold

In my UI the user needs to enter an ID number, if a number is entered that doesn't exist I have a snackbar that informs the user that no such ID exists. The problem is that it's under the soft keyboard. I'm currently configuring the snackbar in a scaffold. I haven't found a way to move the position of the snackbar from the bottom of the screen within the scaffold attributes. I've gotten it to work by creating a SnackbarHost within the column of my UI. Is this the only way or can I define my snackbar placement using the scaffold?

Scaffold(
        scaffoldState = rememberScaffoldState(snackbarHostState = snackbarHostState),
        topBar = {
            TopAppBar(
                title = {
                    Text(
                        text = "Keep them honest",
                        modifier = Modifier
                            .fillMaxWidth(),
                        textAlign = TextAlign.Center,
                        fontSize = 40.sp
                    )
                }
            )},
        
        content = { padding->

I've found older references in stackoverflow that address this if you were using activities but nothing with Compose.

like image 312
JD74 Avatar asked Sep 15 '25 18:09

JD74


1 Answers

I have managed to do this by setting the insets myself https://developer.android.com/jetpack/compose/layouts/insets#compose-apis

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    WindowCompat.setDecorFitsSystemWindows(window, false)

    setContent {
        Box(Modifier.safeDrawingPadding()) {
            // the rest of the app
        }
    }
}
like image 90
Vasil Kirilov Vasilev Avatar answered Sep 17 '25 19:09

Vasil Kirilov Vasilev