Is there a way to turn off the sound response when pressing a button for the entire flutter application?

118 views Asked by At

I'm trying to disable all sounds when clicking on any of the possible buttons (ElevatedButton, TextButton, IconButton etc.). But no matter how much I try, I can't do it by using the app theme or any other way.

I've already tried setting enableFeedback = false for all button types, but it absolutely doesn't work for IconButton.

So, I can't do it for whole app and the only solution is to set enableFeedback = false for each button, but isn't there any easier way to do this?

3

There are 3 answers

0
veesilenavi On BEST ANSWER

Well, after a little research, I discovered that you can set the value enableFeedback = false/true in the theme for any buttons that inherit ButtonStyleButton, but you cannot set this value for IconButton, since it inherits StatelessWidget and does not request data from the application theme.

In case if you need to set enableFeedback value for your IconButton widgets, you need to do it separately for each IconButton (doesn't matter whether you do this using other widgets or whether you actually set each value manually).

I think the issue can be closed, but it really looks like bug.

1
Ozan Taskiran On

Set the enableFeedback in your theme, not for every button.

For example:

elevatedButtonTheme: const ElevatedButtonThemeData(
        style: ButtonStyle(
      enableFeedback: false,
    )),

should disable the sound for all ElevatedButtons. If you have any other type of buttons, you will need to apply a theme again for this button (OutlinedButton for example).

1
Abel On

You can wrap up your button in a GestureDetector and implement the code in the onTap there and leave the button onPressed empty. Maybe if this works for you, you can create a new Widget that wraps the following code that you can utilise more than once.

    GestureDetector(
  onTap: () {
    // Your button's functionality
  },
  child: OutlinedButton(
    onPressed: () {}, // Leave this empty
    child: Text('Button Text'),
  ),
)