Future<List<SongData>> _getMetadata () async {
Uri url = Uri.parse('https://radioactivefm.gr/live/api/getCoverJson.php');
final response = await http.get(url);
var data = jsonDecode(response.body);
print('data: $data');
return SongData.fromJson(data);
}
// I can't declare this way, showing A value of type 'SongData' can't be returned from the method '_getMetadata' because it has a return type of 'Future<List>
CodePudding user response:
Future<List<SongData>> _getMetadata () async {
Uri url = Uri.parse('https://radioactivefm.gr/live/api/getCoverJson.php');
final response = await http.get(url);
var data = jsonDecode(response.body);
print('data: $data');
return data.map((e) => SongData.fromJson(e)).toList();
}
Try this and please share the shape of the received data.
CodePudding user response:
Just add this line under
List<SongData> songs = data.map((e) =>SongData.fromJson(e)).toList();
print('data: $data');
return songs;