Kostya Vyrodov
Kostya Vyrodov

Reputation: 7277

How to mute the sound of buttons in application?

Is there any way to mute click sound in android? I need to use my own sound effects.

Note: I don't want to use gesture detector instead of default button widgets, because it affects plenty of my screens.

Upvotes: 3

Views: 3295

Answers (3)

Sleewok
Sleewok

Reputation: 153

I wanted to do this for a TextButton widget.

To disable the sound I added the following property:

style: ButtonStyle(
            enableFeedback: false,
          ),

Upvotes: 0

Prakash Basnet
Prakash Basnet

Reputation: 121

To mute the sound of the button

ElevatedButton
(
              style: ElevatedButton.styleFrom(
                //this enable feedback helps to turn off the sound on click
                enableFeedback: false,
              ),

Upvotes: 4

Kostya Vyrodov
Kostya Vyrodov

Reputation: 7277

I didn't find any property in default Flutter buttons.

But I think, I found the source of sound. This's InkWell widget. I did the trick below and it helped me:

class SilentBtn extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.red,
      child: Material(
        child: InkWell(
          onTap: () => print('OnTap'),
          enableFeedback: false,
          child: Container(
            width: 50,
            height: 50,
            child: Center(
              child: Text(
                ':)',
                style: TextStyle(color: Colors.white, fontSize: 16),
              ),
            ),
          ),
        ),
        color: Colors.transparent,
      ),
    );
  }
}

If you set the 'enableFeedback: false' you won't here click sound. If it's true then the sound is hearable.

Upvotes: 7

Related Questions