Home > Enterprise >  Flutter: change default sound button
Flutter: change default sound button

Time:03-24

I would like to know if there is any way to change the default click sound in Flutter, like replace it.

I have this floatingActionButton:

floatingActionButton: SpeedDial(
        animatedIcon: AnimatedIcons.menu_close,
        backgroundColor: Colors.purple,
        children: [
          SpeedDialChild(
              child: const Icon(Icons.person),
              label: "Perfil",
              onTap: () => {
                    playSound(),
                    Navigator.push(context,
                        MaterialPageRoute(builder: (context) => Profile())),
                  }),  
        ],
      ),

And them i Have the function playSound():

void playSound() {
    final player = AudioCache();
    player.play("audio/buttonSound.mp3", mode: PlayerMode.LOW_LATENCY);
  }

But this does not replace the default sound of the floatingActionButton. It plays after the button click sound.
enter image description here

flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  assets:
    - images/
    - audios/
class _ItemDetailsScrrentState extends State<ItemDetailsScrrent> {
  AudioCache audioCache = AudioCache();
  // void playSound() {
  //   final player = AudioCache();
  //   player.play("../audios/0125.mp3");
  // }

      floatingActionButton: FloatingActionButton.extended(
        enableFeedback: false,
        onPressed: () {
          // playSound();
          audioCache.play(
            '../audios/0125.mp3',
            mode: PlayerMode.LOW_LATENCY,
          );
          print('ttt');
          // Add your onPressed code here!
        },
        label: const Text('Approve'),
        icon: const Icon(Icons.thumb_up),
        backgroundColor: Colors.pink,
      ),

enter image description here

  • Related