Skip to content

Load web asset from actual path#23

Open
elitree wants to merge 2 commits into
LottieFiles:mainfrom
ReportAll:fix/web-asset-path-bug
Open

Load web asset from actual path#23
elitree wants to merge 2 commits into
LottieFiles:mainfrom
ReportAll:fix/web-asset-path-bug

Conversation

@elitree
Copy link
Copy Markdown

@elitree elitree commented May 24, 2026

Loads the actual asset path passed in, without prepending an extra 'assets'.

EDIT - changed to preserve the 'assets' prefix in the web path, which better matches conventions as well as the current mobile code.

Fixes #22.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 24, 2026

⚠️ No Changeset found

Latest commit: f73a15b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@samuelOsborne
Copy link
Copy Markdown
Member

thanks for your PR and raising the issue @elitree, but I'd like to suggest we move to rootBundle like you suggested but keep 'assets/'

          case 'asset':
            final bytes = await rootBundle.load('assets/$source');
            playerConfig['data'.toJS] = bytes.buffer.toJS;
            break;

Why?

  • This aligns with whats described in flutter's docs: https://docs.flutter.dev/ui/assets/assets-and-images#loading-assets

  • Would be a breaking change for everyone, whereas you just need to change the url in your app:
    DotLottieView(sourceType: 'asset', source: 'assets/animations/foo.lottie') to
    DotLottieView(sourceType: 'asset', source: 'animations/foo.lottie')

  • Testing locally with your change the animation loads but I get a weird error where it fails to fetch but still loads

I tested this suggestions with a base-href build too and it worked. If you could make that change to your PR I'll go ahead and merge it, cheers!

@elitree
Copy link
Copy Markdown
Author

elitree commented May 25, 2026

Thanks for the suggested change. I'll test a little further--I agree that it's easy for me to suggest a breaking change, but not so desirable for the package maintainer and user base. I'll try to update in the next couple days.

@elitree
Copy link
Copy Markdown
Author

elitree commented May 26, 2026

@samuelOsborne you're right, the path should have assets in there, even if we do switch to using rootBundle.load. Thanks for the catch and explanation. I've updated the PR as requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web asset loading constructs incorrect URL; fails on non-default Flutter web layout

2 participants