How can I update a value of a map entry in an array in firebase?

1,598 views
Skip to first unread message

Tililweet

unread,
Jul 7, 2020, 12:13:43 PM7/7/20
to Flutter Development (flutter-dev)
Hi all, so I want to update the map entry of the circled element to another number:

exmaple10.png

This is what I got so far:
var val = [];
   val.add(groupUID);
   var userInviteUID;
   await users
       .document(uid)
       .get()
       .then((value) => userInviteUID = value.data['inviteUID']);
   await invites.document(userInviteUID).updateData(
       {'invites': FieldValue.arrayUnion(val: 2 )});

So the last 2 lines of the snippet is what I need help on...I thought this would work but it complains about missing arguments(Also not sure why val needs to be a list so I just changed it.). I'd appreciate any help on this, thanks!

Souvik Dutta

unread,
Jul 7, 2020, 12:16:14 PM7/7/20
to Tililweet, Flutter Development (flutter-dev)
Why not use a map instead an array? 

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/7cd96302-8fab-429b-aa3e-c380ae1eee39o%40googlegroups.com.

Tililweet

unread,
Jul 7, 2020, 12:21:28 PM7/7/20
to Flutter Development (flutter-dev)
What do you mean? There would be multiple invites so i decided to use an array


On Tuesday, July 7, 2020 at 12:16:14 PM UTC-4, Souvik Dutta wrote:
Why not use a map instead an array? 

On Tue, Jul 7, 2020, 9:43 PM Tililweet <fordhig...@gmail.com> wrote:
Hi all, so I want to update the map entry of the circled element to another number:

exmaple10.png

This is what I got so far:
var val = [];
   val.add(groupUID);
   var userInviteUID;
   await users
       .document(uid)
       .get()
       .then((value) => userInviteUID = value.data['inviteUID']);
   await invites.document(userInviteUID).updateData(
       {'invites': FieldValue.arrayUnion(val: 2 )});

So the last 2 lines of the snippet is what I need help on...I thought this would work but it complains about missing arguments(Also not sure why val needs to be a list so I just changed it.). I'd appreciate any help on this, thanks!

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.

Souvik Dutta

unread,
Jul 7, 2020, 12:24:18 PM7/7/20
to Tililweet, Flutter Development (flutter-dev)
Oh okay. Can you share the entire error message?

To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/cc7225ee-3489-48ed-9e47-801bff833540o%40googlegroups.com.

Tililweet

unread,
Jul 7, 2020, 12:29:51 PM7/7/20
to Flutter Development (flutter-dev)
1 positional argument(s) expected, but 0 found.
Try adding the missing arguments.
dartnot_enough_positional_arguments
The named parameter 'val' isn't defined.
Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'val'.
dartundefined_named_parameter
 think its syntax thing, i just cant figure it out..

Souvik Dutta

unread,
Jul 7, 2020, 12:50:32 PM7/7/20
to Tililweet, Flutter Development (flutter-dev)
You can try to check the class definition and figure out what is needed. 

To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/551b9555-b634-4a98-8a4d-48a51b523921o%40googlegroups.com.

Tililweet

unread,
Jul 7, 2020, 1:19:59 PM7/7/20
to Flutter Development (flutter-dev)
So i tried this.
var val = [];
   val.add({'$groupUID': status});
   var userInviteUID;
   await users
       .document(uid)
       .get()
       .then((value) => userInviteUID = value.data['inviteUID']);
   await invites
       .document(userInviteUID)
       .updateData({'invites': FieldValue.arrayUnion(val)});
 and got this:

example10.png


Not really what I wanted...if it existed shouldn't it have over written? Also do you know why there's () around the text?

Souvik Dutta

unread,
Jul 7, 2020, 10:11:52 PM7/7/20
to Tililweet, Flutter Development (flutter-dev)
Val is a list. So you might have to use val.elementAt(0) or val[0] in the last line.

Souvik flutter dev

To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/6dfd8b37-bc3e-4b77-8d57-2398fd80b8bao%40googlegroups.com.

Souvik Dutta

unread,
Jul 7, 2020, 10:12:39 PM7/7/20
to Tililweet, Flutter Development (flutter-dev)
You might also want to check what is groupId

Souvik flutter dev

On Tue, Jul 7, 2020, 10:50 PM Tililweet <fordhig...@gmail.com> wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/6dfd8b37-bc3e-4b77-8d57-2398fd80b8bao%40googlegroups.com.

Ken Corey

unread,
Jul 10, 2020, 4:07:42 AM7/10/20
to Flutter Development (flutter-dev)
Did you check the F1 help for arrayUnion?

Returns a special value that tells the server to union the given elements with any array value that already exists on the server.
Each specified element that doesn't already exist in the array will be added to the end.
So the items from the val list are being appended on the array already existing on the server.

Why do you need to use arrayUnion?

-Ken
Reply all
Reply to author
Forward
0 new messages