在我的 flutter 應用程式中,我想通過音頻播放突出顯示每個串列項中的文本。音頻結束后,下一個串列項應突出顯示。但是發生的事情是我無法僅突出顯示特定索引。目前,當播放串列開始時,在每個備用音頻上,所有串列項都會更改 bgcolor。那么如何指定要突出顯示的索引呢?例如,在 7 個音頻的播放串列中,第一個專案應在播放第一個音頻時突出顯示。請幫忙!
text: TextSpan(
text: arabic ,
style: TextStyle(
color: getTextColor(index),
backgroundColor: ishighlight ? Colors.blue:Colors.white,
fontSize: 24.0,
fontWeight: FontWeight.w200,
fontFamily: 'uthmanitext', ),
void playAudioNetwork() async{
Playlist playlist;
List<Audio> _audios = [];
for (int i =1;i<=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(() {
ishighlight= !ishighlight;
});
});
audioPlayer.open(
playlist,
autoStart: true,
showNotification: true,
);
}
uj5u.com熱心網友回復:
您定義了一個布林值來指示名為 ishighlight 的高亮狀態,當其中一個專案正在播放時,您更改 ishighlight 值,然后在此行中通過 ishighlight 決定:
backgroundColor: ishighlight ? Colors.blue:Colors.white,
所以所有專案都將被高亮顯示。您應該有一個名為 highlightIndex 的整數而不是布林值,然后像這樣更改您的代碼:
text: TextSpan(
text: arabic ,
style: TextStyle(
color: getTextColor(index),
backgroundColor: highlightedIndex == index ? Colors.blue:Colors.white,
fontSize: 24.0,
fontWeight: FontWeight.w200,
fontFamily: 'uthmanitext', ),
void playAudioNetwork(int index) async{
Playlist playlist;
List<Audio> _audios = [];
for (int i =1;i<=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,
);
}
您應該將串列的專案索引傳遞給 playAudioNetwork 方法
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/367169.html
