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?
CodePudding user response:
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);