#flutter #listview #indexing #audio-player
Вопрос:
в моем приложении flutter я хочу изменить цвет фона текста в элементах списка при воспроизведении звука. каждый элемент списка содержит аудио. Проблема в том, что я пытаюсь передать индекс элемента списка за пределы listview.builder в метод воспроизведения звука, но при воспроизведении списка воспроизведения выделяется только индекс № 5 при запуске аудио 2. Я должен определить, когда заканчивается звук, а затем соответствующим образом выделить следующий стих и автоматически воспроизвести следующий стих. Вот код;
int highlightedIndex; int itemIndex=0; ListView.builder( controller: hiding.controller, itemCount: surahcountlist.length, itemBuilder: (context, index) { itemIndex= index; return GestureDetector( child: Card( color: getColor(index, surahcountlist[index].surah_no, surahcountlist[index].ayah_no),// light_mode ? Colors.white : Color(0xFF6D6D6D), child: Column( textDirection: TextDirection.rtl, mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.stretch, children: lt;Widgetgt;[ showBSMLSV(index), Wrap( direction: Axis.horizontal, alignment: WrapAlignment.start, runAlignment: WrapAlignment.center, textDirection: TextDirection.rtl, spacing: 2.0, // gap between adjacent chips runSpacing: 5.0, children: makeSurahListview( surahcountlist[index].surah_no, surahcountlist[index].ayah_no, surahcountlist[index].count, index)), ]))); } ), void playAudioNetwork(int index) async{ Playlist playlist; Listlt;Audiogt; _audios = []; for (int i =1;ilt;=7;i ) { String Url= 'https://everyayah.com/data/Ayman_Sowaid_64kbps/00100${i}.mp3'; _audios.add(Audio.network(Url)); print(Url); } playlist = Playlist(audios: _audios); audioPlayer.playlistAudioFinished.listen((event) { setState(() { highlightedIndex = index; }); }); audioPlayer.open( playlist, autoStart: true, showNotification: true, ); }
В нижней Панели Навигации:
SizedBox( width: 45, height: 45, child: FloatingActionButton( onPressed: () { playAudioNetwork(itemIndex); }, backgroundColor: light_mode ? Color(0xFFEA80FC) : Color(0xFF6D6D6D), child: Icon( Icons.play_arrow, color: Colors.white, size: 30, ), ), ), TextSpan( text: arabic , style: TextStyle( color: getTextColor(index), backgroundColor: highlightedIndex == index ? Colors.blue:Colors.white, fontSize: 24.0, fontWeight: FontWeight.w200, fontFamily: 'uthmanitext', ),