createSqliteTable function

FutureOr createSqliteTable(
  1. Map fields,
  2. String tableName,
  3. String dbName
)

Implementation

FutureOr createSqliteTable(Map fields, String tableName, String dbName) async {
  final database = sqlite3.open('${Directory.current.path}/$dbName.db');
  if (fields.length != 0) {
    var keys = fields.keys.map((key) => '$key ${fields[key]}').join(', ');
    var startSql = 'CREATE TABLE IF NOT EXISTS $tableName ($keys);';
    try {
      database.execute(startSql);
      database.dispose();
    } on SqliteException catch (e) {
      print(e.message);
    }
  } else {
    print('Unknown error!!');
    exit(0);
  }
}