0

I got the following Json data through the drawing-related library.

                            {
                              "bounds": {"width": 525.0, "height": 735.0},
                              "paths": [
                               // draw line 
                                [
                                  {"x": 470.0, "y": 98.0, "t": 1657102762880}
                                  {"x": 470.0, "y": 98.0, "t": 1657102762880}
                                ],
                                [
                                  {"x": 470.0, "y": 98.0, "t": 1657102762880}
                                ]
                              ],
                              "threshold": 0.01,
                              "smoothRatio": 0.65,
                              "velocityRange": 2.0
                            }

And I'm going to upload this data to firestore. (To upload drawing data and load it later)

However, when I upload it to Firestore, the following error is printed

Nested arrays are not supported.

Here's the code I tried

                    await FirebaseFirestore.instance
                            .collection(COL_ROOMS)
                            .doc(widget.roomKey)
                            .collection(COL_DRAW)
                            .doc()
                            .set({
                              "bounds": {"width": 525.0, "height": 735.0},
                              "paths": [
                                [
                                  {"x": 470.0, "y": 98.0, "t": 1657102762880}
                                ]
                              ],
                              "threshold": 0.01,
                              "smoothRatio": 0.65,
                              "velocityRange": 2.0
                            })
                            .then((value) => logger.d("upload"))
                            .catchError((error) => logger.e(error));

Can I know a good way to solve this problem?

3
  • 1
    What do you mean by "turning off"? Crashing? Do you have any logs? Have you initialized your app by using await Firebase.initializeApp()? Commented Jul 6, 2022 at 13:30
  • When an Android app crashes, it writes an error message and stack trace to its logcat. Please find those, and add them to your question by clicking the edit link under it. Also see stackoverflow.com/questions/23353173/… and stackoverflow.com/questions/3988788/… Commented Jul 6, 2022 at 14:08
  • I checked the error message "Nested arrays are not supported." . I'll correct the post Commented Jul 7, 2022 at 0:43

1 Answer 1

2

The problem is in the paths field.

"paths": [
   [
     {"x": 470.0, "y": 98.0, "t": 1657102762880}
   ]
 ]

You have an array of arrays, this is not supported by Firestore.

If you just want to store the data, you can try to store it as a String.

// Covert to string
final dataAsString = json.encode({
    "bounds": {"width": 525.0, "height": 735.0},
    "paths": [
      [
        {"x": 470.0, "y": 98.0, "t": 1657102762880}
      ]
    ],
    "threshold": 0.01,
    "smoothRatio": 0.65,
    "velocityRange": 2.0
  });

// Convert to Map
final dataAsMap = json.decode(dataAsString);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.