Skip to main content
added 813 characters in body
Source Link
sinshev
  • 215
  • 2
  • 5
ByteData data = await rootBundle.load(join(dbPath, '/backup.db'));

You are trying to load "/backup.db" from the asset bundle adding dbPath to the key.

You need to add the backup.db to the assets folder if you want to load the database this way.

If you know the location of the .db file and it's not in the assets then why do you need to import it? Just open it.

You can copy the database to another location using File(path).copy(String newPath)

Future<void> initDB() async {
    Directory documentsDirectory = await getApplicationDocumentsDirectory();
    String newPath = join(documentsDirectory.path, '/backup.db');
    final exist = await databaseExists(newPath);
    if (!exists) {
        try {
            final dbPath = await ExtStorage.getExternalStoragePublicDirectory(
            ExtStorage.DIRECTORY_DOCUMENTS);
            final path = join(dbPath, '/backup.db');
            File(path).copySync(newPath);
        } catch (_) {}
     }
}

Future<Database> openDB() async {
    Directory documentsDirectory = await getApplicationDocumentsDirectory();
    String path = join(documentsDirectory.path, '/backup.db');
    await initDB();
    Database db = await openDatabase(path);
    return db;
}
ByteData data = await rootBundle.load(join(dbPath, '/backup.db'));

You are trying to load "/backup.db" from the asset bundle adding dbPath to the key.

You need to add the backup.db to the assets folder if you want to load the database this way.

If you know the location of the .db file and it's not in the assets then why do you need to import it? Just open it.

You can copy the database to another location using File(path).copy(String newPath)

ByteData data = await rootBundle.load(join(dbPath, '/backup.db'));

You are trying to load "/backup.db" from the asset bundle adding dbPath to the key.

You need to add the backup.db to the assets folder if you want to load the database this way.

If you know the location of the .db file and it's not in the assets then why do you need to import it? Just open it.

You can copy the database to another location using File(path).copy(String newPath)

Future<void> initDB() async {
    Directory documentsDirectory = await getApplicationDocumentsDirectory();
    String newPath = join(documentsDirectory.path, '/backup.db');
    final exist = await databaseExists(newPath);
    if (!exists) {
        try {
            final dbPath = await ExtStorage.getExternalStoragePublicDirectory(
            ExtStorage.DIRECTORY_DOCUMENTS);
            final path = join(dbPath, '/backup.db');
            File(path).copySync(newPath);
        } catch (_) {}
     }
}

Future<Database> openDB() async {
    Directory documentsDirectory = await getApplicationDocumentsDirectory();
    String path = join(documentsDirectory.path, '/backup.db');
    await initDB();
    Database db = await openDatabase(path);
    return db;
}
added 89 characters in body
Source Link
sinshev
  • 215
  • 2
  • 5
ByteData data = await rootBundle.load(join(dbPath, '/backup.db'));

You are trying to load "/backup.db" from the asset bundle adding dbPath to the key.

You need to add the backup.db to the assets folder if you want to load the database this way.

If you know the location of the .db file and it's not in the assets then why do you need to import it? Just open it.

You can copy the database to another location using File(path).copy(String newPath)

ByteData data = await rootBundle.load(join(dbPath, '/backup.db'));

You are trying to load "/backup.db" from the asset bundle adding dbPath to the key.

You need to add the backup.db to the assets folder if you want to load the database this way.

If you know the location of the .db file and it's not in the assets then why do you need to import it? Just open it.

ByteData data = await rootBundle.load(join(dbPath, '/backup.db'));

You are trying to load "/backup.db" from the asset bundle adding dbPath to the key.

You need to add the backup.db to the assets folder if you want to load the database this way.

If you know the location of the .db file and it's not in the assets then why do you need to import it? Just open it.

You can copy the database to another location using File(path).copy(String newPath)

Source Link
sinshev
  • 215
  • 2
  • 5

ByteData data = await rootBundle.load(join(dbPath, '/backup.db'));

You are trying to load "/backup.db" from the asset bundle adding dbPath to the key.

You need to add the backup.db to the assets folder if you want to load the database this way.

If you know the location of the .db file and it's not in the assets then why do you need to import it? Just open it.