Search code examples
dartflutterfloating-action-button

Floating action button: how to change the splash color and highlight color like in a RaisedButton?


I see that the splash and highlight colors that the FAB takes are connected to argument color in the MaterialApp widget. is there a way to override those colors? I found only foreground color and background colors and those are not what I want. Thanks


Solution

  • If you check the source code of FloatingActionButton the splash color is tied to the Theme of the app, so you can change the theme only for the button, like this:

    Theme(
      data: Theme.of(context).copyWith(highlightColor: Colors.yellow),
      child: FloatingActionButton(
        backgroundColor: Colors.red,
        onPressed: () {},
        child: Text("hello world"),
     ),
    )