import 'package:cpd/database/todo_db.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:sqflite/sqflite.dart'; import 'package:path/path.dart'; import 'package:cpd/database/habit.dart'; class HabitDatabase { Database? _database; Future get database async { if (_database != null) { return _database; } _database = await _initialize(); return _database!; } Future _initialize() async { final path = await fullPath; var database = await openDatabase( path, version: 1, onCreate: create, singleInstance: true, ); return database; } Future create(Database database, int version) async => await TodoDB().createTable(database); Future get fullPath async { const name = 'habit.dart'; final path = await getDatabasesPath(); return join(path, name); } }