Not able to generate RealmModel on MacOS 14.1.1

Hi,

I was trying to create a simple data model in Flutter (MacOS 14.1.1) and run the ‘dart run realm generate’ command following the .guide

Below is the output that I receive where it shows that it succeeded, however it does not generate the SampleItem.g.dart file. I have also tried ‘dart run realm generate --clean’ and ‘dart run build_runner build --delete-conflicting-outputs’. However, it has a similar output where it shows a success message but no file gets generated. Any help in this regard would be highly appreciated.

Building package executable…
Built realm:realm.
[INFO] Generating build script…
[INFO] Generating build script completed, took 225ms

[INFO] Precompiling build script…
[INFO] Precompiling build script… completed, took 4.4s

[INFO] Setting up file watchers…
[INFO] Setting up file watchers completed, took 7ms

[INFO] Waiting for all file watchers to be ready…
[INFO] Waiting for all file watchers to be ready completed, took 199ms

[INFO] Initializing inputs
[INFO] Building new asset graph…
[INFO] Building new asset graph completed, took 852ms

[INFO] Checking for unexpected pre-existing outputs…
[INFO] Checking for unexpected pre-existing outputs. completed, took 0ms

[INFO] Running build…
[INFO] realm:realm_generator on lib/src/sample_feature/SampleItem.dart:[generate (0)] completed, took 22ms
[INFO] 1.9s elapsed, 11/24 actions completed.
[INFO] 8.2s elapsed, 25/37 actions completed.
[INFO] realm:realm_generator on lib/src/settings/settings_controller.dart:[generate (0)] completed, took 88ms
[INFO] realm:realm_generator on lib/src/sample_feature/sample_item_list_view.dart:[generate (0)] completed, took 72ms
[INFO] realm:realm_generator on lib/src/settings/settings_view.dart:[generate (0)] completed, took 93ms
[INFO] realm:realm_generator on lib/src/settings/settings_service.dart:[generate (0)] completed, took 65ms
[INFO] realm:realm_generator on lib/src/sample_feature/sample_item_details_view.dart:[generate (0)] completed, took 66ms
[INFO] realm:realm_generator on lib/main.dart:[generate (0)] completed, took 24ms
[INFO] realm:realm_generator on lib/src/app.dart:[generate (0)] completed, took 9ms
[INFO] realm:realm_generator on test/unit_test.dart:[generate (0)] completed, took 8ms
[INFO] realm:realm_generator on test/widget_test.dart:[generate (0)] completed, took 3ms
[WARNING] source_gen:combining_builder on test/widget_test.dart:
widget_test.g.dart must be included as a part directive in the input library with:
part ‘widget_test.g.dart’;
[WARNING] source_gen:combining_builder on lib/src/settings/settings_service.dart:
settings_service.g.dart must be included as a part directive in the input library with:
part ‘settings_service.g.dart’;
[WARNING] source_gen:combining_builder on test/unit_test.dart:
unit_test.g.dart must be included as a part directive in the input library with:
part ‘unit_test.g.dart’;
[WARNING] source_gen:combining_builder on lib/src/settings/settings_view.dart:
settings_view.g.dart must be included as a part directive in the input library with:
part ‘settings_view.g.dart’;
[WARNING] source_gen:combining_builder on lib/main.dart:
main.g.dart must be included as a part directive in the input library with:
part ‘main.g.dart’;
[WARNING] source_gen:combining_builder on lib/src/settings/settings_controller.dart:
settings_controller.g.dart must be included as a part directive in the input library with:
part ‘settings_controller.g.dart’;
[WARNING] source_gen:combining_builder on lib/src/app.dart:
app.g.dart must be included as a part directive in the input library with:
part ‘app.g.dart’;
[WARNING] source_gen:combining_builder on lib/src/sample_feature/sample_item_list_view.dart:
sample_item_list_view.g.dart must be included as a part directive in the input library with:
part ‘sample_item_list_view.g.dart’;
[WARNING] source_gen:combining_builder on lib/src/sample_feature/sample_item_details_view.dart:
sample_item_details_view.g.dart must be included as a part directive in the input library with:
part ‘sample_item_details_view.g.dart’;
[WARNING] source_gen:combining_builder on lib/src/sample_feature/SampleItem.dart:
SampleItem.g.dart must be included as a part directive in the input library with:
part ‘SampleItem.g.dart’;
[INFO] Running build completed, took 9.7s

[INFO] Caching finalized dependency graph…
[INFO] Caching finalized dependency graph completed, took 40ms

[INFO] Succeeded after 9.8s with 56 outputs (76 actions)

Below is the output of the flutter pub deps:

