fooder-app/lib/storage.dart

31 lines
812 B
Dart

import 'dart:async';
import 'package:flutter/widgets.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
import 'package:fooder/storage/product.dart';
class Storage {
Database db;
ProductStorage product;
static const String path = "storage.db";
Storage({required this.db, required this.product});
static Future<Storage> create() async {
WidgetsFlutterBinding.ensureInitialized();
var db = await openDatabase(
join(await getDatabasesPath(), path),
onCreate: createTables,
version: 1,
);
return Storage(db: db, product: ProductStorage(db: db));
}
static Future<void> createTables(Database db, int version) async {
var batch = db.batch();
await ProductStorage.createTable(batch);
await batch.commit(noResult: true);
}
}