DB class

Annotation for create database. It must be applied on an abstract class. Database entities(tables) must be defined in this annotation. Configuration methods like OnConfigure, OnCreate, OnOpen, OnUpgrade and OnDowngrade for actions like Migration can implement in the class that this annotation applied on. Also, Dao classes must be defined in the class that this annotation applied on as an abstract method. TypeConverters annotation also apply on the class that this annotation applied on.

@DB(
  name: 'note_db',
  version: 1,
  entities: [Note],
)
@TypeConverters(Converters)
abstract class NoteDB {
  NoteDao noteDao();

  @OnUpgrade()
  Future<void> onUpgrade(Database db, int oldVersion, int newVersion) async {
    print('Migration');
  }
}

Constructors

DB({required String name, required int version, List<Object> entities = const [], bool readOnly = false, bool singleInstance = true, List<Object> migrations = const []})
const

Properties

entities List<Object>
final
hashCode int
The hash code for this object.
no setterinherited
migrations List<Object>
final
name String
final
readOnly bool
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
singleInstance bool
final
version int
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

fields ↔ _DBFields
getter/setter pair