-
Notifications
You must be signed in to change notification settings - Fork 408
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
Migrate Hive v2 to support Flutter web WASM #1291
base: main
Are you sure you want to change the base?
Conversation
Thank you for your effort! I've been trying to migrate Hive v2 to package:web and have been stuck. I'll be trying your branch very soon and giving you feedback. |
I'm experience a runtime error. Here's the related info
Ran with |
The But that's probably not the issue here. You re-ran the generator right? |
That error seems to imply that the issue is with this line: But that would mean you somehow have a box key that's infinity or NaN which doesn't make any sense. I suppose we could just call |
I did forget to re-ran the generator. The error still shows up. The same code runs well when compiled to main.dart.js without error. Other than using the master channel, I'm not how can I get a useful stack trace. Another exception I'm having is this:
Which may or may not be related. I'm not sure which is the error that's preventing the app to run. I made the change you mentioned, and now I'm getting this error:
Hope it helps a little |
On Flutter stable you need to run |
The hive code has no call to I'm not sure what the second exception is about. Probably just another exception caused by the key that's infinity or NaN. Maybe try this: /// Not part of public API
@visibleForTesting
Future<List<Object?>> getKeys({bool cursor = false}) async {
var store = getStore(false);
if (store.has('getAllKeys') && !cursor) {
final result = await getStore(false).getAllKeys(null).asFuture();
final keys = <Object?>[];
for (final key in (result as JSArray).toDart) {
if (key is JSNumber) {
final keyDart = key.toDartDouble;
if (keyDart.isFinite) {
keys.add(keyDart.toInt());
} else {
print('Box key is not finite: $key');
}
} else if (key is JSString) {
keys.add(key.toDart);
}
}
return keys;
} else {
final cursors = await store.getCursors();
return cursors.map((e) => e.key).toList();
}
} What I'm afraid of is that you will be missing data due to keys not getting read correctly or something. Let me know how many times that print statement gets called. |
Thanks! I tried the
Seemed like there's a bug in the Dart compiler: firebase/flutterfire#12623 It's fixed in the master channel, however I get this error again when I switch to the master channel:
This time it's sentry. I don't think either is related to Hive, but at the moment I'm unable to test out this branch with my app unfortunately. |
Filed this issue: getsentry/sentry-dart#2082 (Not that it's related to Hive. Just for tracking sake) |
Can you take out sentry for now and see if the app runs? Also did you have to edit the getKeys method? |
Yes, I updated the getKeys method with the code you provided. I got rid of Sentry. Now this is the error I'm getting:
|
Can you try/catch your openBox calls and print the error/stacktrace? |
They're already in a try-catch block. Are you sure the error's from the openBox calls? |
@1l0 I wrote tests for BoxCollection and they pass so the original code you showed me should work now |
I did a bunch of cleanup. I also refactored the code that required dart 3.4.0, but the web package requires dart 3.3.0 anyways so not really much of an accomplishment. |
I have confirmed that it just works ™️. Errors are gone. I don't know why but with |
Just tried, it worked! |
Thanks, I overlooked that information. The problem seems to be resolved. |
I have released the following packages to replace Hive in my projects. The intent is to keep these up to date with modern Dart/Flutter standards. I can't promise fixing any issues with Hive itself unless you create PRs. hive_ce Please feel free to create any issues with those packages in their repo: https://github.com/IO-Design-Team/hive_ce |
@Rexios80 You are awesome! starred |
Migrates Hive v2 to support Flutter web WASM since v3 and v4 are major changes (and not stable)
This should not be merged into the main branch, but there isn't a better option right now. This should probalby be merged into a branch created off of the tag
v2.2.3
since that is the commit these changes are based on.IF YOU WANT TO USE THIS NOW
I have released the following packages to replace Hive in my projects. The intent is to keep these up to date with modern Dart/Flutter standards.
hive_ce
hive_ce_flutter
hive_ce_generator
If you do not want to use Hive Community Edition, you can use this PR directly:
Make sure to run the generator after updating
Related issues
#1287
isar/isar#1617
isar/isar#1616