Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rrousselGit committed Mar 2, 2025
1 parent c260f68 commit 82b26ca
Showing 1 changed file with 1 addition and 45 deletions.
46 changes: 1 addition & 45 deletions packages/freezed/migration_guide.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Migration Guide

## Migrate from v2 to v3

### Require keyword (`sealed` / `abstract`)
### Require keyword (`sealed` / `abstract`)

Classes using the factory constructor now require a keyword `sealed` / `abstract`.

Expand Down Expand Up @@ -47,45 +45,3 @@ final model = Model.first('42');
+};

```


### Classic classes (new)

Instead of primary constructors, you can write normal Dart classes.

In this scenario, write a typical constructor + fields combo as you normally would:

```dart
import 'package:freezed_annotation/freezed_annotation.dart';
// required: associates our `main.dart` with the code generated by Freezed
part 'main.freezed.dart';
// optional: Since our Person class is serializable, we must add this line.
// But if Person was not serializable, we could skip it.
part 'main.g.dart';
@freezed
@JsonSerializable() // needed for class serialization
class Person with _$Person {
const Person({
required this.firstName,
required this.lastName,
required this.age,
});
final String firstName;
final String lastName;
final int age;
factory Person.fromJson(Map<String, Object?> json)
=> _$PersonFromJson(json);
Map<String, Object?> toJson() => _$PersonToJson(this);
}
```

In this scenario, Freezed will generate `copyWith`/`toString`/`==`/`hashCode`,
but won't do anything related to JSON encoding (hence why you need to manually add `@JsonSerializable`).

This syntax has the benefit of enabling advanced constructor logic, such as
inheritance or non-constant default values.

0 comments on commit 82b26ca

Please sign in to comment.