The first thing we need to do in this class is to initialize our database.

PHOTO EMBED

Fri Aug 02 2024 09:09:21 GMT+0000 (Coordinated Universal Time)

Saved by @zemax_c4 ##flutter

class NoteDatabase {
  static final NoteDatabase instance = NoteDatabase._internal();

  static Database? _database;

  NoteDatabase._internal();

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

    _database = await _initDatabase();
    return _database!;
  }

  Future<Database> _initDatabase() async {
    final databasePath = await getDatabasesPath();
    final path = '$databasePath/notes.db';
    return await openDatabase(
      path,
      version: 1,
      onCreate: _createDatabase,
    );
  }
}
content_copyCOPY

https://medium.com/@beccasaka/using-sqlite-in-flutter-3d5a10138090