Should I use additional Models with Drift on Flutter?

81 Views Asked by At

When using Drift with flutter I define a Table for example like this:

class TodoItems extends Table {
  IntColumn get id => integer().autoIncrement()();
  TextColumn get title => text().withLength(min: 6, max: 32)();
  TextColumn get content => text().named('body')();
  IntColumn get category => integer().nullable().references(Categories, #id)();
}

Drift then automatically provides functions to e.g. read data from the table quite easy which returns then a Future<List>.

My question to this topic: Should the returned values be used directly or does it make more sense to have an additional model class for TodoItems with a repository that maps the table data to my native model?

1

There are 1 best solutions below

1
Zahal A_Omer On

Properly you should have an additional model class for TodoItems with a repository that maps the table data because it make the code more efficient,consistent and also you can share it with in the app easly