Share objects between aqueduct and flutter - dart

I'm using aqueduct as a server where I defined an user object and extended it to make use of OAuth:
class ManagedUser extends ManagedObject<_User> implements _User, ManagedAuthResourceOwner<_User>
After finishing the work on aqueduct I started working on the flutter app and wanted to use the ManagedUser-object in flutter as well, that's why I thought about putting it into a separate project.
The problem I face now (during deployment) is the following:
ERROR:flutter/shell/common/shell.cc(184)] Dart Error: error: import of dart:mirrors with --enable-mirrors=false
As I read here Dart Error: error: import of dart:mirrors with --enable-mirrors=false it's because flutter doesn't seem to support parts of aqueduct (which I unfortunately need in my shared project to use ManagedObject).
So I'm kinda stuck here. What are my options? I really don't like to map all objects again on the flutter side.

You won't be able to combine Aqueduct and Flutter in the same project - they have different compilation targets, and both take advantage of those targets.
The general approach is to use aqueduct document to create an OpenAPI document from your code, then use an OpenAPI code generator to build your client-side code. This approach is preferable to sharing code between the server and clients. Code can be shared between browser and mobile targets. It is a good idea to avoid having one type that represents the database, server and client definition of an object. A client type and a database table mapping will eventually have differences that will be difficult to manage.

Related

Getting error while adding SwiftKafka package manager in Swift

Getting error while adding SwiftKafka using package manager in Swift. Got error like undefined symbol. I have to added target in targets array in package manage package file but still getting error.
How to use swiftKafka library in swift?
Assuming you're writing an app not for macOS, then Kafka cannot be used with mobile applications, mostly because of network switching.
If that is your goal, you should look into alternatives like the Confluent REST Proxy, and use HTTP calls to its API instead.

Exporting from Azure Custom vision to ios CoreML doesn't work on xcode or ios

I am using the Azure Custom Vision service customvision.ai for data labelling. I trained my data from Azure and it can detect the objects via API or via quicktesting from the customvision.ai. I exported it to CoreML by the insturctions from Microsoft's documentation, but I couldn't make it work for ios or xcode.
There is a preview tab for coreML files on xcode. The sample models I downloaded from the internet works as expected. However, I cannot get the expected results for my model from xcode, compared to the API or quicktest via website.
How can I get it work on my ios app. I am using General (compact) [S1] domain for my model.
Progress Update:
I have found a sample code from Azure's github. It works with their model. However when I change the model and config files to my ones, it throws Bad access error somewhere.
Also I recognized the exporter versions are different and there is an extra metadata_properties.json in my version. So even if the readme from the repo states any 2.x version is supported, (mine is 2.1 but their model is 2.0) I guess that sample code doesn't support the version I exported.
Can I downgrade my model's version or are there any sample swift projects for the updated version.
Changing the domain from General (compact) [S1] to General (compact) [S1] and feeding this new model into my project fixed everything. I don't know if this was coincidence but without replacing a single line of the code, it worked.

Can't implement Firebase across multiple Swift modules

