Background
Trying to use a pure-dart package from a Flutter-project.
The pure-dart package basically is a Database. It reads its own JSON-assets and answers to queries.
The Flutter-project accesses the pure-dart package as a database: PureDart.tellMe("something").
The Flutter-project is not accessing the assets of the pure-dart project directly.
Tried
Inversion-Of-Control seemed interesting, but it does not for work me. The error is always Error while trying to load an asset: Failed to load asset at "assets/BLA.json" (404).
I tried various variations of defining the assets.
How to access asset file in pure dart package?
Question
How to define the assets of the pure-dart package, and where? Do they need to be defined in the Flutter-project and the pure-dart package?
Is there a working example out there demonstrating how to achieve this?
There are a few blog posts and questions on SO regarding this topic, but none actually lead to a working example.
Thanks.
As there seems not plausible way to make a pure-Dart package accessing its JSON-assets, when used consumed by a Flutter project, the alternative is to turn the pure-Dart package into a Flutter project.
The Database-Flutter project needs to access its own assets as follows:
var json = jsonDecode(
await rootBundle.loadString(
'packages/DATABASE_PACKAGE_NAME/assets/asset.json'
)
);
Its pubspec.yaml defines the assets as usual:
dependencies:
flutter:
sdk: flutter
flutter:
assets:
- assets/
The Flutter project consuming the Database-Flutter project simply adds it as a dependency.
Related
We are using a Jenkins Shared Library to centralize some code for all our (scripted) pipelines. Now we factored out some Groovy code into a .jar library (written in Kotlin, compiled to be Java 8 compatible). We published this library to our in-house maven repo and now want to use it in our Shared Libary.
We are using #Grab to load our library and up until that point it works like a charm. However we are getting NoSuchMethodError's. We pinpointed it down a bit, we are using OkHttp in our Kotlin lib. OkHttp internally uses Okio. When we call methods that internally call OkHttp-Code from our pipeline, everything is fine. However when the OkHttp-Code call Okio internally, we get a NoSuchMethodError.
We already checked the published .jar file, it contains the classes with the methods that seem to be missing. Does anybody have an idea what the issue could be?
While we are at it, we can't access environment variables set on Jenkins in our Kotlin library, is there a way we can fix this?
We figured it out. The problem was, that a Jenkins plugin used an older version of okio internally. Because plugins and shared libraries somehow share the same classpath, okio did not get loaded and the version from the plugin got used, therefore the class was not present.
We fixed this by repackaging all dependencies in our .jar, so package names would not interfere and we can make sure that our specified dependencies are being used.
Looking the dependencies here you have a few problems:
OKHttp - seems to expect some Android libraries
okio - depends on the Kotlin runtime
Any calls to these will result in method not found errors unless you find a way to make them available without causing problems in Jenkins
I recently stumbled across Dart, and got pretty excited about it because it almost feels like that perfect language I've always been looking for. I work with PHP at my job (Yes, I know, ew gross) as a web developer and was excited to try and build a web app using the language. Figured it couldn't be too hard as that's what Dart was originally made for. Turns out it more difficult than I though, and I can't even get off the ground. I was hoping someone else could help point me in the right direction.
So, I really haven't done any real coding in this project at all. I literally downloaded the Dart SDK, used stagehand to create web-simple project, then I added a bin/server.dart file to the project. The code in that file was pretty much taken straight out of the online documentation for the mojito package:
import 'package:mojito/mojito.dart';
main() {
var app = init();
app.router
..addStaticAssetHandler('/static');
app.start();
}
I added the dependency mojito: "^0.6.6" to the pubspec.yaml file as well of course. That's all I've done though, like I say, I haven't even managed to get off the ground yet.
When I run server.dart I get the following error:
'package:convert/src/percent/encoder.dart': malformed type: line 23 pos 13: cannot resolve class 'ChunkedConverter' from 'PercentEncoder'
I get the exact same error message if I try to build a server with the shelf_rest package instead of the mojito package.
A search of that error message doesn't bring up too much helpful info, though I found one forum where someone recommended adding convert: ^2.0.1 to the dependencies. Apparently there was a change made in that package that causes incompatibility with other packages. I tried that suggestion but it doesn't seem to be resolving the issue.
I'm certain the issue is some sort of dependency issue, I'm probably using a mix of dependencies that I guess just aren't meshing right. If someone could help me figure out what I'm doing wrong it would be much appreciated. I want to learn and start using Dart but obviously I'm not having such great luck with it...
Here's what the pubspec.yaml looks like in case it helps:
environment:
sdk: '>=1.24.0 <2.0.0'
dependencies:
shelf: ^0.6.0
mojito: "^0.6.6"
convert: ^2.0.1
dev_dependencies:
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
transformers:
- dart_to_js_script_rewriter
The last version of mojito was uploaded in October 2016 and it seems abandoned. Since then, Dart has added Strong mode and begun transitioning to Dart 2. This included significant changes to the type system and updates to SDK libraries.
Additionally, transformers have also been removed - any documentation you find referencing them is out of date. And in this case, the dart2js script rewriter is for client side JavaScript, not servers.
If you're looking for Server libraries, I would recommend just starting with the latest version of Shelf
I'm trying to rollup my completely es6 module repo which has both local imports/export for the projects, and imports to dependencies that are also either scripts or modules.
I'm also trying to have a dual build which creates legacy iife modules via rollup.
This works fine for just my project, no problems. The difficulty is that I have imports for my dependencies.
Rollup's globals and external options are supposed to help but thus far I haven't succeeded in exposing these and rolling up to an iffe. I get
http://backspaces.github.io/asx/libs/three.module.js' is imported by src/Three.js, but could not be resolved – treating it as an external dependency
errors and others. The resulting rollups are not what I want: converting the iife rollup to expect the dependencies to be globals thus removed from the rollup.
I realize this is a pretty general question, but I just want to know how to use these two options to manage my repo so that I have imports to dependencies and can "remove" them in the rollup.
Can anyone clearly explain them and what they do? The rollup wiki is slightly helpful but not complete enough.
For Rollup to be able to include a dependency, it has to be able to find it. It doesn't have any built-in logic for fetching a remote URL such as http://backspaces.github.io/asx/libs/three.module.js (that could be done as a plugin, but AFAIK that plugin hasn't been written, and I'd probably advise against it anyway).
Instead, you'd be better off importing the module from node_modules like so...
import THREE from 'three';
...and adding node-resolve and commonjs to the config that generates the IIFE.
For the config that generates the non-IIFE build where Three.js is kept external, you would need to use the paths config to point three back to the URL:
// rollup.config.js
export default {
entry: 'src/main.js', // or whatever
// ...
external: ['three'], // so it's not included
paths: {
three: http://backspaces.github.io/asx/libs/three.module.js
}
};
I'm get this error with a angular 1.0.0 project and I don't know what this means and what should be done. I do not understand the explanation in link https://github.com/angular/di.dart/wiki/Uninitialized-Module.DEFAULT_REFLECTOR-error
My project declare one dependency in a library that declares a dependency in angular. So my project doesn't have a direct dependency in angular and I can't declare transformers in the pubspec.yaml file.
I got the same error when I was using main() async - so removing the async and going back to the conventional Future-base version was the solution.
I filed an issue report: https://github.com/angular/di.dart/issues/221
Angular now use static generated content. The html files for components are processed during pub install or pub serve
The pubspec.yaml file needs something like:
transformers:
- angular:
html_files:
- web/controllers/error_warning_controller.html
- web/controllers/http_interceptor_controller.html
- web/controllers/notify_tray_controller.html
- web/controllers/notify_desktop.html
- web/controllers/panel_controller.html
- web/controllers/window_controller.html
dart_sdk: /usr/local/opt/dart/libexec
Also it not work if you use a library that depends on angular you need a direct dependency for angular transform to work, I work around declaring the dependency twice, one for the library one for the project that use the library.
I'm trying to package the Mac version of an open source application that I didn't write (I'm not much of a coder). I'm using py2app 0.6.4. The application builds on my system properly, but I'm unsure of what to list for the includes in the setup.py file.
The dependencies include qt4, PyQt, matplotlib, cherrypy, and sip.
When I looked at this article on handling PyQt applications, I noticed the dependencies were not listed simply as PyQt but rather *PyQt4._qt* etc. How can I determine what to insert in the includes statement from the code of the application?
When py2app runs, it's going to look at each of your scripts, automatically grabbing any modules or packages imported by your scripts. In many cases, this will suffice and you won't need to list anything in the includes variable. Some packages have extra files such as data files that aren't used by the import statement, but must be present for the package to run correctly. Then you need to explicitly include it so py2app will grab it as well. Try to use your app; if you get an error that some module or file isn't found then worry about putting it in the includes variable.