suragch / flutter_audio_service_demo

Companion project for Flutter audio_service tutorial
https://suragch.medium.com/background-audio-in-flutter-with-audio-service-and-just-audio-3cce17b4a7d?sk=0837a1b1773e27a4f879ff3072e90305
MIT License
57 stars 28 forks source link

No Click items in listview #9

Open nayyelin365 opened 2 years ago

nayyelin365 commented 2 years ago

I can not click items in listview

suragch commented 2 years ago

Yes, this tutorial doesn't cover that. However, you can add that functionality yourself by implementing _audioHandler.skipToQueueItem() when the user taps a list view item.

zionnite commented 2 years ago

was able to do this @MgNayYELinUCS , this is what you need to do that's if you still need the code on how to do it.

class Playlist extends StatelessWidget {
  const Playlist({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final pageManager = getIt<PageManager>();
    return ValueListenableBuilder<List<String>>(
      valueListenable: pageManager.playlistNotifier,
      builder: (context, playlistTitles, _) {
        return ListView.builder(
          scrollDirection: Axis.vertical,
          shrinkWrap: true,
          physics: ClampingScrollPhysics(),
          itemCount: playlistTitles.length,
          itemBuilder: (context, index) {
            return Column(
              children: [
                InkWell(
                  onTap: () {
                    var current_id = pageManager.getCurrentSongId();
                    var current_playlist = pageManager.getCurrentPlaylist();
                    pageManager.skipToQueueItem(index, playlistTitles[index]);
                    // pageManager.updateMyQueueItem(
                    //   current_playlist[int.parse(current_id)],
                    //   int.parse(current_id),
                    // );
                  },
                  child: ListTile(
                    //leading: CurrentSongImage(),
                    title: Text(
                      '${playlistTitles[index]}',
                    ),
                    //trailing: AddRemoveSongButtons(),
                  ),
                ),
                SizedBox(
                  height: 5,
                )
              ],
            );
          },
        );
      },
    );
  }
}

page_manager.dart

void skipToQueueItem(int index, String name) {
    _audioHandler.skipToQueueItem(index);
 }

audio_handler.dart

@override
  Future<void> skipToQueueItem(int index) async {
    if (index < 0 || index >= queue.value!.length) return;
    if (_player.shuffleModeEnabled) {
      index = _player.shuffleIndices![index];
    }
    _player.seek(Duration.zero, index: index);
}

That's all and everything worked for me!