This is for Firebase 6.26.0 and 6.27.0 (I've tried both for reasons that will become clear)
I have a Swift application I'm trying to decompose into modules from its current monolith, but so far I have not been able to expose Firebase classes across the modules (i.e frameworks) by installing Firebase pods in each individual module. It will only work when there is only one existing library, and when that library is installed in the application target, where it is instantiated in AppDelegate.
Does anyone know if it's possible to implement Firebase across multiple modules in a single workspace?
Expected results
That Firebase classes will be exposed to all modules in a multi-module Swift application, with one or more copies of the Firebase library present, allowing all modules to call Firebase methods and implement Firebase classes within a single, global instance of FirebaseApp.
Actual results
Either Firebase refuses to instantiate because of the presence of more than one Firebase library in the workspace, or, when only one library is present, Firebase classes cannot be exposed to other modules in the workspace.
What I've done
Installed individual Firebase pods in every module requiring them. On launch I got this error:
.
The default FirebaseApp instance must be configured before the defaultFirebaseApp instance can be initialized
.
According to an answer from a Firebase team member on another StackOverflow post, this is caused by the presence of more than one Firebase library in the workspace.
Installed only one pod to create a "FirebaseProxy" module that both the application target and all other modules could share. By using typealiases and extensions I was able to let classes implement Firebase classes without having to be exposed to the actual Firebase library, for example:
import Firebase
public typealias FirebaseUserProxy = Firebase.User
public extension FirebaseUserProxy {}
So this way an implementing class could use the Firebase.User type by using FirebaseUserProxy instead, and without having to be directly exposed to the Firebase library.
.
However, there were some proxied classes that still seemed to require being exposed to the full library. (My brain is a bit addled from dealing with all this so I've forgotten exactly which ones, I believe it was FirebaseApp.) But even using #_exposed import Firebase in the proxy definition didn't do the trick, and I only got the message Missing required module 'Firebase'.
Same solution as in #2, but using use_frameworks! :linkage => :static in my Podfile. No luck. And yes, I did try using $(SRCROOT)/Stat in my frameworks search paths build settings.
Finally I tried integrating the library directly into my project without using Cocoapods. Here I was using 6.26.0 since the Firebase download link with a 6.27.0 in the URL resulted in a Not Found message, so I manually changed it to 6.26.0 and that downloaded fine
.
I installed the library in the application and in another module, hoping that somehow this method would obscure each library from the other, but ended up with the same error message as in #1... The default FirebaseApp...
.
I also tried using the proxy method from #2, but that resulted in the same error.
.
I had to set :linkage => :static in my Podfile so the installed pods would play nicely with the integrated library. Turning it off resulted in an error.
Alternatives
If I can't get this to work, I may have to refactor my code so that the Firebase-dependent code exists in the application itself instead of a standalone framework module. This would not impact functionality, but it would break the architecture and make the code a good deal more convoluted and brittle.
There is a solution on the Firebase git repo (that I haven't tried), that suggests reverting back to v.6.15.0. I am reluctant to do this though since the most recent release is at 6.27.0 and I don't want to be unable to upgrade and risk using an older version that later releases will undoubtedly break eventually.
Finally
It's disappointing that such a widely used and vital tool can only be used in monolith applications, basically limiting developers to a single, often suboptimal, type of architecture. Have I missed something? Maybe. It wouldn't be the first time. But if anyone can light the way out of my dilemma I would be happy to buy you a beer, and given the current social distancing regulations, consume it on your behalf.

Can I access metadata annotations of a type or parameter in flutter?

Or is that capability lost with the loss of the reflect package?
What I'm curious about is can I use annotations in my own flutter app? Or is that a feature only available in dart, but not flutter?
Annotations can only be used for static analysis in Flutter.
For example the analyzer that generates hints and warnings in your IDE, code generation tools like built_value, built_redux, json_serializable, and other packages that use https://github.com/dart-lang/build make use of this.
There is no way to get metadata information at runtime without dart:mirrors.
There is work in progress to make the reflectable package work with code generation. This might work with Flutter eventually to generate code that allows to access predefined metadata at runtime.
See also https://github.com/dart-lang/reflectable/tree/use_build
Yes, of course you can use metadata annotations in flutter. Flutter has a meta-library, which you can look into to know about available annotations that can be used with flutter.
Hope this helped!

Whirlyglobe private API complain during app submission

I have a simple app which uses whirlyglobe framework (2.2). Otherwise, it is pretty basic program with Apple frameworks.
When I tried to validate the app (and during the distribution, Xcode complains that my app is using private API; specifically it calls "rootElement", and "attributeForFont:". I suspect these functions are part of WhilyGlobe component distribution.
What is the easiest way to remove those files from the framework? Do I need to have the source and compile the framework myself? Or is there a simpler way?
Solved. Here is what I did:
1) Searched in github repository of WhirlyGlobe and found the file that uses the functions which caused issue.
2) I did not need the functionality provided by the file that had the functions.
3) Removed the references (class instantiation) to the file from my project.
That's actually part of the KissXML framework and the implementation is in there. I suspect Apple's test is in error.
In any case, if you're not using the WMS functionality, you can probably drop it out just fine.

Resources