45 lines
1.1 KiB
Dart
45 lines
1.1 KiB
Dart
import 'package:sqflite/sqflite.dart';
|
|
import 'package:path/path.dart';
|
|
|
|
class LocalDatabase {
|
|
static final LocalDatabase _instance = LocalDatabase._internal();
|
|
factory LocalDatabase() => _instance;
|
|
LocalDatabase._internal();
|
|
|
|
static Database? _database;
|
|
|
|
Future<Database> get database async {
|
|
if (_database != null) return _database!;
|
|
_database = await _initDB();
|
|
return _database!;
|
|
}
|
|
|
|
Future<Database> _initDB() async {
|
|
final dbPath = await getDatabasesPath();
|
|
final path = join(dbPath, 'app_database.db');
|
|
|
|
return await openDatabase(
|
|
path,
|
|
version: 1,
|
|
onCreate: (db, version) async {
|
|
/// CITY TABLE
|
|
await db.execute('''
|
|
CREATE TABLE selected_city (
|
|
id INTEGER PRIMARY KEY,
|
|
city_id INTEGER
|
|
)
|
|
''');
|
|
|
|
/// ONBOARDING TABLE
|
|
await db.execute('''
|
|
CREATE TABLE onboarding_state (
|
|
id INTEGER PRIMARY KEY,
|
|
is_first_time INTEGER NOT NULL,
|
|
page INTEGER NOT NULL
|
|
)
|
|
''');
|
|
},
|
|
);
|
|
}
|
|
}
|