Freezed: Integration with flutter `builders` in pubspec.yaml

Created on 17 Apr 2020  Â·  4Comments  Â·  Source: rrousselGit/freezed

Hi there. Thanks for this library. It's great.

I am curious if you know how to get this set up to automatically run the codegen builder in when flutter hot-reloads happen. I tried following this documentation but the files are never being generated.

I have this in my pubspec.yaml:

builders:
  freezed: ^0.10.1

And I have no build.yaml file. It's my understanding that I should only need that builders entry since freezed ships with a build.yaml, correct?

I'm basing this approach on this documentation for functional_widget https://github.com/rrousselGit/functional_widget/blob/30581a3698cb47d65f55a4f96765ed763e6622e2/README.md#install-builder

Thank you for any help you can provide.

bug question

Most helpful comment

@rrousselGit you are correct, there's nothing you need to do as a builder author, its a setting that Flutter users can choose but its known to be currently broken 😞
so I think this issue can be closed.

All 4 comments

Note: I have been able to use freezed just fine with build_runner via the CLI, but I'm interested in seeing if I can get the flutter-suggested builders approach working instead.

to make this easier to investigate, i created an example app, here https://github.com/samandmoore/freezedgen-example

and here's the error i see when running flutter run

generating build script...                                         29.5s
starting build daemon...                                            1.0s
Launching lib/main.dart on iPhone 11 Pro Max in debug mode...
starting build daemon...

Compiler message:
org-dartlang-app:/main.dart:4:6: Error: Error when reading 'org-dartlang-app:/main.freezed.dart': File not found
part 'main.freezed.dart';
     ^
org-dartlang-app:/main.dart:4:6: Error: Can't use 'org-dartlang-app:/main.freezed.dart' as a part, because it has no 'part of' declaration.
part 'main.freezed.dart';
     ^
org-dartlang-app:/main.dart:7:27: Error: Type '_$Thing' not found.
abstract class Thing with _$Thing {
                          ^^^^^^^
org-dartlang-app:/main.dart:7:16: Error: The type '_$Thing' can't be mixed in.
abstract class Thing with _$Thing {
               ^
org-dartlang-app:/main.dart:8:35: Error: Couldn't find constructor '_Initial'.
  const factory Thing.initial() = _Initial;
                                  ^
org-dartlang-app:/main.dart:8:35: Error: Redirection constructor target not found: '_Initial'
  const factory Thing.initial() = _Initial;
                                  ^
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
Failed to build bundle.
Error launching application on iPhone 11 Pro Max.

I'm not quite sure what to do here.

From my understanding, it is more the tooling that is unreliable than the generator that have a bug.
The generator configuration is standard

@rrousselGit you are correct, there's nothing you need to do as a builder author, its a setting that Flutter users can choose but its known to be currently broken 😞
so I think this issue can be closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matiasosuna picture matiasosuna  Â·  4Comments

freezed picture freezed  Â·  4Comments

pblinux picture pblinux  Â·  4Comments

agordeev picture agordeev  Â·  4Comments

rakakhrl picture rakakhrl  Â·  6Comments