Home > Back-end >  Play Pause icon in single button (Audioplayer flutter)
Play Pause icon in single button (Audioplayer flutter)

Time:07-17

'''

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

CodePudding user response:

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
  });
}
  • Related