Assets in Flutter package are not visible in the app - flutter

I've created a package, which uses some assets (sf2 file, ttf files, etc). Assets don't seem to load. I can fix this by including these files in the assets folder of my main project (so now, every asset in the package is also in my main project). However, when I build a web app, it still creates an extra folder for my package with the files that it needs.
Is there a way around this? How do I enforce the package to use the assets from itself?

After some digging, I've found a way to include it.
'packages/livescore_sdk/assets/default_team_logo.png' works instead of 'assets/default_team_logo.png'

Include the assets in your lib folder, and import it from local project only.
Assuming the project name ABC:
Steps
Create assets folder in lib, example: lib/assets. Full assets example url: ABC/lib/assets/some_asset.png
Copy the assets in this folder.
Import the assets in your pubspec.yaml like this:
assets:
- packages/ABC/assets/some_asset.png
Hope this help someone. :smiley:

Related

Why Flutter Web Assets folder inside of another assets folder?

I have an assets folder in my project. When I run flutter build web and look into the resulting build, this assets folder is nested inside another automatically generated assets folder. So, now I have to either:
Prepend every asset reference in my code with assets/.
or
Move all my assets up a directory, so instead of the path being assets/assets/asset.jpg, now it will be assets/asset.jpg.
Is there a way for me to stop flutter from nesting my assets folder in another assets folder?

How to specify a path of file inside flutter project(How to retrieve CSV string inside flutter project)

For example, place the test.csv file directly under the lib directory of the flutter project.
If I want to get the CSV(string) in that file and do something with it when running the app, how do I get(retrieve) the CSV file?
Generally external files are placed in an assets folder. Assuming you put it in the root of the assets folder. You need to do two manipulations.
List this file as an asset in the pubspec.
assets:
assets/my_csv_file.csv
2.Read it in your app.
import "package:flutter/services.dart" as s;
var csvData = await s.rootBundle.loadString("assets/my_csv_file.csv");
Edit : the assets folder is in the root of the project.
By convention, you place any assets in a freshly created asset folder at the root of your project.
For getting those assets, you can use a dependency called path_provider that will allow you to get paths (temporary paths, project root folder etc..).
You will be interested in the project root folder and then navigate to the /asset folder or the /lib folder in the specific case of this question.

How to add a second example app to a Flutter plugin project?

When creating a plugin project in Flutter, an example app, that is using the plugin, is added in a subfolder of the plugin project. What needs to be done to add a second "example" app to the plugin folder?
So far I have:
Copied and renamed the example folder to (let's call it) app2.
Adjusted the package names at the android manifest files of app2.
Renamed pluginrootfolder/app2/pluginname_example.iml to pluginrootfolder/app2/pluginname_app2.iml (to reflect the name of the second app).
In the .iml file of the plugin project (the root folder):
Copied and adjusted the exclude folder directive to reflect app2
<excludeFolder url="file://$MODULE_DIR$/app2/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/app2/.pub" />
<excludeFolder url="file://$MODULE_DIR$/app2/build" />
Run Flutter clean and Flutter pub get in both the plugins root directory and app2's directory.
Problem now is that app2 causes 1k+ Target of URI doesn't exist: error messages - from packages (like provider and json_annotation) to classes in the plugin's root project.
Do you have any ideas what's wrong here or how to fix it?
Firstly, please give a full GitHub reproducible repository and link it here so I can examine. And also paste (e.g. using github gist) the long log. Please comment to this answer so I can examine more.
"In the .iml file of the plugin project (the root folder)" - indeed not that needed. iml is for intellij idea, and is unrelated to flutter. so should not error even with wrong iml. You can even safely delete iml and when you import that module in intellij it will auto recreate.
Have you modified pubspec.yaml? e.g. the package name in it.
And, where is your plugin located, relative to your app2? In example app, the default pubspec.yaml uses path: ../ to point to your plugin. So if your app2 does not have .. as the plugin path you should change this as well.
Anyway, paste your log and give a reproducible sample please...
I suspect your issue is in the dependency tree. Your example2 project does not seem to point to the project above it. The only manual edits you need are in the pubspec.yaml. In the dependencies for the second example project.yaml file, include the path to the root project. For example:
dependencies:
<YOUR_ROOT_PROJECT>:
path: ../
flutter:
sdk: flutter
Including that should map the decencies of the root over with pub.get.
That should take care of the Target of URI doesn't exist errors.
Since you are using .iml files, I assume you're using an IntelliJ/JetBrains IDE. Creating example subprojects can be done without all of the manual work you listed.
You don't have to copy the files themselves manually to create a second example. You can simply right-click on the project root and select new module. Choose Flutter. The project type is Application.
Secondly, you don't have to add the second project to the exclude folders.

How to build assets separately from the rest of the app with Parcel

I have a project that I am building with parcel. Since it is mostly static, I only have some files that should be updated once a day, I put the project on aws s3 bucket. I am thinking of updating the files that should be updated once a day, with a lambda function. But, in my project that is structured like this:
src/
assets/
components/
main.js
...
In the folder assets, I have two other folders data and icons. Data folder holds json files that should be updated once a day.
assets/data/
/icons/
When I run parcel to build a project, I see that all files inside icons folder are built as individual files.
How can I make files inside the data folder to build separately so that I know which files I need to target in order to update them?
I found this package parcel-plugin-static-files-copy
that does exactly what I need. Only had to add this to my package.json:
"staticFiles": {
"staticPath": "src/assets/data"
}

How to add library ending with numbers (libXXX.so.1) in Unity3D assets

I'm creating a Unity3D application which depends of libraries named as libXXX.so.1
Unity are not bundle them into the assets: I can't select them in the editor and they are just ignored if I put them into the Assets folder.
It's working well if library names are libXXX.so, but renaming breaks the links between libraries.
How to force Unity to include those libraries inside Plugins folders?
I want to create a distribuable unitypackage so I can't just copy them to the output folder after each build.
Source folder:
find . -name "*.so*"
./Assets/Plugins/Linux/libTest1.so
./Assets/Plugins/Linux/libTest2.so.1
Build foder:
find . -name "*.so*"
./Project_Data/Mono/x86_64/libmono.so
./Project_Data/Mono/x86_64/libMonoPosixHelper.so
./Project_Data/Plugins/libTest1.so
./Project_Data/Plugins/x86_64/ScreenSelector.so
./LinuxPlayer.so
Unity3D will include all the files that are in the Assets/Resources folder (and all sub-folders under Assets/Resources). Check out this document page:
https://docs.unity3d.com/ScriptReference/Resources.html