5

I am writing a Dart package, and I would like to have a resources directory that Pub includes with the package. I want this directory to be accessible relative to the root file of the package. Is there a standard way of doing this with Pub?

Thanks!

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Gabriel Ratener
  • 595
  • 5
  • 20

2 Answers2

4

In general only files within lib/** can be used from other packages, therefore this is where you should put them.

Your question doesn't contain a lot of information what kind of package your want to create and what kind of resources you want to ship with the package or how the resources are supposed to be used by the user of the package. There are a few open bugs about other ways to make resources available to running applications.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • I have chosen to do this, but it feels like hack, there should be a better way. Thanks! – Gabriel Ratener Apr 19 '15 at 16:49
  • What do you miss? There was an additional `asset` directory supported but it was there were no convincing reasons to keep it. – Günter Zöchbauer Apr 19 '15 at 16:51
  • The part I don't like is having to mention the name of my package in the asset path. – Gabriel Ratener Apr 20 '15 at 00:39
  • I guess there is no way around, at least none I'm aware of. – Günter Zöchbauer Apr 20 '15 at 06:22
  • Could someone please provide a short example of how to access the file lateron inside the package? I'm want to put a json file inside the asset filder of my dart package and have to access the json string from the package code. However I can't use `File('file.json)` because I use this package in flutter application where it wouldn't find the path – tmaihoff Jun 05 '21 at 12:40
0

Assets are available within the lib folder. Create a folder under lib called assets, i.e. /lib/assets

Then link it in pubspec.yaml:

assets: - assets/something.jpeg