Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several Documentation Examples Contain Errors or Are Outdated #1190

Closed
danielkiing3 opened this issue Mar 2, 2025 · 1 comment
Closed

Several Documentation Examples Contain Errors or Are Outdated #1190

danielkiing3 opened this issue Mar 2, 2025 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation needs triage

Comments

@danielkiing3
Copy link

I came across several examples in the Freezed documentation that do not work as expected, likely due to changes in Freezed's generated code. These examples either cause constructor errors, missing required arguments, or improper subclass behavior

I believe these examples need to be updated or clarified to match the latest Freezed version.

Steps to Reproduce

Here are some examples from the documentation that fail and the errors they produce:

Example 1: Non-empty private constructor (Response example)

@freezed
sealed class Response<T> with _$Response<T> {
  // We give "time" parameters a non-constant default
  Response._({DateTime? time}) : time = time ?? DateTime.now();
  // Constructors may enable passing parameters to ._();
  factory Response.data(T value, {DateTime? time}) = ResponseData;
  // If ._ parameters are named and optional, factory constructors are not required to specify it
  factory Response.error(Object error) = ResponseError;

  @override
  final DateTime time;
}

Error:

1 positional argument expected by '_', but 0 found.
Try adding the missing argument.

Example 2: MyFreezedClass

class Subclass {
  Subclass.name(this.value);
  final int value;
}

@freezed
class MyFreezedClass extends Subclass with _$MyFreezedClass {
  // We can receive parameters in this constructor, which we can use with `super.field`
  MyFreezedClass._(super.value) : super.name();

  factory MyFreezedClass(int value /* other fields */) = _MyFreezedClass;
}

Code generation just doesn't work at all

Environment

Freezed Version: 3.0.2 and 2.5.8
Dart Version: 3.7.0
Flutter Version: 3.29.0

@danielkiing3 danielkiing3 added documentation Improvements or additions to documentation needs triage labels Mar 2, 2025
@rrousselGit
Copy link
Owner

Thanks! There's already an issue/PR about it though, so I'll close this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation needs triage
Projects
None yet
Development

No branches or pull requests

2 participants