简体   繁体   English

单个按钮中的播放暂停图标(音频播放器颤动)

[英]Play Pause icon in single button (Audioplayer flutter)

'''

i Just want create a button that controlls the audio play pause state please some body let me know how can i do that?我只想创建一个控制音频播放暂停状态的按钮,请一些人告诉我我该怎么做?

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("ListView.builder")),
      body: ListView.builder(
        itemCount: radioDetails.length,
        itemBuilder: (BuildContext context, int index) {
          return Card(
            clipBehavior: Clip.antiAlias,
            child: ListTile(
                title: Text(radioDetails[index].name),
                trailing: IconButton(
                  icon: null as Widget,
                  onPressed: null,
                )),
          );
        },
      ),
    );
  }
}

Create a bool创建一个布尔值

bool isPlaying = false;

In place of icon check this variable代替图标检查此变量

icon: (isPlaying)? Icons.stop: Icons.play,
onTap: (){
  setState((){
    isPlaying = !isPlaying;
    //Manage playerto stop or play audio here
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用单个图标按钮在 flutter 中播放和暂停音频 - How to use single Icon button to play and pause audio in flutter AudioPlayer 暂停方法不起作用 - Flutter - AudioPlayer pause method not working - Flutter 播放和暂停 Flutter 动画 - Play & pause a Flutter animation 在 Flutter 中创建播放暂停按钮的正确方法是什么 - What is the Correct method to create Play Pause Button in Flutter 如何在颤动的视频播放中显示播放和暂停按钮? - how can display play and pause button in videoplay on flutter? Flutter:有没有办法处理耳机播放/暂停媒体按钮? - Flutter: Is there a way to handle headphone play/pause media button? 无法使用 AudioPlayer package - ZC047B1077763AFECC8164 在 iOS 上播放来自 URL 的音频 - Unable to play audio from URL on iOS using AudioPlayer package - Flutter 如何在 Flutter 中使用音频播放器插件播放本地 mp3 文件 - How to play local mp3 file with audioplayer plugin in Flutter Flutter iOS 存储音频不播放音频播放器、颤音和仅音频 - Flutter iOS Storage audio doesnt Play with audioplayer, fluttersound and just audio flutter:: 有没有办法使用音频播放器 package 只播放一个音频文件? - flutter:: Is there a way to play only one audio file using the audioplayer package?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM