Reputation: 105
From an api i get a list of albums with cover art ids, I take that list and put the cover art ids into a function to get the URLs for the cover art from the api. My problem is I'm trying to turn the URLs into a list but i get the error: "type string is not a subtype of List". If i don't try and turn it into a list the URLs are fine but I can't access individual urls so i can display it in a grid list. When i try and index it, it comes back with individual letters rather than the individual URLs.
class _RecentlyAddedAlbumsState extends State<RecentlyAddedAlbums> {
Future<List<Album>> albums;
List<String> coverARTLIST;
@override
Widget build(BuildContext context) {
return Scaffold(
/* backgroundColor: Colors.black, */
body: Container(
child: FutureBuilder(
future: fetchRecentlyAddedAlbums(),
builder: (context, AsyncSnapshot<List<Album>> data) {
switch (data.connectionState) {
case ConnectionState.none:
return Text(
"none",
style: TextStyle(color: Colors.black),
);
case ConnectionState.waiting:
return Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.black),
));
case ConnectionState.active:
return Text('');
case ConnectionState.done:
if (data.hasData) {
List<Album> albums = data.data;
return ListView.builder(
itemCount: albums.length,
itemBuilder: (context, index) {
return FutureBuilder(
future: recentAlbumArt(albums[index].coverArt),
builder: (context, AsyncSnapshot cover) {
switch (cover.connectionState) {
case ConnectionState.none:
return Text(
"none",
style: TextStyle(color: Colors.black),
);
case ConnectionState.waiting:
return Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Colors.black),
));
case ConnectionState.active:
return Text('');
case ConnectionState.done:
if (cover.hasData) {
List<String> coverARTLIST = cover.data;
print(coverARTLIST);
return GridView.count(
scrollDirection: Axis.vertical,
crossAxisCount: 2,
shrinkWrap: true,
padding: const EdgeInsets.all(5),
crossAxisSpacing: 10,
children: <Widget>[Text("TEST")],
);
}
}
});
},
);
}
}
}),
),
);
}
}
coverart function:
Future recentAlbumArt(String coverArtID) async {
try {
var salt = randomToken(6);
var token = makeToken("$password", "$salt");
var uRL =
"$server/rest/getCoverArt/?u=$username&t=$token&s=$salt&v=$tapeOutVerison&c=$client$format&id=$coverArtID";
return uRL.toString();
} catch (e) {
print(e);
}
}
Upvotes: 0
Views: 105
Reputation: 3130
List<String> coverARTLIST = cover.data;
This line is the reason for you error. You are trying to assign string to list of string.
Try this instead
List<String> coverARTLIST=[];
coverARTLIST.add(cover.data);
print(coverARTLIST[0]);
Upvotes: 1