isar / isar/hive

HiveError: The box "boxName" is already open and of type Box<BoxType>

Open
#237 4 comments 3 reactions 1 assignee Claimed by @simc View on GitHub
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

**Steps to Reproduce**
I`ve created custom adapter ArticleAdapter.
But have 2 issues:

1. When i try to register with `Hive.registerAdapter(ArticleAdapter())`, i receive an error
> The argument type 'ArticleAdapter' can't be assigned to the parameter type 'TypeAdapter'. (argument_type_not_assignable at [eton_news_test] lib/core/services/hive_service.dart:24)
So the only way is working is to write `Hive.registerAdapter(ArticleAdapterAdapter())
`

2. When i try to access to read data from the box by
```
static Article loadArticle(String id) {
Box box = Hive.box (BoxNames.ARTICLES_BOX);
return box.get(id);
}
```
I receive an error:

> Unhandled Exception: HiveError: The box "articlesbox" is already open and of type Box.

**Code sample**
```
import 'package:eton_news_test/core/domains/articles/author.dart';
import 'package:eton_news_test/core/domains/domains.dart';
import 'package:hive/hive.dart';

part 'article_adapter.g.dart';

@HiveType(typeId: 0)
class ArticleAdapter {
@HiveField(0)
String authorId;
@HiveField(1)
Author author;
@HiveField(2)
DateTime createdAt;
@HiveField(3)
String id;
@HiveField(4)
List likes;
@HiveField(5)
List content;
@HiveField(6)
MobileTextBlock mainContent;
@HiveField(7)
MobileMediaBlock mainMedia;
@HiveField(8)
MobileMediaBlock mainMediaPreview;
@HiveField(9)
MobileTextBlock subtitle;
@HiveField(10)
MobileTextBlock title;
@HiveField(11)
String ownerId;
@HiveField(12)
String projectId;
@HiveField(13)
bool rtl;
@HiveField(14)
String language;
}
```

**Version**
- Platform: iOS, Android, Mac, Windows, Linux, Web
- Flutter version: [e.g. 1.5.4]
- Hive version: [e.g. 0.5.0]

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.