Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cloud_firestore] Can't add to list with transaction. Please Help. #23

Closed
mike-gallego opened this issue Aug 24, 2019 · 5 comments
Closed

Comments

@mike-gallego
Copy link

I tried many different ways but I cannot add to a placeholder list that I have. I followed exactly how the documentation handled it, too.

await Firestore.instance.collection('users').document(user.uid).setData({ 'ban_list': [], });

await tx.update(postRef, <String, dynamic>{ 'ban_list': postSnapshot.data['ban_list'] .add(listOfDocs[index]['id']) });

Annotation 2019-08-23 220202
Annotation 2019-08-23 220245

@mike-gallego mike-gallego changed the title Can't add to list with transaction. Can't add to list with transaction. Please Help. Aug 24, 2019
@mike-gallego
Copy link
Author

Temporary workaround was to make the placeholder a map instead and in the transaction add the map to the existing map (placeholder).

await Firestore.instance.collection('users').document(user.uid).setData({ 'ban_list': new Map(), });

await tx.update(postRef, <String, dynamic>{ 'ban_list': postSnapshot.data['ban_list']..addAll({listOfDocs[index]['id'] : listOfDocs[index]['id']}) });

@collinjackson collinjackson changed the title Can't add to list with transaction. Please Help. [cloud_firestore] Can't add to list with transaction. Please Help. Aug 25, 2019
@collinjackson
Copy link
Contributor

I'm confused by your original code snippet, since it looks like you're using the return value of .add (void) as a value in a Map. I'm not sure if the issue is in the plugin, the native SDK, or your code, but if you want to write an integration test for it I'd be happy to investigate further.

@NoamDev
Copy link
Contributor

NoamDev commented Aug 26, 2019

try this:
await tx.update(postRef, <String, dynamic>{ 'ban_list': postSnapshot.data['ban_list'].toList() .add(listOfDocs[index]['id']) });
calling toList will make a new growable list from the fixed-length list, which will allow you to add new elements to it.

@NoamDev
Copy link
Contributor

NoamDev commented Aug 30, 2019

@mikeyyg96 did it work for you?

@iapicca
Copy link

iapicca commented Oct 24, 2019

Hi @mikeyyg96
I'm closing this issue for inactivity.
If you disagree please write in the comments
and I will reopen it.
Thank you

@iapicca iapicca closed this as completed Oct 24, 2019
@iapicca iapicca removed the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Oct 24, 2019
@firebase firebase locked and limited conversation to collaborators Aug 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants