zorphy library
Zorphy - Modern code generation for Dart/Flutter
This library provides a complete solution for generating boilerplate code like copyWith, JSON serialization, equality, toString, and more.
Classes
-
AlwaysMatch<
TEntity> - A filter that always evaluates to true.
-
And<
TEntity> - Logical AND combining multiple filters
-
Contains<
TEntity, TValue> - Contains filter (e.g., for strings or lists)
- EntityConfig
- Configuration for entity creation
- EntityCreator
- Main orchestrator for creating Zorphy entities
- EntityResult
- Result of entity creation
- EnumConfig
- Configuration for enum creation
- EnumResult
- Result of enum creation
-
Eq<
TEntity, TValue> - Equality filter (e.g., field == value)
-
Field<
TEntity, TValue> -
Represents a field in a Zorphy entity
TEntitywith value typeTValue. Used for type-safe query construction and runtime evaluation. - FieldDefinition
- Field definition for an entity
-
Filter<
TEntity> - Base class for all filters
-
Gt<
TEntity, TValue> - Greater than filter
-
Gte<
TEntity, TValue> - Greater than or equal filter
- Immutable
- Used to annotate a class.
-
InList<
TEntity, TValue> - In list filter
-
JsonConverter<
T, S> - Implement this class to provide custom converters for a specific Type.
- JsonEnum
-
Allows configuration of how
enumelements are treated as JSON. - JsonKey
- An annotation used to specify how a field is serialized.
- JsonLiteral
- An annotation used to generate a private field containing the contents of a JSON file.
- JsonSerializable
- An annotation used to specify a class to generate code for.
- JsonValue
- An annotation used to specify how a enum value is serialized.
-
List_E<
E> - Enhanced List type for Zorphy with additional functionality
-
Lt<
TEntity, TValue> - Less than filter
-
Lte<
TEntity, TValue> - Less than or equal filter
- NamingUtils
- Utility class for naming conventions
-
Neq<
TEntity, TValue> - Not equal filter (e.g., field != value)
-
NoOpPatch<
T> - Represents a patch that makes no changes
-
Opt<
T> - Optional type wrapper for Zorphy
-
Or<
TEntity> - Logical OR combining multiple filters
-
Patch<
T> - Patch interface for Zorphy code generation
-
PatchBase<
T> - Base class for patch operations in Zorphy
- RecordUse
- Annotates a static method to be recorded.
- Required
-
Used to annotate a named parameter
pin a method or functionf. -
Sort<
TEntity> - Represents a sort operation on a field
- SubtypeResult
- Result for subtype generation
- UseResult
- See useResult for more details.
- Zorphy
- Zorphy2
- ZorphyGenerator
- Generates Zorphy code from @Zorphy annotated classes.
- ZorphyX
Enums
- FieldRename
- Values for the automatic field renaming behavior for JsonSerializable.
Extensions
-
FieldOps
on Field<
TEntity, TValue> - Extension methods for easier filter creation
-
FieldSortOps
on Field<
TEntity, TValue> - Extension methods for sorting on fields
-
NullableStringFieldOps
on Field<
TEntity, String?> - OptExtension on T
- Extension to allow calling opt() on any value
-
StringFieldOps
on Field<
TEntity, String> -
ZorphyQueryIterableExt
on Iterable<
T> - Extension methods for in-memory querying of iterables
Constants
- alwaysThrows → const _AlwaysThrows
-
Used to annotate a function
f. Indicates thatfalways throws an exception. Any functions that overridef, in class inheritance, are also expected to conform to this contract. - awaitNotRequired → const _AwaitNotRequired
-
Used to annotate a Future-returning function (including constructors,
getters, methods, and operators), or a Future-typed field (including
top-level, instance, and static)
f. Indicates that the Future value thatfreturns does not need to be awaited. Any methods that overridefin class inheritance, are also expected to conform to this contract. - checked → const _Checked
- Used to annotate a parameter of an instance method that overrides another method.
- doNotStore → const _DoNotStore
-
Used to annotate a method, getter, top-level function, or top-level getter
to indicate that the value obtained by invoking it should not be stored in a
field or top-level variable. The annotation can also be applied to a class
to implicitly annotate all of the valid members of the class, or applied to
a library to annotate all of the valid members of the library, including
classes. If a value returned by an element marked as
doNotStoreis returned from a function or getter, that function or getter should be similarly annotated. - doNotSubmit → const _DoNotSubmit
- Used to annotate an optional parameter, method, getter or top-level getter or function that is not intended to be accessed in checked-in code, but might be ephemerally used during development or local testing.
- experimental → const _Experimental
- Used to annotate a library, or any declaration that is part of the public interface of a library (such as top-level members, class members, and function parameters) to indicate that the annotated API is experimental and may be removed or changed at any-time without updating the version of the containing package, despite the fact that it would otherwise be a breaking change.
- factory → const _Factory
-
Used to annotate an instance or static method
m. Indicates thatmmust either be abstract or must return a newly allocated object ornull. In addition, every method that either implements or overridesmis implicitly annotated with this same annotation. - immutable → const Immutable
-
Used to annotate a class
C. Indicates thatCand all subtypes ofCmust be immutable. - internal → const _Internal
- Used to annotate a declaration which should only be used from within the package in which it is declared, and which should not be exposed from said package's public API.
- isTest → const _IsTest
- Used to annotate a test framework function that runs a single test.
- isTestGroup → const _IsTestGroup
- Used to annotate a test framework function that runs a group of tests.
- literal → const _Literal
-
Used to annotate a const constructor
c. Indicates that any invocation of the constructor must use the keywordconstunless one or more of the arguments to the constructor is not a compile-time constant. - mustBeConst → const _MustBeConst
- Used to annotate a parameter which should be constant.
- mustBeOverridden → const _MustBeOverridden
-
Used to annotate an instance member
mdeclared on a class or mixinC. Indicates that every concrete subclass ofCmust directly overridem. - mustCallSuper → const _MustCallSuper
-
Used to annotate an instance member (method, getter, setter, operator, or
field)
m. Indicates that every invocation of a member that overridesmmust also invokem. In addition, every method that overridesmis implicitly annotated with this same annotation. - nonVirtual → const _NonVirtual
-
Used to annotate an instance member (method, getter, setter, operator, or
field)
min a classCor mixinM. Indicates thatmshould not be overridden in any classes that extend or mixinCorM. - optionalTypeArgs → const _OptionalTypeArgs
-
Used to annotate a class, mixin, extension, function, method, or typedef
declaration
C. Indicates that any type arguments declared onCare to be treated as optional. - protected → const _Protected
- Used to annotate an instance member in a class or mixin which is meant to be visible only within the declaring library, and to other instance members of the class or mixin, and their subtypes.
- redeclare → const _Redeclare
- Used to annotate an instance member of an extension type that redeclares a member from a superinterface.
- reopen → const _Reopen
-
Annotation for intentionally loosening restrictions on subtyping that would
otherwise cause lint warnings to be produced by the
implicit_reopenlint. - required → const Required
-
Used to annotate a named parameter
pin a method or functionf. Indicates that every invocation offmust include an argument corresponding top, despite the fact thatpwould otherwise be an optional parameter. - sealed → const _Sealed
- Annotation marking a class as not allowed as a super-type outside of the current package.
- useResult → const UseResult
- Used to annotate a method, field, or getter within a class, mixin, or extension, or a or top-level getter, variable or function to indicate that the value obtained by invoking it should be used. A value is considered used if it is assigned to a variable, passed to a function, or used as the target of an invocation, or invoked (if the result is itself a function).
- virtual → const _Virtual
- Used to annotate a field that is allowed to be overridden in Strong Mode.
- visibleForOverriding → const _VisibleForOverriding
- Used to annotate an instance member that was made public so that it could be overridden but that is not intended to be referenced from outside the defining library.
- visibleForTesting → const _VisibleForTesting
- Used to annotate a declaration that was made public, so that it is more visible than otherwise necessary, to make code testable.
- zorphy → const Zorphy
- normal class; prepend class with a single dollar & make abstract
- zorphy2 → const Zorphy2
- Zorphy2 will be created before Zorphy, sometimes the generator needs a related class to be built before another.
Functions
-
$checkedConvert<
T> (Map map, String key, T castFunc(dynamic), {Object? readValue(Map, String)?}) → T -
Helper function used in generated code when
JsonSerializableGenerator.checkedistrue. -
$checkedCreate<
T> (String className, Map map, T constructor(S < S>(String, S (Object?), {Object? readValue(Map, String)?}) ), {Map<String, String> fieldKeyMap = const {}}) → T -
Helper function used in generated code when
JsonSerializableGenerator.checkedistrue. -
$checkedNew<
T> (String className, Map map, T constructor(), {Map< String, String> ? fieldKeyMap}) → T -
Helper function used in generated code when
JsonSerializableGenerator.checkedistrue. -
$checkKeys(
Map map, {List< String> ? allowedKeys, List<String> ? requiredKeys, List<String> ? disallowNullValues}) → void -
Helper function used in generated
fromJsoncode whenJsonSerializable.disallowUnrecognizedKeysis true for an annotated type orJsonKey.requiredistruefor any annotated fields. -
$enumDecode<
K extends Enum, V> (Map< K, V> enumValues, Object? source, {K? unknownValue}) → K -
Returns the key associated with value
sourcefromenumValues, if one exists. -
$enumDecodeNullable<
K extends Enum, V> (Map< K, V> enumValues, Object? source, {Enum? unknownValue}) → K? -
Returns the key associated with value
sourcefromenumValues, if one exists. -
getFromJsonToGenericFn(
Map< List< fns, Map<String> , dynamic Function(Map<String, dynamic> )>String, dynamic> json, List<String> genericType) → dynamic - Resolves the matching fromJson function for the provided generic type ids.
-
getGenericToJsonFn(
Map< Type, Object? Function(Never)> fns, Type type) → Object? Function(Never) -
Resolves a generic toJson function for the provided
type. -
hashObjects(
Iterable objects) → int -
Generates a hash code for multiple
objects.
Exceptions / Errors
- BadKeyException
- A base class for exceptions thrown when decoding JSON.
- CheckedFromJsonException
-
Exception thrown if there is a runtime exception in
fromJsoncode generated whenJsonSerializableGenerator.checkedistrue - DisallowedNullValueException
-
Exception thrown if there are keys with disallowed
nullvalues in a JSON map that was provided during deserialization. - MissingRequiredKeysException
- Exception thrown if there are missing required keys in a JSON map that was provided during deserialization.
- UnrecognizedKeysException
- Exception thrown if there are unrecognized keys in a JSON map that was provided during deserialization.