Flutter:更改默认声音按钮

Flutter: change default sound button

我想知道有没有什么方法可以改变Flutter中默认的点击声音,比如替换它。

我有这个 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())),
                  }),  
        ],
      ),

我有函数 playSound():

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

但这并没有取代 floatingActionButton 的默认声音。它在按钮点击声音后播放。
enter image description here

我确实喜欢这种方式,它有效。你能在浏览器中启动你的程序吗? 您记得将您存储该 MP3 的文件夹添加到 pubspec.yaml 中吗?

如果仍然不能解决您的问题,您需要检查来自Logcat的错误消息。 (图1就是让你知道Logcat在哪里的例子)

请更改“enableFeedback: false”的参数。 声音将被删除。

图1

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,
      ),