Flare-flutter: JSON reader should be key-order independent

Created on 12 May 2019  路  2Comments  路  Source: 2d-inc/Flare-Flutter

If the animations key within an artboard appears before the nodes key in the same object, the flare_flutter plugin will crash due to the _collections container not being populated yet.

The JSON reader should work regardless of key order within any JSON object.

For example, this JSON .flr file will crash the reader because the keys are in sorted order (which is the default for writers like https://golang.org/pkg/encoding/json/#Marshal):

{"artboards":[{"animations":[{"animationEnd":0.6,"animationStart":0,"duration":0.6,"fps":25,"isLooping":true,"keyed":[{"component":0,"opacity":[[{"interpolatorType":1,"time":0.24,"value":0},{"interpolatorType":1,"time":0.36,"value":1},{"interpolatorType":1,"time":0.48,"value":1},{"interpolatorType":1,"time":0.6,"value":0}]]},{"component":3,"opacity":[[{"interpolatorType":1,"time":0.12,"value":0},{"interpolatorType":1,"time":0.24,"value":1},{"interpolatorType":1,"time":0.36,"value":1},{"interpolatorType":1,"time":0.48,"value":0}]]},{"component":6,"opacity":[[{"interpolatorType":1,"time":0,"value":0},{"interpolatorType":1,"time":0.12,"value":1},{"interpolatorType":1,"time":0.24,"value":1},{"interpolatorType":1,"time":0.36,"value":0}]]}],"name":"idle","type":"animation"}],"clipContents":true,"color":[0,0,0,1],"height":200,"name":"Artboard","nodes":[{"blendMode":3,"clips":[],"drawOrder":1,"isCollapsed":false,"isVisible":true,"name":"Shape Layer 3","opacity":1,"rotation":0,"scale":[1,1],"translation":[128,100],"type":"shape"},{"color":[0.7921569,0.8156863,0.8352941,1],"fillRule":1,"name":"Fill 1","opacity":1,"parent":0,"type":"colorFill"},{"clips":[],"height":14.963,"isCollapsed":false,"name":"Ellipse Path 1","opacity":1,"parent":0,"rotation":0,"scale":[1,1],"translation":[0,0],"type":"ellipse","width":14.963},{"blendMode":3,"clips":[],"drawOrder":2,"isCollapsed":false,"isVisible":true,"name":"Shape Layer 1","opacity":1,"rotation":0,"scale":[1,1],"translation":[99.875,100],"type":"shape"},{"color":[0.7921569,0.8156863,0.8352941,1],"fillRule":1,"name":"Fill 1","opacity":1,"parent":3,"type":"colorFill"},{"clips":[],"height":14.963,"isCollapsed":false,"name":"Ellipse Path 1","opacity":1,"parent":3,"rotation":0,"scale":[1,1],"translation":[0,0],"type":"ellipse","width":14.963},{"blendMode":3,"clips":[],"drawOrder":3,"isCollapsed":false,"isVisible":true,"name":"Shape Layer 2","opacity":1,"rotation":0,"scale":[1,1],"translation":[71.75,100],"type":"shape"},{"color":[0.7921569,0.8156863,0.8352941,1],"fillRule":1,"name":"Fill 1","opacity":1,"parent":6,"type":"colorFill"},{"clips":[],"height":14.963,"isCollapsed":false,"name":"Ellipse Path 1","opacity":1,"parent":6,"rotation":0,"scale":[1,1],"translation":[0,0],"type":"ellipse","width":14.963}],"origin":[0,0],"translation":[0,0],"type":"artboard","width":200}],"version":21}

Most helpful comment

Thanks @gmlewis, we are aware of this one. It's a byproduct of the JSON loader being based off of our binary loader, which does have guaranteed order. We have a few ideas in mind for how to fix this.

All 2 comments

Thanks @gmlewis, we are aware of this one. It's a byproduct of the JSON loader being based off of our binary loader, which does have guaranteed order. We have a few ideas in mind for how to fix this.

For others running into this issue, I have written a temporary workaround to fix the problem:
https://github.com/gmlewis/lottie2flare/tree/master/cmd/flare-bug-workaround

Was this page helpful?
0 / 5 - 0 ratings