Flutter snackbar dismiss on SnackBarAction onPressed


I want to dismiss SnackBar on SnackBarAction‘s onPressed method. I tried with Navigator.of(context).pop(); but SnackBar is not dismissing my screen get black instead.

Here is code:

 void showInSnackBar(String value) {
homeScaffoldKey.currentState.showSnackBar(new SnackBar(content: new Text(value),
  action: SnackBarAction(
    label: 'Dissmiss',
    textColor: Colors.yellow,
    onPressed: () {
    //  Navigator.of(context).pop();


Try using hideCurrentSnackBar method

onPressed: () {

More info here: https://docs.flutter.io/flutter/material/ScaffoldState/hideCurrentSnackBar.html

Answered By – diegoveloper

Answer Checked By – Marie Seifert (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *