Search code examples
dartflutteraqueduct

Share objects between aqueduct and flutter


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.


Solution

  • 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.