Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load asset on window #1

Open
MZengYi opened this issue May 26, 2022 · 8 comments
Open

Unable to load asset on window #1

MZengYi opened this issue May 26, 2022 · 8 comments

Comments

@MZengYi
Copy link

MZengYi commented May 26, 2022

image

pubspec.yaml

assets:
   - assets/data.json
    var datas = await JsonAssetCache(basePath: "assets").load('data.json') as List;
[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Unable to load asset: assets\data.json
#0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:237:7)
<asynchronous suspension>
#1      AssetCache.loadAsset (package:asset_cache/src/asset_cache.dart:30:26)
<asynchronous suspension>
#2      ImageModel.loadData (package:vshow/data.dart:43:17)

@erf
Copy link
Owner

erf commented May 26, 2022

Did you describe data.json as an asset in your pubspec.yaml file?

@MZengYi
Copy link
Author

MZengYi commented May 26, 2022

@erf yes

pubspec.yaml

assets:
   - assets/data.json

@MZengYi
Copy link
Author

MZengYi commented May 26, 2022

on web, android and iOS work. but on window didn't work

@erf
Copy link
Owner

erf commented May 26, 2022

OK. I'm not able to test on Windows. It sounds like a platform specific path issue, but I'm using the path package.. Strange. PR's are welcome.

@MZengYi
Copy link
Author

MZengYi commented May 26, 2022

should not work the path separate '\' on windows. because pubspec.yaml always define as '/'

so work for below code

    var datas = await JsonAssetCache().load('assets/data.json') as List;

@erf
Copy link
Owner

erf commented May 26, 2022

Not sure. Maybe this is a Flutter issue?

@MZengYi
Copy link
Author

MZengYi commented Jun 13, 2022

assets:

  • assets/data.json

it always defined as '/' in pubspec.yaml, so all platforms should be as '/'

@erf
Copy link
Owner

erf commented Jun 13, 2022

Ok, can try this and confirm this fixes the issue on Windows?

Repository owner deleted a comment Dec 24, 2023
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

No branches or pull requests

2 participants