Realm schema generation error: The non-abstract class 'PseudoType' is missing implementations

I’m trying to generate a schema from a file with this content;

// file schemas.dart
import 'package:realm/realm.dart';

part 'schemas.g.dart';

@RealmModel()
class _Song {
  late String? songNumber;
  late String? fileName;
  late String? englishTitle;
  late String? year;
  late String? key;
  late String? author;
}

On running flutter pub run realm generate I get the following error message.

flutter pub run realm generate
[INFO] Generating build script...
[INFO] Generating build script completed, took 429ms

[INFO] Precompiling build script......
[WARNING] /C:/<path>/flutter/.pub-cache/hosted/pub.dartlang.org/realm_generator-0.3.1+beta/lib/src/pseudo_type.dart:12:7: Error: The non-abstract class 'PseudoType' is missing implementations for these members:
 - DartType.element2
Try to either
 - provide an implementation,
 - inherit an implementation from a superclass or mixin,
 - mark the class as abstract, or
 - provide a 'noSuchMethod' implementation.

class PseudoType extends TypeImpl {
      ^^^^^^^^^^
/C:/<path>/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-4.6.0/lib/dart/element/type.dart:52:16: Context: 'DartType.element2' is defined here.
  Element? get element2;
               ^^^^^^^^
[INFO] Precompiling build script... completed, took 1.4s

[SEVERE] Failed to precompile build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.

What am I doing wrong?
I know the error message has suggestions on how to solve it. I’ve generated similar models in other projects successful.

I’m on Windows 11 x64, using Flutter 3.0.5 and Realm .0.3.1+beta

I tried the same project on Ubuntu 22.04 x64 and got exactly the same error message.

Hi @Tembo_Nyati,
We have this issue from last Friday. The commands that you run are correct. But there are recently released breaking changes in the packages that we depends on. This problem is already fixed in PR757. We are publishing it as soon as possible.
Will it help you if you download librealm-windows artefact from the last CI run and replace your realm_dart.dll with the new one until we have an official release?
Sorry for the inconvenience.

Here is the full link to librealm-windows

@Desislava_Stefanova, I’m totally OK with this approach, but the problem I’ve just faced is the same error message. I do not know at what time should I do the replace, is it before running 'flutter pub run realm generate` or before. What i did was before.

Yes @Tembo_Nyati , you are right.
Unfortunately, the changes in dart_realm.dll are not enough. The most important changes are in the package and its dependencies.
I suggest you to wait for our published release.
Meanwhile, you can also send your dart model to realm-help@mongodb.com. I can try to generate the realm objects for you.

@Desislava_Stefanova, my dart model is the one in the first post. Here it is, in terms of models I’ve nothing more in this project.

// file schemas.dart
import 'package:realm/realm.dart';

part 'schemas.g.dart';

@RealmModel()
class _Song {
  late String? songNumber;
  late String? fileName;
  late String? englishTitle;
  late String? year;
  late String? key;
  late String? author;
}

@Desislava_Stefanova, I’ve posted in realm-help@mongodb.com as well, thank you.

Amani.

@Tembo_Nyati I answered to your email. Here is the model. Please save it into a file with name schemas.g.dart.

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'schemas.dart';

// **************************************************************************
// RealmObjectGenerator
// **************************************************************************

class Song extends _Song with RealmEntity, RealmObject {
  Song({
    String? songNumber,
    String? fileName,
    String? englishTitle,
    String? year,
    String? key,
    String? author,
  }) {
    RealmObject.set(this, 'songNumber', songNumber);
    RealmObject.set(this, 'fileName', fileName);
    RealmObject.set(this, 'englishTitle', englishTitle);
    RealmObject.set(this, 'year', year);
    RealmObject.set(this, 'key', key);
    RealmObject.set(this, 'author', author);
  }

  Song._();

  @override
  String? get songNumber =>
      RealmObject.get<String>(this, 'songNumber') as String?;
  @override
  set songNumber(String? value) => RealmObject.set(this, 'songNumber', value);

  @override
  String? get fileName => RealmObject.get<String>(this, 'fileName') as String?;
  @override
  set fileName(String? value) => RealmObject.set(this, 'fileName', value);

  @override
  String? get englishTitle =>
      RealmObject.get<String>(this, 'englishTitle') as String?;
  @override
  set englishTitle(String? value) =>
      RealmObject.set(this, 'englishTitle', value);

  @override
  String? get year => RealmObject.get<String>(this, 'year') as String?;
  @override
  set year(String? value) => RealmObject.set(this, 'year', value);

  @override
  String? get key => RealmObject.get<String>(this, 'key') as String?;
  @override
  set key(String? value) => RealmObject.set(this, 'key', value);

  @override
  String? get author => RealmObject.get<String>(this, 'author') as String?;
  @override
  set author(String? value) => RealmObject.set(this, 'author', value);

  @override
  Stream<RealmObjectChanges<Song>> get changes =>
      RealmObject.getChanges<Song>(this);

  static SchemaObject get schema => _schema ??= _initSchema();
  static SchemaObject? _schema;
  static SchemaObject _initSchema() {
    RealmObject.registerFactory(Song._);
    return const SchemaObject(Song, 'Song', [
      SchemaProperty('songNumber', RealmPropertyType.string, optional: true),
      SchemaProperty('fileName', RealmPropertyType.string, optional: true),
      SchemaProperty('englishTitle', RealmPropertyType.string, optional: true),
      SchemaProperty('year', RealmPropertyType.string, optional: true),
      SchemaProperty('key', RealmPropertyType.string, optional: true),
      SchemaProperty('author', RealmPropertyType.string, optional: true),
    ]);
  }
}

I hope it will help.

A workaround (until we release a new version) is to avoid analyzer package version 4.6.0. Add a constraint in your pubspec.yaml like this:

dependencies: 
  analyzer: '>=4.0.0 <4.6.0'
1 Like

I received it, thank you.

@Kasper_Nielsen1, this works as well, thank you so much.

this works, thank you so much.

@Tembo_Nyati , @12_12
The new release is already available:

1 Like