Skip to content
This repository has been archived by the owner on Jan 18, 2020. It is now read-only.

JSON files with similar animations render incorrect animation #21

Open
colbymaloy opened this issue Mar 7, 2019 · 9 comments
Open

JSON files with similar animations render incorrect animation #21

colbymaloy opened this issue Mar 7, 2019 · 9 comments

Comments

@colbymaloy
Copy link

I have 2 separate .json files, both named uniquely in my assets folder.

Viewing them in an online Lottie previewer, everything looks correct. Both animations are different.

When I actually load the asset and run the animation in my project, it shows the EXACT SAME asset in both widgets. I can load alternate .json animations just fine, but i THINK since the 2 I'm using are so similar in looks, it some how is showing the same asset instead of the correct one.

Tried one of the other lottie packages that use platform view and the animations show correctly.

@dnfield
Copy link
Owner

dnfield commented Mar 7, 2019

Can you provide a reproduction?

@colbymaloy
Copy link
Author

yes, use the files here - https://drive.google.com/open?id=1dAS6UYVpERsP0mmBBVblwHBKfHjFeGWj

and try previewing them, you'll see that they show the same animation in the app but when previewed online, they are different animations

@dnfield
Copy link
Owner

dnfield commented Mar 8, 2019

I suspect the issue might be the way you're loading them - can you share that code?

@colbymaloy
Copy link
Author

colbymaloy commented Mar 8, 2019

i first used the example from the package when i noticed the issue but here is the code i ended up with:

void _loadButtonPressed(String assetName) {
loadAsset(assetName,context).then((LottieComposition composition) {
  setState(() {
    _assetName = assetName;
    _composition = composition;
    _controller.reset();
  });
});
}

loadAsset

Future<LottieComposition> loadAsset(String assetName,BuildContext 
context) async {
print("loading asset : "+assetName);
return await  DefaultAssetBundle.of(context)
  .loadString(assetName,cache: false)
  .then<Map<String, dynamic>>((String data) => json.decode(data))
  .then((Map<String, dynamic> map) =>LottieComposition.fromMap(map));
}

 @override
 Widget build(BuildContext context) {
 return Center(
    child: Container(
  width: 200,
  height: 200,
  child: Transform(transform: Matrix4.translationValues(0.0, 20.0, 
 0.0),
       child: Transform.scale(
        scale: 2.0,
        child: Lottie(
        composition: _composition,
        size: const Size(200.0, 200.0),
        controller: _controller,
      ),
    ),
  ),
));
}
}

@dnfield
Copy link
Owner

dnfield commented Mar 8, 2019

Just to help narrow this down, can you change

.then<Map<String, dynamic>>((String data) => json.decode(data))

to

.then<Map<String, dynamic>>((String data) {
  print(data);
  return json.decode(data);
})

@colbymaloy
Copy link
Author

colbymaloy commented Mar 26, 2019

im actually loading them using your example and the bug is still present.

any update on this bug? this package seems like my last hope !

@dnfield
Copy link
Owner

dnfield commented Mar 26, 2019

I'm not able to reproduce your issue in a clean project. I would instrument your core and try to figure out where this is going wrong.

@colbymaloy
Copy link
Author

colbymaloy commented Mar 27, 2019

I'm not too sure what "instrument your core" means. I created a new project and copy/pasted the example. Are you using the JSON assets linked in the above drive ? I've only had it happen with those two json animations. For clarity, they are two separate animations but if you load "Gongv4" it shows the animation for "timerv4". "Timerv4" animation works just fine

@dnfield
Copy link
Owner

dnfield commented Mar 27, 2019

Sorry, that should have been code not core.

I'm suggesting adding print statements to make sure your actual assets are different.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants