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,
);
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter