I have an module with an 'assets' folder located in the same directory as my pubspec.yaml file. In my assets folder I have test.txt, and simpleObject.json.
flutter:
assets:
- assets/test.txt
- assets/simpleObject.json
I believe the following code should then allow me to read it into my app.
var test = await DefaultAssetBundle.of(context).loadString("assets/test.txt");
Sadly I get the following error:
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Unable to load asset: assets/test.txt
The error comes from the asset_bundle.dart. I have to assume this is my fault, but according to everything I've read I'm doing it correctly. Any thoughts?
Here is my file structure if it helps.
MyModule
|_assets/test.txt
|_lib/
|_pubspec.yaml
I got a solution. Even though my package was trying to load its own asset, it still had to specify itself as the location.
Here is how my_package loads an image asset (specifying the package), uses it in a widget, and that widget is easily used by outside apps.
Image.asset(AssetImage("assets/splash.png").assetName, package: 'my_package',);
This is a bit late, but another solution can be:
Image.asset('packages/<package_name>/assets/splash.png');
I encountered this problem and took a lot of time before it was resolved.
The solution was to downgrade to a previous version (git checkout v1.5.4-hotfix.2)
Related
I'm trying to run my flutter-app in web. So I created a web folder and added all the necessary things. Since I'm using the objectBox in multiple dart files, I'm getting error based on ObjectBox.
So what I did to find the issue was, In the main.dart file i'm just trying to display only simple Container widget containing a text. But still I'm getting the same error related to objectBox with its entity.
So my doubt is, Is it compiling all the dart files located in lib? If then, can I exclude them.
I have tried(created a build.yaml file) to exclude all my files which are using ObjectBox.
My build.yaml file:
targets:
$default:
sources:
exclude:
- lib/test_driver/runner.dart
- lib/tools/**.dart
I created a flutter project recently but when I try to run it shows me the error below, how to solve it? Thanks in advance!
**CMake Error at flutter/CMakeLists.txt:75 (add_custom_command): add_custom_command called with OUTPUT containing a "#". This character is not allowed. Exception: Unable to generate build files**
Make sure that there's no # character in any of the directories in your path to where the Flutter project is located. For example, if you have path like this;
C:\#projects#flutter\your_project
You need to remove all hashtags # present, you will have something like this
C:\projects\flutter\your_project
Hope it helped you out ^_^
I am writing uber h3 plugin for flutter. I have working source code but I have problems with creating package more precisely I have problems to bundle libh3.so
Quick overview:
there is uber h3 c source code which is downloaded by. download_deps.sh
then android/build.gradle has build commands
externalNativeBuild {
cmake {
path "../ios/CMakeLists.txt"
}
}
then example/lib/main.dart has some initialization code.
initializeH3((String name) => Platform.isAndroid
? DynamicLibrary.open("lib${name}.so")
: DynamicLibrary.process());
but when I try to build it library file can not be found.
-I tried different locations.
It seems that library native .so is not bundled into application
But I don't konw why
According to tutorial https://flutter.dev/docs/development/platform-integration/c-interop
it should be bundled.
Here is the source code https://github.com/fmatuszewski/h3
I have managed to get this running, the pubspec.yaml was incorrectly formatted and required:
flutter:
plugin:
platforms:
android:
package: com.example.h3
pluginClass: H3Plugin
ios:
pluginClass: H3Plugin
Adding in at the end.
In doing this the package was properly attached.
libh3.so needs to be added into android/src/main/jniLibs to naturally be attached however I also moved the code:
final DynamicLibrary h3 = Platform.isAndroid
? DynamicLibrary.open("libh3.so")
: DynamicLibrary.process();
Back into h3.dart and removed main.dart to get this to run.
I think these were the main issues to get the code running. I had issues working out what was wrong as I am new to plugins - so it was a long process to sit and work out all the ins and outs. In doing this I ended up reworking all of the code to understand what was going on. If none of these points work or you wants eyes on the working code let me know and I can upload it to Github.
This is getting passed back from my exception. This only occurs on web, on ios and android it works perfectly.
Any insight on how to correct this or point me in the right direction will be appreciated.
_newZLibDeflateFilter means that you are using GZipCodec() which related to dart:io library that's currently doesn't support flutter web, in order to decompress your http response you can use archive package
include the package in your YAML file
dependencies:
archive: ^3.3.2
and use GZipDecoder() that's included in the package instead of dart:io GZipCodec()
import 'package:archive/archive_io.dart';
String responseBodyDecompressed = utf8.decode(
GZipDecoder().decodeBytes(response.bodyBytes) //decompression
);
I have stumbled upon a problem in importing the package in Flutter, I tried to solve this by running flutter packages get and also shutting down the project in Android studio and reopening it.
import 'package:task_02_category_widget/category.dart';
Here is the line above, and the error I'm running into when I run it gives the following error in the console.
Your application could not be compiled, because its dependencies could
not be established.
The following Dart file:
/Users/username/Documents/flutter_rectangle_2/lib/main.dart
...refers, in an import, to the following library:
package:task_02_category_widget/category.dart
That library is in a package that is not known. Maybe you forgot to
mention it in your pubspec.yaml file?
If task_02_category_widget/category.dart is part of an old project you are reusing you should put it in a folder in your flutter application and include it like "../ folder /task_02_category_widget/category.dart ". If it is part of github repository you have copy pasted from, just copy the file and use the step above. Most probably you are looking for that . In any other case check here to find the source code.
You should have in your project at a file called pubspec.yaml a definition like this:
name: my_app
dependencies:
task_02_category_widget:
Let’s say that your package is laid out as follows:
task_02_category_widget/
lib/
category.dart
Then, you can import it:
import 'package:task_02_category_widget/category.dart';
More information:
https://www.dartlang.org/tools/pub/get-started
https://www.dartlang.org/guides/libraries/create-library-packages