isar / isar/hive

Widget test returns HiveError: The box "orders" is already open and of type Box<Order>.

Open
#1,250 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

I'm trying to write some tests for a widget that uses Hive boxes.
```
void main() {
setUp(() async {
final temp = await Directory.systemTemp.createTemp();
Hive.init(temp.path);
Hive.registerAdapter(OrderAdapter());

await Hive.openBox('userInfo');
await Hive.openBox('orders');
});

tearDown(() async {
await Hive.close();
});

testWidgets('Test the home page', (widgetTester) async {
await widgetTester.pumpWidget(const MaterialApp(
home: Scaffold(
body: StartTab(),
)
));
expect(1, 1);
});
}
```

In `StartTab()`, I have:
```
class StartTab extends StatefulWidget {
const StartTab({super.key});

@override
StartTabState createState() => StartTabState();
}

class StartTabState extends State {
Box orderBox = Hive.box('orders');
Box userInfoBox = Hive.box('userInfo');
```

When I run this test, I keep getting:
**The box "orders" is already open and of type Box\.**

My understanding is this error occurs because I have another box called 'orders' that has a conflicting type somewhere. But I've checked the code in `StartTab()` and `orders` is only defined at the beginning as shown above.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the widget test's setUp and tearDown, then inspect StartTab's box fields and the calls opening "orders" and "userInfo". Reproduce the test and trace Hive's box state; done means the test completes without the reported HiveError and the box setup is consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
database, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.