Dart SDK 3.2.0
Flutter SDK 3.16.0
realm_testing 1.0.0+1
├── build_runner 2.4.7
│ ├── analyzer 6.2.0
│ │ ├── _fe_analyzer_shared 64.0.0
│ │ │ └── meta…
│ │ ├── convert 3.1.1
│ │ │ └── typed_data…
│ │ ├── collection…
│ │ ├── crypto…
│ │ ├── glob…
│ │ ├── meta…
│ │ ├── package_config…
│ │ ├── path…
│ │ ├── pub_semver…
│ │ ├── source_span…
│ │ ├── watcher…
│ │ └── yaml…
│ ├── async 2.11.0
│ │ ├── collection…
│ │ └── meta…
│ ├── build 2.4.1
│ │ ├── analyzer…
│ │ ├── async…
│ │ ├── convert…
│ │ ├── crypto…
│ │ ├── glob…
│ │ ├── logging…
│ │ ├── meta…
│ │ ├── package_config…
│ │ └── path…
│ ├── build_config 1.1.1
│ │ ├── checked_yaml…
│ │ ├── json_annotation…
│ │ ├── path…
│ │ ├── pubspec_parse…
│ │ └── yaml…
│ ├── build_daemon 4.0.1
│ │ ├── built_collection 5.1.1
│ │ ├── built_value 8.8.0
│ │ │ ├── fixnum 1.1.0
│ │ │ ├── built_collection…
│ │ │ ├── collection…
│ │ │ └── meta…
│ │ ├── crypto…
│ │ ├── http_multi_server…
│ │ ├── logging…
│ │ ├── path…
│ │ ├── pool…
│ │ ├── shelf…
│ │ ├── shelf_web_socket…
│ │ ├── stream_transform…
│ │ ├── watcher…
│ │ └── web_socket_channel…
│ ├── build_resolvers 2.4.1
│ │ ├── analyzer…
│ │ ├── async…
│ │ ├── build…
│ │ ├── collection…
│ │ ├── convert…
│ │ ├── crypto…
│ │ ├── graphs…
│ │ ├── logging…
│ │ ├── package_config…
│ │ ├── path…
│ │ ├── pool…
│ │ ├── pub_semver…
│ │ ├── stream_transform…
│ │ └── yaml…
│ ├── build_runner_core 7.2.11
│ │ ├── async…
│ │ ├── build…
│ │ ├── build_config…
│ │ ├── build_resolvers…
│ │ ├── collection…
│ │ ├── convert…
│ │ ├── crypto…
│ │ ├── glob…
│ │ ├── graphs…
│ │ ├── json_annotation…
│ │ ├── logging…
│ │ ├── meta…
│ │ ├── package_config…
│ │ ├── path…
│ │ ├── pool…
│ │ ├── timing…
│ │ ├── watcher…
│ │ └── yaml…
│ ├── code_builder 4.8.0
│ │ ├── built_collection…
│ │ ├── built_value…
│ │ ├── collection…
│ │ ├── matcher…
│ │ └── meta…
│ ├── dart_style 2.3.4
│ │ ├── analyzer…
│ │ ├── args…
│ │ ├── collection…
│ │ ├── path…
│ │ ├── pub_semver…
│ │ └── source_span…
│ ├── frontend_server_client 3.2.0
│ │ ├── async…
│ │ └── path…
│ ├── glob 2.1.2
│ │ ├── file 7.0.0
│ │ │ ├── meta…
│ │ │ └── path…
│ │ ├── async…
│ │ ├── collection…
│ │ ├── path…
│ │ └── string_scanner…
│ ├── graphs 2.3.1
│ │ └── collection…
│ ├── http_multi_server 3.2.1
│ │ └── async…
│ ├── io 1.0.4
│ │ ├── meta…
│ │ ├── path…
│ │ └── string_scanner…
│ ├── js 0.6.7
│ │ └── meta…
│ ├── mime 1.0.4
│ ├── pool 1.5.1
│ │ ├── async…
│ │ └── stack_trace…
│ ├── shelf 1.4.1
│ │ ├── async…
│ │ ├── collection…
│ │ ├── http_parser…
│ │ ├── path…
│ │ ├── stack_trace…
│ │ └── stream_channel…
│ ├── shelf_web_socket 1.0.4
│ │ ├── shelf…
│ │ ├── stream_channel…
│ │ └── web_socket_channel…
│ ├── stack_trace 1.11.1
│ │ └── path…
│ ├── stream_transform 2.1.0
│ ├── timing 1.0.1
│ │ └── json_annotation…
│ ├── watcher 1.1.0
│ │ ├── async…
│ │ └── path…
│ ├── web_socket_channel 2.4.0
│ │ ├── async…
│ │ ├── crypto…
│ │ └── stream_channel…
│ ├── yaml 3.1.2
│ │ ├── collection…
│ │ ├── source_span…
│ │ └── string_scanner…
│ ├── args…
│ ├── collection…
│ ├── crypto…
│ ├── logging…
│ ├── meta…
│ ├── package_config…
│ ├── path…
│ ├── pub_semver…
│ └── pubspec_parse…
├── flutter 0.0.0
│ ├── characters 1.3.0
│ ├── collection 1.18.0
│ ├── material_color_utilities 0.5.0
│ │ └── collection…
│ ├── meta 1.10.0
│ ├── sky_engine 0.0.99
│ ├── vector_math 2.1.4
│ └── web 0.3.0
├── flutter_localizations 0.0.0
│ ├── clock 1.1.1
│ ├── intl 0.18.1
│ │ ├── clock…
│ │ ├── meta…
│ │ └── path…
│ ├── path 1.8.3
│ ├── characters…
│ ├── collection…
│ ├── flutter…
│ ├── material_color_utilities…
│ ├── meta…
│ ├── vector_math…
│ └── web…
├── flutter_test 0.0.0
│ ├── boolean_selector 2.1.1
│ │ ├── source_span…
│ │ └── string_scanner…
│ ├── fake_async 1.3.1
│ │ ├── clock…
│ │ └── collection…
│ ├── matcher 0.12.16
│ │ ├── async…
│ │ ├── meta…
│ │ ├── stack_trace…
│ │ ├── term_glyph…
│ │ └── test_api…
│ ├── source_span 1.10.0
│ │ ├── collection…
│ │ ├── path…
│ │ └── term_glyph…
│ ├── stream_channel 2.1.2
│ │ └── async…
│ ├── string_scanner 1.2.0
│ │ └── source_span…
│ ├── term_glyph 1.2.1
│ ├── test_api 0.6.1
│ │ ├── async…
│ │ ├── boolean_selector…
│ │ ├── collection…
│ │ ├── meta…
│ │ ├── source_span…
│ │ ├── stack_trace…
│ │ ├── stream_channel…
│ │ ├── string_scanner…
│ │ └── term_glyph…
│ ├── async…
│ ├── characters…
│ ├── clock…
│ ├── collection…
│ ├── flutter…
│ ├── material_color_utilities…
│ ├── meta…
│ ├── path…
│ ├── stack_trace…
│ ├── vector_math…
│ └── web…
└── realm 1.6.1
├── args 2.4.2
├── build_cli_annotations 2.1.0
│ ├── args…
│ └── meta…
├── cancellation_token 2.0.1
│ ├── collection…
│ └── meta…
├── crypto 3.0.3
│ └── typed_data 1.3.2
│ └── collection…
├── ffi 2.1.0
├── http 1.1.2
│ ├── http_parser 4.0.2
│ │ ├── collection…
│ │ ├── source_span…
│ │ ├── string_scanner…
│ │ └── typed_data…
│ ├── async…
│ ├── meta…
│ └── web…
├── json_annotation 4.8.1
│ └── meta…
├── logging 1.2.0
├── package_config 2.1.0
│ └── path…
├── pub_semver 2.1.4
│ ├── collection…
│ └── meta…
├── pubspec_parse 1.2.3
│ ├── checked_yaml 2.0.3
│ │ ├── json_annotation…
│ │ ├── source_span…
│ │ └── yaml…
│ ├── collection…
│ ├── json_annotation…
│ ├── pub_semver…
│ └── yaml…
├── realm_common 1.6.1
│ ├── objectid 3.0.0
│ └── sane_uuid 1.0.0-alpha.5
│ ├── crypto…
│ └── meta…
├── realm_generator 1.6.1
│ ├── source_gen 1.4.0
│ │ ├── analyzer…
│ │ ├── async…
│ │ ├── build…
│ │ ├── dart_style…
│ │ ├── glob…
│ │ ├── path…
│ │ ├── source_span…
│ │ └── yaml…
│ ├── analyzer…
│ ├── build…
│ ├── build_resolvers…
│ ├── dart_style…
│ ├── realm_common…
│ └── source_span…
├── tar 1.0.2
│ ├── async…
│ ├── meta…
│ └── typed_data…
├── build_runner…
├── collection…
├── flutter…
├── meta…
└── path…

Per the warnings, you’ll need to add

part 'class_name.g.dart'; 

To class_name.dart.

Edit: actually, those files don’t appear to be model files. Can you post your models?

Appreciate the quick response! I was trying Realm for the first time. So the data model is a very simple one. This is the only model I’m using and the only place where the annotation for @RealmModel() has been applied. SampleItem.g.dart file does not get generated. I tried putting part ‘SampleItem.g.dart’ but it shows the lint error that

Target of URI hasn't been generated: 'package:realm_testing/src/sample_feature/SampleItem.g.dart'.
Try running the generator that will generate the file referenced by the URI.
@RealmModel()
class _$SampleItem {
  late int id;
}

Ah, I see. Yes, you do need to add part 'SampleItem.g.dart'; and then run the generator. It’ll create the part and the lint warning will go away.

For some reason, the generator does not create the part file/SampleItem.g.dart, that’s the issue I’m facing.

Can you upload your project?

Really appreciate with the help. It seems like adding the part ‘SampleItem.g.dart’ helped. So used to the hot restart feature in flutter that I did not save the model file before running the generator. Once I saved it and ran the generator again, it finally worked!

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.