Vinasirajan Vilakshan
Vinasirajan Vilakshan

Reputation: 327

How can I store a data contains "." inside firestore inside a map field in flutter?

When I add an email address to the map field vote data, Due to "." inside email address, it is creating a sub map with email.

How can I overcome this??

//Code Below

await FirebaseFirestore.instance
        .collection('polls')
        .doc(pollId)
        .update({"voteData.$currentUser": option});

Here currentUser = "[email protected]"

enter image description here

I tried this code too

await FirebaseFirestore.instance
        .collection('polls')
        .doc(pollId)
        .update({"voteData.${currentUser.replaceAll(".", "\\.")}": option});

but output is

enter image description here

Upvotes: 0

Views: 31

Answers (1)

Nirmal Code
Nirmal Code

Reputation: 4058

You have to escape the .

Try this,

await FirebaseFirestore.instance
        .collection('polls')
        .doc(pollId)
        .update({"voteData.${currentUser.replaceAll(".","\\.")}": option});

Upvotes: 1

Related Questions