Skip to content

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

@naedx

Description

@naedx

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions