flutter: Hive error :There is already a TypeAdapter for typeId 0
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
I am using hive for my project. for creating model I used freezed .these are my models:
@freezed
class VocabularyModel with _$VocabularyModel {
@HiveType(typeId: 0, adapterName: 'VocabularyModelAdaptor')
const factory VocabularyModel({
@HiveField(0) List? phonetics,
@HiveField(1) List? meanings,
@HiveField(2) Configs? configs,
}) = _VocabularyModel;
@freezed
class Phonetics with _$Phonetics {
@HiveType(typeId: 1, adapterName: 'PhoneticsAdaptor')
...
@freezed
class Meanings with _$Meanings {
@HiveType(typeId: 2, adapterName: 'MeaningsAdaptor')
...
@freezed
@JsonSerializable(includeIfNull: false)
class Definitions with _$Definitions {
@HiveType(typeId: 3, adapterName: 'DefinitionsAdaptor')
...
@freezed
class Configs with _$Configs {
@HiveType(typeId: 4, adapterName: 'ConfigsAdaptor')
...
and I initialized Hive and there adapters like this:
Hive
..registerAdapter(VocabularyModelAdaptor())
..registerAdapter(PhoneticsAdaptor())
..registerAdapter(MeaningsAdaptor())
..registerAdapter(DefinitionsAdaptor())
..registerAdapter(ConfigsAdaptor())
..registerAdapter(UserModelAdaptor());
But When I launch the application I to this error:
E/flutter ( 6373): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: HiveError: There is already a TypeAdapter for typeId 0.
E/flutter ( 6373): #0 TypeRegistryImpl.registerAdapter
package:hive/…/registry/type_registry_impl.dart:112
E/flutter ( 6373): #1 HiveService.init
I just one class with `typeId 0` s why I got this error ?
flutter doctor
```
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.1, on macOS 12.4 21F79 darwin-arm, locale en-AM)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc3)
[!] Xcode - develop for iOS and macOS (Xcode 13.4.1)
! CocoaPods 1.10.0 out of date (1.11.0 is recommended).
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.1)
[✓] VS Code (version 1.68.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
! Doctor found issues in 1 category.
```
I am using :
```
hive: ^2.2.1
hive_flutter: ^1.1.0
```
Contributor guide
No contributing guide indexed for this repository
Research direction
The stack trace points to HiveService.init; begin by checking the adapter registrations and initialization path shown in the report. Reproduce the duplicate typeId 0 error and verify what registration state causes it, then document a confirmed resolution or the project change needed to prevent the error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100