40 lines
1.0 KiB
Dart
Raw Normal View History

2022-06-24 22:41:08 +05:30
import 'package:sqflite/sqflite.dart';
import 'package:sqflite_pust_local_notification/models/task_model.dart';
class DBHelper {
static Database? _db;
static final int _version = 1;
static final String _tableName = "tbtask";
static final String _DbName = "task.db";
static Future<void> initDb() async {
if (_db != null) {
return;
}
try {
String _path = await getDatabasesPath() + _DbName;
_db = await openDatabase(
_path,
version: _version,
onCreate: (db, version) {
return db.execute(
"CREATE TABLE $_tableName("
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
"title STRING, note TEXT, date STRING,"
"startTime STRING, endTime STRING,"
"remind INTEGER, repeat STRING,"
"color INTEGER, "
"isCompleted INTEGER)",
);
},
);
} catch (ex) {
print(ex);
}
}
static Future<int> insert(TaskModel? task) async {
return await _db?.insert(_tableName, task!.toJson()) ?? 1;
}
}