0

My API call:

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>

2 Answers 2

1
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.

Sign up to request clarification or add additional context in comments.

1 Comment

Solved! List<SongData> songs = data.map((e) => SongData.fromJson(e)).toList(); print('data: $data'); return songs; add this
0

Just add this line under

List<SongData> songs = data.map((e) =>SongData.fromJson(e)).toList();
print('data: $data');
return songs;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.