Skip to content

Commit

Permalink
improving documentation (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
numen31337 authored Aug 5, 2022
1 parent 0e240e3 commit 0a47b1e
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion copy_with_extension_gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final copiedTwo = result.copyWith(id: "foo", text: null) // Results in BasicClas

You can modify multiple fields at once using `copyWith` as a function like so: `myInstance.copyWith(fieldName: "test", anotherField: "test")`. Passing the `null` value to `non-nullable` fields will be ignored.

#### Nullifying instance fields:
#### Nullifying instance fields

In order to nullify the class fields, an additional `copyWithNull` function can be generated. To make use of it, pass an additional parameter to your class annotation `@CopyWith(generateCopyWithNull: true)`.

Expand All @@ -94,6 +94,35 @@ final int myImmutableField;

By adding this annotation you forcing your generated `copyWith` to always copy this field as it is, without exposing it in the function interface.

#### Custom constructor name

Set `constructor` if you want to use a named constructor, e.g. a private one. The generated fields will be derived from this constructor.

```dart
@CopyWith(constructor: "_")
class SimpleObjectPrivateConstructor {
@CopyWithField(immutable: true)
final String? id;
final int? intValue;
const SimpleObjectPrivateConstructor._({this.id, this.intValue});
}
```

#### Skipping generation of `copyWith` functionality for individual fields

Set `skipFields` to prevent the library from generating `copyWith` functions for individual fields e.g. `instance.copyWith.id("123")`. If you want to use only `copyWith(...)` function.

```dart
@CopyWith(skipFields: true)
class SimpleObject {
final String id;
final int? intValue;
const SimpleObject({required this.id, this.intValue});
}
```

## How this library is better than `freezed`?

It isn't. This library is a non-intrusive alternative for those who only need the `copyWith` functionality and do not want to maintain the codebase in the way implied by the framework. This library only requires from your side the annotation of your class with `CopyWith()` and an indication of the `.part` file, everything else is up to you. [`freezed`](https://pub.dev/packages/freezed), on the other hand, offers many more code generation features but requires your models to be written in a framework-specific manner.

0 comments on commit 0a47b1e

Please sign in to comment.