flutterdartsnackbar

Flutter: How to reset SnackBar timer?


On a button tap I want to show a SnackBar for 5s. If the user taps the button repeatedly in a short amount of time, multiple SnackBars are queued. Instead of showing e.g. 3 SnackBars for 5s each, I want to reset the timer of the currently active SnackBar each time the button is tapped. So if the user taps the button 3 times within 1s, I want to show one SnackBar for a total of 6s, instead of showing 3 SnackBars for a total of 15s.

I do not know how to manipulate the timer of a currently active SnackBar. The ScaffoldMessenger only provides methods such as removeCurrentSnackBar to dismiss the SnackBar and not to manipulate the SnackBar in other ways, as far as I understood.

How can I achieve the reset of the Snackbar timer?

Thanks in advance!


Solution

  • A simple work around. Whenever the user clicks the button clear the snackbar and launch a new one. You can use removeCurrentSnackBar to remove.