Home > Software design >  Snackbar text parameter deprecated
Snackbar text parameter deprecated

Time:01-15

So i am working with an app in jetpack compose and i see this tutorial Tutorial. This tutorial builds a default snackbar within a snackbarhost and adds a text to this snackbar in the way below. Though when i try to add this parameter it tells me that it doesn't exist. Why is this is the parameter deprecated and if so what did it get exchanged with? Plus i have the question of how to clear the que in the snackbarhost quz when i click more then once i first get myh last message and then the one i should get?

Snackbar(
  modifier = Modifier.padding(16.dp),
    text = {
      Text(
        text = data.message,
        style = MaterialTheme.typography.body2,
        color = Color.White
      )
      },
            action = {
                data.actionLabel?.let { actionLabel ->
                    TextButton(
                        onClick = {
                            onDismiss()
                        }
                    ) {
             Text(
                text = actionLabel,
                style = MaterialTheme.typography.body2,
                color = Color.White
            )
         }
      }
   }
)

CodePudding user response:

I'm assume your talking about this line:

Snackbar(
  modifier = Modifier.padding(16.dp),
  text = { // <--

I found a usage example on the Compose Playground here: https://foso.github.io/Jetpack-Compose-Playground/material/snackbar/ (the page also contains a link to the reference of Snackbar)

From what I can see, they probably replaced the text arg with the content of the Snackbar, which would result in something similar to this:

Snackbar(
  modifier = ... same as before ...,
  action = ... same as before ... 
) {
   // Move the text element here
   Text(...)
}
  •  Tags:  
  • Related