hemandroid
hemandroid

Reputation: 618

Unable to load local json file from assets in Flutter Package project

I was working on building a Package project in Flutter and hence I have to add lot of .svg image files and local config.json file from Assets for the Package. But I can able to load the .svg files, but it was throwing error for loading .json file.

I have filed a bug on the github flutter repo, please check the below link for further details. Please do the needful.

Unable to load local json file from "assets" folder in Flutter Package project

Upvotes: 0

Views: 1006

Answers (2)

adee alamsz
adee alamsz

Reputation: 393

Try to write the path with the following format packages/<yourpackagename>/<path to your file> such as below

String jsonString = await rootBundle.loadString('packages/yourpackagename/assets/yourfile.json');

Upvotes: 0

Junsu Cho
Junsu Cho

Reputation: 864

flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg
  assets:
    - assets/JsonConfig/test.json

pubspec.yaml

Upvotes: 0

Related Questions