initDataBase static method

LazyDatabase initDataBase()

Implementation

static LazyDatabase initDataBase() {
  return LazyDatabase(() async {
    final packageInfo = await PackageInfo.fromPlatform();
    final version = packageInfo.version;
    final cachedPath = path.join(
      (await getApplicationDocumentsDirectory()).path,
      'YogivDB$version.db',
    );
    if (!await File(cachedPath).exists()) {
      final dbPath = await rootBundle.load('assets/databases/YogivDB.db');
      await File(cachedPath).writeAsBytes(dbPath.buffer.asUint8List());
    }
    sqlite3.tempDirectory = (await getTemporaryDirectory()).path;
    return NativeDatabase.createInBackground(File(cachedPath));
  });
}