Hi,
First off, thanks for this fantastic package! I just replaced both Shared Preferences and Secure Storage with Hive and am thrilled to have a single solution. Well done!
The issue in question is happening during my integration testing (using flutter_driver), which at this point is just a simple test to login to my app. Prior to Hive, this worked fine. After Hive, it now breaks with a seemingly unrelated error. Because of the unhelpful error, it took me a while to track it down.
Steps to Reproduce
I've created a minimal reproduction in this repo: https://github.com/jamesdixon/hive_flutter_driver_issue
flutter drive --target=test_driver/run_app.dartResult (on Emulators):
DriverError: Error in Flutter application: Uncaught extension error while executing tap: 'package:flutter_driver/src/extension/extension.dart': Failed assertion: line 193 pos 14: 'WidgetsBinding.instance.isRootWidgetAttached || !command.requiresRootWidgetAttached': No root widget is attached; have you remembered to call runApp()?
Result (on physical iPhone):
[VERBOSE-2:shell.cc(178)] Dart Error: Unhandled exception:
FileSystemException: writeFrom failed, path = '' (OS Error: Input/output error, errno = 5)
Next, comment out line 12 of main.dart where we use Hive to open a box.
Run the test command again and the result will be that all tests pass on both emulators and devices.
I'm not sure if this is a Flutter Driver error or a Hive error but figured I'd take a shot and post it here first :)
Version
Thanks that you took the time to file this issue.
I think the problem is that you open a box in the main method.
Running the app will be delayed for a split second and Flutter Driver does not seem to like that.
You should use a FutureBuilder to open a box. Here you can find an example.
I agree that Flutter Driver doesn't like it but FutureBuilder isn't an option for me as in my real application, I initialize a service layer at startup and one of those services is a LocalStorageService that's using Hive.
Theoretically, since main is async, I would expect Flutter Driver to respect that and wait for it to finish initializing but it appears that isn't the case. I'll file an issue in the main Flutter repo and report back.
Thanks!
@leisim I went ahead an opened an issue in the Flutter repo as I don't think this is Hive-specific after doing more testing.