Open vanlooverenkoen opened 5 months ago
Hive, in my opinion is better for clean architecture because you don't have to use the generator and all the annotations in your core model classes.
consider this product model using dart_mappable package to generate toMap
and fromMap
@MappableClass(discriminatorKey: 'type')
sealed class Product with ProductMappable {
const Product(this.id, {required this.isAvailable});
final int id;
final bool isAvailable;
}
@MappableClass()
class AvailableProduct extends Product with AvailableProductMappable {
const AvailableProduct(super.id) : super(isAvailable: true);
}
@MappableClass()
class UnAvailableProduct extends Product with UnAvailableProductMappable {
const UnAvailableProduct(super.id) : super(isAvailable: false);
}
using this code at your core folder of your app is a good practice because it depends only on dart_mappable and not on your services (Hive, Isar, Sqflite) or logic (Bloc, Riverpod) ....
then you add the following code to make it compatible with Hive
class ProductAdapter extends TypeAdapter<Product> {
@override
Product read(BinaryReader reader) {
final map = reader.readMap().map((key, value) => MapEntry(key.toString(), value));
return ProductMapper.fromMap(map);
}
@override
int get typeId => 10;
@override
void write(BinaryWriter writer, Product obj) {
writer.writeMap(obj.toMap());
}
}
If you want now to change, lets say to Sqflite, you don't need to change your core prodcut models.
To bee or not to bee:
I suggest you find the most recent version of either hive or isar that works for your requirement. Do not bank on any future functionality being delivered to bail you out. Now if you're able to fork and self maintain go crazy. I use hive for exactly the reasons @CardosoShlomo cites. But don't have much faith in future support.
I am confused on what to use. On Isar faq page I find this.
On the hive quick start page I find this:
And in the github page of hive I find this:
I am building a shopping list/ todo list. Super simple. What should I be using? I would think hive because it is just a key value store. But after reading the other pages I am not sure anymore. Can we have clarification on this?