简体   繁体   中英

Flutter: How can I store another list in a value of a list - error "type 'UserForPosts' is not a subtype of type 'Iterable<dynamic>of 'iterable'

everyone. I have the following problem: I have a list and I want to save another list in a value of this list. Unfortunately I get the error mentioned above.

Here is my Code (sorry beginner):

var userInformationSnap = await FirebaseFirestore.instance
      .collection('users')
      .where('__name__', whereIn: aUserIDOnly)
      .get();

  var userInformationSnapList = userInformationSnap.docs.map((d) =>
      UsersForPosts.fromJson(d.data())).toList();

  for (var i = 0; i < eventsWithoutUserData.length; i++) {
    for (var j = 0; j < userInformationSnapList.length; j++) {
      if (eventsWithoutUserData[i].userID == userInformationSnapList[j].UserID) {
        eventsWithoutUserData[i].userInformation.addAll(userInformationSnapList[j]);
      }
    }
  }

Error - "type 'UserForPosts' is not a subtype of type 'Iterable dynamic of 'iterable'"

Does anyone have an idea where exactly the problem lies and how I can solve it? Many Thanks

Error - "type 'UserForPosts' is not a subtype of type 'Iterable dynamic of 'iterable'"

Does anyone have an idea where exactly the problem lies and how I can solve it? Many Thanks

Yes, like Anis Alibegić said try tor replace addAll . with add. like this:

      for (var i = 0; i < eventsWithoutUserData.length; i++) {
    for (var j = 0; j < userInformationSnapList.length; j++) {
      if (eventsWithoutUserData[i].userID == userInformationSnapList[j].UserID) {
        eventsWithoutUserData[i].userInformation.add(userInformationSnapList[j]);
      }
    }
  }

  return eventsWithoutUserData;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM