import 'dart:io'; import 'package:sqflite/sqflite.dart'; class DB { static final DB _singleton = DB._internal(); String dbName = "workouttest.db"; Database _db; factory DB() { return _singleton; } DB._internal() { dbName = 'workouttest.db'; } Future initDb() async { _db = await openDatabase(dbName); File dbFile = File('database.sql'); String contents = await dbFile.readAsString(); List commands = contents.split(";"); commands.forEach((sqlCommand) { if (!sqlCommand.startsWith("--")) { DB().getDB().execute(sqlCommand); } }); } Future closeDb() async { if ( _db != null ) { this._db.close(); } } Database getDB() => this._db; }