Is it possible to use Brick/Drift with Freezed?

Hello Community,

I have an app that just needs to persist data in a local database.

I am trying to find the best package to learn and use in this project and future ones that may also need web.

I thought about drift but when just started with it I found that it has an opinionated structure that differs from the needed one for Freezed, what do you advice ?

I have previously used Supabase & Powersync (for offline-first purpose) that works pretty well even on the web but here we don’t need any remote database.

Freezed is a bad package, don’t use it. It makes using classes as intended in Dart impossible (hence your problem with drift). If a tool get in your way, it is a bad tool.

If you need equality check, copyWith and serialization, use dart_mappable.

If you only need union types, use sealed class in Dart 3+

And, BTW, Drift is the best ORM out there, upon SQLite (which is the best real database available for mobile)

4 Likes

Thanks for your answer

What about Offline-First concept ? I have mentioned Brick for that purpose.

There’s a Brick discussion which you might be interested in

1 Like

What about Offline-First concept ? I have mentioned Brick for that purpose.

I use PowerSync + Hasura (because I prefer it over Supabase, but it works on any postgres).

Advantages, IMO:

  1. I have all user data available in my local database (brick is only a cache, it doesn’t have data that you never requested before).

  2. I can filter data using SQL locally (brick is only a cache for a specific call, so, getUserById(1) is cached and getUserById(2) is not and will fail.

  3. PowerSync let you deal with changes that must be uploaded (and they are already checked for conflicts). In my case, I concatenate a big GraphQL query and send it to Hasura. Easy. I could do a lot more, if I wanted. Brick is kinda limited in this regard (it will do the thing, not showing you what things need to be done).

But, of course, this is not intended for all data. If my app has a feed, I would not write it in my local database (brick here makes more sense, I guess).

1 Like

I don’t think it’s fair to flatly state “Freezed is a bad package; don’t use it.”

It is true that Dart’s expanding class options (like enhanced enums and sealed classes) have flipped some scenarios from “Freezed is your only way to get this functionality” into scenarios well supported by plain Dart.

It is also true that Freezed makes assumptions about the shape of your classes which can be incompatible with other packages which make their own assumptions. In those cases, using Freezed may not be possible.

It is also true that dart_mappable is quite good. I rather like that library.

But, all of that said, Freezed has delivered robust data classes to Dart for the last two or three years, and to this day is the only place that brings together many of its features into one solution.

2 Likes

Thanks @CraigLabenz, I agree that calling it a bad package is a bit harsh. My biggest problem with it is that code using it does look like normal Dart anymore which I always refraint if using it till Dart has something similar as part of the language

If it gets in your way, preventing you do what you COULD do or locking you in, it is a bad package.

If you don’t like honesty, ok, I can be political or lie about. But I rather not. There is always an option to block me.

Also, the maintainer doesn’t listen AT ALL the community. If you get, for instance, Simon, from Drift package, that guy is freaking awesome. He listens, he tries to build stuff WE use. And the final product is a VERY good package.

1 Like