0

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);
  }
}

1 Answer 1

1

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]);
Sign up to request clarification or add additional context in comments.

5 Comments

This worked! Side question, is there a way to have them in a new list but as separated objects? when i use this method them seem to be all one object but before they were all different objects?
I didn't get you
So before when its the "albums" list it has lets say 13 items when i call .length on the list. But after when i add it to the "coverARTLIST" using the method above it it says it has 1 item when i call .length on the list. So when i try and display in the grid it displays as if its only 1 big item. Does that make sense ?
@limitlessbritt declare List<String> coverARTLIST=[]; out of future builder that is inside list builder
sorry to bother you again that worked, but for some reason it doubles the list, for example the original list size is 10 but then the coverARTLIST is 20, the URLs seem to be added twice? Also when i go to print lets say coverARTLIST[0] it prints the URL multiple times

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.