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:
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.
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.
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')), ), ), );
setTextSize(30); //increase max lines of text in snackbar. default is 2. textView. setMaxLines(10); // NOTE new View TextView textAction = (TextView) sbView.
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.
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.
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.
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), )
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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With