Snackbar duration and height

Mee picture Mee · Sep 24, 2018 · Viewed 13.2k times · Source

I'm trying to show a snackbar.
After I click on a gesture detector, this snack has two buttons.
The problem is that the snackbar appears for seconds and then disappears.

So I have two questions:

  1. How to stop the snackbar from disappearing until the user takes an action and clicks on a button?
  2. Also, the snackbar has a height of the whole screen.
    How can I make it have a specific height in the bottom of the screen?

Answer

Günter Zöchbauer picture Günter Zöchbauer · Sep 24, 2018

You can use a long duration

HomeScreen.scaffoldKey.currentState.showSnackBar(
    SnackBar(duration: const Duration(minutes: 5), content: Text(message)));

See also https://material.io/design/components/snackbars.html#behavior

Appearing and disappearing

Snackbars appear without warning, and don't require user interaction. They automatically disappear from the screen after a minimum of four seconds, and a maximum of ten seconds.