Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Snackbar duration and height

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?
like image 619
Mee Avatar asked Sep 24 '18 16:09

Mee


People also ask

How do I set duration on SnackBar?

The duration should be LENGTH_SHORT, LENGTH_LONG or LENGTH_INDEFINITE. When LENGTH_INDEFINITE is used, the snackbar will be displayed indefinite time and can be dismissed with swipe off. And you can set the duration of your snackbar by setDuration(int) method.

How do you set the SnackBar duration in flutter?

You can change the duration which a SnackBar is displayed by assigning a required duration to the backgroundColor property of SnackBar, as a Duration object. Following is a quick code snippet of SnackBar with deep orange background color.

How do you set the SnackBar height in flutter?

When you pass a container with height 200 it will set the snack bar's height 200. scaffoldKey. currentState. showSnackBar( SnackBar( content: Container( height: 200, child: Center(child: Text('Hi')), ), ), );

How do I increase the size of my SnackBar?

setTextSize(30); //increase max lines of text in snackbar. default is 2. textView. setMaxLines(10); // NOTE new View TextView textAction = (TextView) sbView.

What are the options for snackbar length duration?

The options for duration are Snackbar.LENGTH_SHORT, LENGTH_LONG and LENGTH_INDEFINITE. LENGTH_INDEFINITE is now included as of Android Support library version 22.2.1. Originally, SHORT and LONG were the only values, as this was meant to be a transient message to the user.

Can you set the height and width of a snackbar?

First a statement or two! You can set the height and width of a Snackbar but it is messy and time consuming period. One realization about a Snackbar widget is most tutorials do not talk about styling.

Can snackbars be persistent or stacked?

They should not be persistent or be stacked, as they are above other elements on screen. On Android, when an unrelated dialog or popup occurs while the snackbar is up, the snackbar timeout will reset upon the window focus being regained. This is to ensure that the user will be able to read the snackbar for the full intended duration.

How to change the duration of Snackbar's background color?

You can change the duration which a SnackBar is displayed by assigning a required duration to the backgroundColorproperty of SnackBar, as a Duration object. Following is a quick code snippet of SnackBar with deep orange background color. SnackBar( content: Text('This is a SnackBar.'), duration: Duration(seconds: 2, milliseconds: 500), )


2 Answers

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.

like image 173
Günter Zöchbauer Avatar answered Oct 16 '22 09:10

Günter Zöchbauer


I wrote a little something about how i solved this https://dev.to/eyewritecode/persisting-flutter-snackbar-until-user-interacts-with-it-2583

You basically have to set a long duration

duration: Duration(days: 1)

And call the following whenever you want to hide it.

Scaffold.of(context).hideCurrentSnackBar();
like image 22
Eyewritecode Avatar answered Oct 16 '22 10:10

Eyewritecode