graphql-code-generator-community icon indicating copy to clipboard operation
graphql-code-generator-community copied to clipboard

flutter-freezed plugin is incompatible Freezed (v3). (Minor change required)

Open naedx opened this issue 3 months ago • 2 comments

Is your feature request related to a problem? Please describe.

The upgrade to the Freezed package from v2 to v3 comes with a breaking change in the syntax. Specifically, "Classes using the factory constructor now require a keyword sealed / abstract." (details here)

Describe the solution you'd like

  • Create a new major version of the flutter-freezed plugin that automatically includes sealed/abstract keyword.
  • ~~Create a config flag that allows the user to specify if they want to add sealed/abstract before the class definition based on the version of Freezed they are using~~.

Describe alternatives you've considered

I've done a global replace on the file generated by the plugin add 'abstract' before the 'class' keyword.

So that this:


@freezed
class Report with _$Report {
  const Report._();

  const factory Report({
    required final String name
  }) = _Report;

  factory Report.fromJson(Map<String, dynamic> json) =>
      _$ReportFromJson(json);
}

//...

Becomes:

@freezed
abstract class Report with _$Report {
  const Report._();

  const factory Report({
    required final String name
  }) = _Report;

  factory Report.fromJson(Map<String, dynamic> json) =>
      _$ReportFromJson(json);
}

//...

...and that works as expected.

Additional context

The change to Freezed is described here.


To: @Parables

naedx avatar Aug 21 '25 18:08 naedx

#1130

A PR coming soon

Parables avatar Sep 14 '25 18:09 Parables

Awesome! Thanks for the update, @Parables !

naedx avatar Sep 20 '25 22:09 naedx