Is there any way to use typeconverter for list of objects in floor database, like we have in room database for android.
For example i have entity class which has field list of objects;
@Entity(tableName: "example")
class Example {
@PrimaryKey()
String id;
...
List<AnotherObject> objects;
}
If floor doesn't support typeconverters which flutter ORM would you recommend to use?
floor handles it in the best way, I mean you are free to develop your code for converting all types of data to a data type that is supported by floor.
You can use something like this:
class ListSubCategoryFinanceConverter
extends TypeConverter<List<SubCategoryFinance>, String> {
@override
List<SubCategoryFinance> decode(String databaseValue) {
final jsonFile = json.decode(databaseValue);
List<SubCategoryFinance> finances = [];
finances = List.from(jsonFile['subCats'])
.map((e) => SubCategoryFinance.fromMap(jsonDecode(e)))
.toList();
return finances;
}
@override
String encode(List<SubCategoryFinance> value) {
final data = <String, dynamic>{};
data.addAll({'subCats': value});
return json.encode(data);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With