-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 4.0: copyWith(...) function nullability support (#43)
* basic implementation * minor * prevent unnecessary copyWithNull methods generation * naming corrections * naming + ignore cast_nullable_to_non_nullable * docs + test fixes * docs * docs * release
- Loading branch information
1 parent
526d702
commit f977405
Showing
19 changed files
with
207 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,33 @@ | ||
/// Provides annotation class to use with | ||
/// [copy_with_extension_gen](https://pub.dev/packages/copy_with_extension_gen). | ||
/// Provides `CopyWith` annotation class used by [copy_with_extension_gen](https://pub.dev/packages/copy_with_extension_gen). | ||
library copy_with_extension; | ||
|
||
/// Annotation used to indicate that the `copyWith` extension should be generated. | ||
class CopyWith { | ||
const CopyWith({ | ||
this.copyWithNull = false, | ||
this.skipFields = false, | ||
this.namedConstructor, | ||
this.constructor, | ||
}); | ||
|
||
/// Set `copyWithNull` to `true` if you want to use `copyWithNull` function that allows you to nullify the fields. E.g. `myInstance.copyWithNull(id: true, name: true)`. Otherwise it will be still generated for internal use but marked as private. | ||
/// Set `copyWithNull` to `true` if you want to use `copyWithNull` function that allows you to nullify the fields. E.g. `myInstance.copyWithNull(id: true, name: true)`. | ||
final bool copyWithNull; | ||
|
||
/// Prevent the library from generating copyWith function for individual filelds. If you want to use only copyWith(...) function. | ||
/// Prevent the library from generating `copyWith` functions for individual filelds e.g. `instance.copyWith.id("123")`. If you want to use only copyWith(...) function. | ||
final bool skipFields; | ||
|
||
/// Set `namedConstructor` if you want to use a named constructor instead. The generated fields will be derived from this constructor. | ||
final String? namedConstructor; | ||
/// Set `constructor` if you want to use a named constructor. The generated fields will be derived from this constructor. | ||
final String? constructor; | ||
} | ||
|
||
/// Additional field related options for the `CopyWith`. | ||
class CopyWithField { | ||
const CopyWithField({this.immutable = false}); | ||
|
||
/// Indicates that the field should be hidden in the generated `copyWith` method. By setting this flag to `true` the field will always be copied as it is e.g. `userID` field. | ||
/// Indicates that the field should be hidden in the generated `copyWith` method. By setting this flag to `true` the field will always be copied as it and excluded from `copyWith` interface. | ||
final bool immutable; | ||
} | ||
|
||
/// This placeholder object is a default value for nullable fields to handle cases when the user wants to nullify the value. | ||
class $CopyWithPlaceholder { | ||
const $CopyWithPlaceholder(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.