Search code examples
flutterdartsnackbar

How to set splash color from SnackBarAction in flutter?


I'm trying to use a snackbar and i would like to change ripple effect in action button..

enter image description here but i couldnt find a property splashColor or something like that. I really like to change the blue splash color to pink. Is it possible ?

Follow code bellow:

var snackBar = SnackBar(

              content: const Text("Task removed!"),
              duration: const Duration(seconds: 3),
              action: SnackBarAction(
                  textColor: Colors.purple,
                  label: "Desfazer",
                  onPressed: (() {
                    setState(() {
                      _taskList.insert(index, _lastItemRemoved);
                    });
                    _saveFile();
                  })));
          ScaffoldMessenger.of(context).showSnackBar(snackBar);

Solution

  • Try the following code:

    var snackBar = SnackBar(
      padding: const EdgeInsets.only(top: 14.0, bottom: 14.0),
      content: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          const Text("Task removed!"),
          Transform(
            transform: Matrix4.translationValues(45.0, 0.0, 0.0),
            child: ElevatedButton(style: ElevatedButton.styleFrom(foregroundColor: Colors.pink[200], backgroundColor: Colors.indigo[900]), onPressed: () {}, child: const Text("Desfazer", style: TextStyle(color: Colors.purple))),
          ),
        ],
      ),
      duration: const Duration(seconds: 3),
    );
    
    ScaffoldMessenger.of(context).showSnackBar(snackBar);