Unsupported operation: _newZLibDeflateFilter, what is this? - flutter

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
);

Related

how to bundle flutter ffi plugin

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.

Why the app produced by flutter build web sometimes doesn't work?

I have 2 issues that only appear when executing flutter build web.
Sometimes flutter build web fails complaining (wrongly) about types that were not compatible (see below).
Sometimes the build process finishes but then the web app doesn't work: doesn't display anything and there are no messages in the console.
The error I mention is something like this:
% flutter build web
Target dart2js failed: Exception: lib/main.dart:24:31:
Error: A value of type 'ApiUsersRepository' can't be assigned to a variable of type 'UsersRepository'.
- 'ApiUsersRepository' is from 'package:my_app/api_users_repo.dart' ('lib/api_users_repo.dart').
- 'UsersRepository' is from 'lib/users_repo.dart'.
final UsersRepository usersRepository = ApiUsersRepository();
^
Error: Compilation failed.
The app is working in iOS and web when developing.
The solution
I changed all imports of my files like:
import 'package:my_app/users_repo.dart';
To:
import 'users_repo.dart';
More Details
Investigating the error about types, I found this issue, where the important part is this comment: after changing every import to relative format it resolves my problem.
So I did that, and it solved the 2 issues, the compilation error, and the runtime error.
for me I had to remove a package that was corrupted. c:\src\flutter.pub-cache\hosted\pub.dartlang.org\localstorage-4.0.0+1 Apparently, a file had become corrupted by me invertly. I removed the package and did a flutter pub get then recompiled and it worked.

Flutter Package Reading its Own Assets

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)

Angular Dart Tutorial - Unable to find modules for some sources

I'm trying to follow the Angular Dart tutorial (https://webdev.dartlang.org/angular/tutorial/toh-pt1) but got stuck after adding some html that makes use of the ngModel directive.
According to the tutorial in order to make use of the ngModel directive one has to add "angular_forms: ^2.0.0" to the pubspec.yaml, import 'package:angular_forms/angular_forms.dart' and add "formDirectives" to the component directives. I did all of that including running "pub get" to get the dependencies but when I run "webdev serve" I get the following error:
[SEVERE] build_web_compilers|entrypoint on test/app_test.dart (cached):
Unable to find modules for some sources, this is usually the result of either a
bad import, a missing dependency in a package (or possibly a dev_dependency
needs to move to a real dependency), or a build failure (if importing a
generated file).
What am I missing?
I had the same the problem. I don't think it mentions explicityly in the tute but after adding angular_forms dependency to the pubspec.yaml file, you need to pull in this new dependency with:
pub get
Hope it helps!

Target URI doesn't exist, when trying to import a package in flutter

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