Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled Exception: UnimplementedError: idbFactoryNative #66

Open
saintjab opened this issue Jan 17, 2025 · 1 comment
Open

Unhandled Exception: UnimplementedError: idbFactoryNative #66

saintjab opened this issue Jan 17, 2025 · 1 comment

Comments

@saintjab
Copy link

saintjab commented Jan 17, 2025

I am getting the error as in title. Running this in Android emulator. This is my code:

const storeName = "myStrore";
final idbFactory = getIdbFactory("native");
late Database database;

void initStore() async {
  database = await getDatabase(idbFactory!);
}

Future<Database> getDatabase(IdbFactory idbFactory) async {
  final db = await idbFactory.open('store.db', version: 1,
      onUpgradeNeeded: (VersionChangeEvent event) {
        final db = event.database;
        db.createObjectStore(storeName, autoIncrement: true);
      });
  return db;
}

then calling the initStore() in main.dart file. Am using the latest version (2.6.1+7) of the lib

@alextekartik
Copy link
Collaborator

The native factory (idbFactoryWeb) is only available on the web. I'm assuming you are using flutter. If you want to target Android, while idbFactoryIo could work I would recommend using idb_sqflite.

The recommended implementation is idb_sqflite
based on sqflite for mobile (iOS, MacOS and Android) or desktop and dart VM using sqflite_ffi_common.

Choosing an implementation is mainly finding the best IdbFactory for the platform.

Here is a basic example to target both web and mobile

In pubspec.yaml:

dependencies:
  idb_shim: any
  idb_sqflite: any
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:idb_sqflite/idb_sqflite.dart';

late IdbFactory idbFactory;

/// Initialization example for flutter
///
/// It uses indexed_db on the web and sqflite on other platforms
void initIdbFactory() {
  WidgetsFlutterBinding.ensureInitialized();
  if (kIsWeb) {
    idbFactory = idbFactoryWeb;
  } else {
    idbFactory = idbFactorySqflite;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants