How to generate adapters for classes in separate files.
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
**Question**
How do I generate adapters for classes in separate files? I'm not clear where I need to put the part lines and where I need to register the adapters. Are all the adapters registered in the `Main()` method? Do I add the `part` lines for all of the class files into the class containing the `Main()` method? I've tried various combinations but the `part` file for CLASS B is not generated.
**Code sample**
**CLASS A**
```dart
import 'package:my_project/class_b.dart';
import 'package:hive/hive.dart';
part 'class_a.g.dart';
part 'class_b.g.dart'; //?????? Target of URI hasn't been generated
...
@HiveType(typeId: 0)
class ClassA {
@HiveField(0)
String string ="";
...
void main(List arguments) async {
var path = "assets/";
Hive
..registerAdapter(ClassAAdapter());
..registerAdapter(ClassBAdapter()); //??? The function 'CLASSBAdapter' isn't defined
...
}
```
**CLASS B**
```
import 'package:hive/hive.dart';
part 'class_b.g.dart'; //???? target of URI hasn't been generated
...
@HiveType(typeId: 1)
class ClassB {
@HiveField(0)
String string ="";
...
```
**Version**
- Platform: iOS, Android, Mac, Windows, Linux, Web
- Dart version: 2.17.5
- Hive version: 2.2.3
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the class A and class B examples in the issue and compare their part declarations with the generated class_a.g.dart and class_b.g.dart files. Verify how Hive adapters are generated and registered in main; done means both adapter files are generated and both adapters can be registered without undefined symbols.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- database
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100