【问题标题】:Add SystemSounds to PageView in Flutter在 Flutter 中将 SystemSounds 添加到 PageView
【发布时间】:2026-01-28 23:25:03
【问题描述】:

我希望在 PageView 中的每个页面更改都播放声音。我已经导入了 services.dart 包。 PageView 中有一个 onPageChanged 属性,但我不知道如何使用它来实现这一点。还是我使用 GestureDetector?还是别的什么?

谢谢!

【问题讨论】:

    标签: flutter flutter-animation


    【解决方案1】:

    据我所知,截至目前(2019 年 2 月),Flutter 不支持音频播放。

    使用像pub.dartlang:audioplayers 这样的插件来播放音频。

    可以通过简单地在改变页面的动作上调用函数或简单地在状态中放置触发器来完成。

    【讨论】:

    • 我认为你是对的。 gitHub github.com/rxlabz/audioplayer/issues/35 上有一个线程讨论 Flutter 中没有通知声音。我可以点击一下:onHorizo​​ntalDragStart: (DragStartDetails details) {SystemSound.play(SystemSoundType.click);