There are different configuration options that control how
dart_mappable generates code for your
models. Most of the options can be configured on three levels:
- On a Class Level, by using its property on the
- on a Library Level, by using its property on the
- on a Global Level, by defining its options in the
build.yamlfile (as shown further down).
Class level configurations override library level configurations override global configurations.
This package can generate a few different sets of methods, which can be activated or deactivated individually. This makes sure that only code is generated that you actually need. By default, all methods are generated for each class.
You can set the
generateMethods property to specify which methods to generate.
The following methods are supported:
- decode: Will generate
- encode: Will generate
- copy: Will generate
- stringify: Will generate the
- equals: Will generate the
When using annotations, you can specify multiple methods using the bitwise-or operator like this:
@MappableClass(generateMethods: GenerateMethods.copy | GenerateMethods.equals | GenerateMethods.stringify).
You can specify the
caseStyle options for the json keys and the
enumCaseStyle option for your
stringified enum values. Choose one of the existing styles or specify a custom one.
Currently supported are:
||myFieldName (unchanged, default)|
||myFieldName (dart style)|
You can also specify a custom case style using the
custom(ab,c) syntax or
The letters before the comma define how to transform each word of a field name. They can be either
capitalCase. When using only one letter, it is applied to all words. When using two letters, the first one is applied to only the first word and the second one to all remaining words. Respective options
The one letter after the comma defines the separator between each word, like
-. This can be any character or empty. Respective option
Here are some examples that can be achieved using this syntax:
Additionally to using the
@MappableLib() annotations for configuration,
you can also define a subset of their properties as global options in the
global_options: dart_mappable_builder: options: # the case style for the map keys, defaults to 'none' caseStyle: none # or 'camelCase', 'snakeCase', etc. # the case style for stringified enum values, defaults to 'none' enumCaseStyle: none # or 'camelCase', 'snakeCase', etc. # if true removes all map keys with null values ignoreNull: false # or true # used as property name for type discriminators discriminatorKey: type # used to specify which methods to generate (all by default) generateMethods: [decode, encode, copy, stringify, equals]
- Used to transform fields to a specific case style.
- Collection of constants to indicate which methods and extensions to generate for a specific class.
- Used to annotate a class in order to generate mapping code
- Used to annotate a constructor to be chosen as the serialization function.
- Used to annotate a parameter or field to overwrite the mapped key.
- Used to annotate a library to define default values.
- Text transformation applied to a single word.