database property

Future<Database> get database

Gets or creates the database instance.

If the database doesn't exist, it will be created and initialized with all necessary tables and data. Subsequent calls return the cached database instance for optimal performance.

The database is created with version 1 and includes:

  • All required tables with proper foreign key constraints
  • Initial data populated from JSON assets
  • Indexes for optimal query performance

Returns a Database instance ready for use.

Throws DatabaseException if database creation or initialization fails.

Implementation

Future<Database> get database async {
  if (_database != null) return _database!;
  _database = await _initDatabase();
  return _database!;
}