Importing Realm Object to another Realm Object of another file

i am learning a flutter realm. i am unable to import a realm object which is in another file

import 'package:realm/realm.dart';

part 'item_type_schemas.g.dart';

/---item_type_schema.dart
@RealmModel()
class _ItemType {
  @MapTo('_id')
  @PrimaryKey()
  late ObjectId id;
  late String name;
  late String description;
  late bool isConsumable;
  late bool isActive;
}

/--item_category_schemas.dart
import 'package:realm/realm.dart';
import '../../item_type/data/item_type_schemas.dart';
part 'item_category_schemas.g.dart';

@RealmModel()
class _ItemCategory {
  @MapTo('_id')
  @PrimaryKey()
  late ObjectId id;
  late String name;
  late String description;
  late _ItemType? itemType;
  late bool isActive;
}
i am unable to import _ItemType. kindly help

Hi @Health_Centre_ERP,
You can use $ instead of _. For example:
class $ItemCategory {
class $ItemType {
Te generator will work with $ and your classes won’t be private.
We usually suggest defining all the realm models in the same file in order to avoid using $ItemType instead of the generated ItemType by mistake while working with the Realm.

1 Like