Home > Back-end >  Instance of 'Future<Map<dynamic, dynamic>>'
Instance of 'Future<Map<dynamic, dynamic>>'

Time:12-17

the problem that am trying to get value from "getThatWishlist" but it returns instead "Instance of 'Future<Map<dynamic, dynamic>>'"

  Future<Map<dynamic, dynamic>> getThatWishlist(String? wishlistname) async {
    FirebaseFirestore db = FirebaseFirestore.instance;

    return await db
        .collection('wishlists')
        .doc(currentUserId)
        .get()
        .then((snapshot) async {
      if (snapshot.data() == null) {
        return {};
      } else {
        Map<dynamic, dynamic> wishlistData = {};
        wishlistData =
            await snapshot.data()!['userWishlists'][wishlistname]['UserItems'];
        return wishlistData; 
      }
    });
  }
void createWishlistForSharedUser(String? ShareUid) async {
    FirebaseFirestore db = FirebaseFirestore.instance;
    await db.collection('wishlists').doc(ShareUid).set({
      'sharedWishlistsWithUser': {
        wishlistName: {
          'UserItems': {getThatWishlist(wishlistName) //the problem is here 
}
          
        },
        'wishlist owner email': currentUserEmail,
      },
    }, SetOptions(merge: true));
  }

How to fix that problem ?

CodePudding user response:

You should do something like this instead:

void createWishlistForSharedUser(String? ShareUid) async {
    /// add this line
    var userItems = await getThatWishlist(wishlistName);

    FirebaseFirestore db = FirebaseFirestore.instance;
    await db.collection('wishlists').doc(ShareUid).set({
      'sharedWishlistsWithUser': {
        wishlistName: {
          /// update line below
          'UserItems': {userItems}          
        },
        'wishlist owner email': currentUserEmail,
      },
    }, SetOptions(merge: true));
  }
  • Related