insert method

Future insert()

Implementation

Future insert() async {
  Database db = await database;

  Map data = toMap();

  Map<String, dynamic> newMap = {};

  data.forEach((k, v) {
    if (v.runtimeType.toString() == "DateTime") {
      newMap[k] = (v as DateTime).toIso8601String();
    } else if (v.runtimeType.toString() == "bool") {
      newMap[k] = v as bool ? 1 : 0;
    } else {
      newMap[k] = v;
    }
  });

  int id = await db.insert(
    table,
    newMap,
    conflictAlgorithm: ConflictAlgorithm.replace,
  );

  return find(id);
}