I am developing a Flutter plugin and I want to access the files which are in my plugin folder, not in my demo example folder. Here is my project structure:
assets/
myfile.txt (what I want to access)
example/
lib/
main.dart (where I execute my demo app & import my plugin)
lib/src/
plugin.dart (where I export my plugin library)
getfile.dart (where I want to access 'assets/myfile.txt')
android/
ios/
I'd like to access assets/myfile.txt
, I hope this will be referenced by the plugin code and later to be used in demo app.
I tried using functions in package:path_provider/path_provider.dart
like getApplicationSupportDirectory()
, getTemporaryDirectory()
, and getApplicationDocumentsDirectory()
. They all direct me to /data/user/0/com.mycompany.dartplugin_example/...
folder, which is my demo app folder.
I also tried rootBundle.load()
but it directs me to example/assets/myfile.txt
, that is not what I expect, either.
Can I access the directory & files of my custom plugin in my demo app?
If anyone knows the answer I would really appreciate it!
Update:
The 2019 Answer solved the issue if we specify every asset file name in pubspec.yaml. And the assets should be put under the lib/ folder. However, there is a question (by Going Bananas) unsolved:
This works but I have to include every single asset file separately in the application's pubspec.yaml under assets:. Is there any way to include all assets under a package folder too like one can do for normal assets in an application?
Anyone knows the solution?