-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
How can i make List audioList [
....
]
with dynamic data from json? I've already realized it in 'for' but it doesn't work correct
final AssetsAudioPlayer audioPlayer = AssetsAudioPlayer();
final SwiperController swiperController = SwiperController();
double screenWidth = 0;
double screenHeight = 0;
var currentSongs;
Color highlightColor = Colors.white;
var audio;
var title;
var subtitle;
var image;
late List allSongs = [];
List<Audio> audioList = [];
@override
void dispose() {
audioPlayer.stop();
super.dispose();
}
@override
void initState() {
setupPlaylist();
super.initState();
}
void setupPlaylist() async {
currentSongs = widget.data['index'];
allSongs = widget.data['songs'];
for (var i = 0; i < allSongs.length; i++) {
audio = allSongs[i]['fields']['audio'][0]['url'].toString();
title = allSongs[i]['fields']['name'].toString();
subtitle = allSongs[i]['fields']['type'].toString();
image = allSongs[i]['fields']['cover'][0]['url'].toString();
audioList.add(
Audio.network(
audio, metas: Metas(
title: title,
artist: subtitle,
image: MetasImage.file(image)
)
),
);
}
audioPlayer.open(
Playlist(audios: audioList, startIndex: currentSongs),
autoStart: false,
showNotification: true,
loopMode: LoopMode.none
);
}
Help me, please.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels