Skip to content

Commit

Permalink
Merge pull request #751 from appwrite/fix-dart-models-nullable-list
Browse files Browse the repository at this point in the history
fix required array in dart serialization
  • Loading branch information
lohanidamodar authored Jan 24, 2024
2 parents 0aa6747 + 460277b commit f875c96
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion templates/dart/lib/src/models/model.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,25 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} implements Model
factory {{ definition.name | caseUcfirst | overrideIdentifier}}.fromMap(Map<String, dynamic> map) {
return {{ definition.name | caseUcfirst | overrideIdentifier }}(
{% for property in definition.properties %}
{{ property.name | escapeKeyword }}: {% if property.sub_schema %}{% if property.type == 'array' %}List<{{property.sub_schema | caseUcfirst | overrideIdentifier}}>.from(map['{{property.name | escapeDollarSign }}'].map((p) => {{property.sub_schema | caseUcfirst | overrideIdentifier}}.fromMap(p))){% else %}{{property.sub_schema | caseUcfirst | overrideIdentifier}}.fromMap(map['{{property.name | escapeDollarSign }}']){% endif %}{% else %}map['{{property.name | escapeDollarSign }}']{% if property.type == "number" %}{% if not property.required %}?{% endif %}.toDouble(){% endif %}{% if property.type == "string" %}{% if not property.required %}?{% endif %}.toString(){% endif %}{% endif %},
{{ property.name | escapeKeyword }}:{{' '}}
{%- if property.sub_schema -%}
{%- if property.type == 'array' -%}
List<{{property.sub_schema | caseUcfirst | overrideIdentifier}}>.from(map['{{property.name | escapeDollarSign }}'].map((p) => {{property.sub_schema | caseUcfirst | overrideIdentifier}}.fromMap(p)))
{%- else -%}
{{property.sub_schema | caseUcfirst | overrideIdentifier}}.fromMap(map['{{property.name | escapeDollarSign }}'])
{%- endif -%}
{%- else -%}
map['{{property.name | escapeDollarSign }}']
{%- if property.type == "number" -%}
{%- if not property.required %}?{% endif %}.toDouble()
{%- endif -%}
{%- if property.type == "string" -%}
{%- if not property.required %}?{% endif %}.toString()
{%- endif -%}
{%- if property.type == "array" -%}
{% if property.required %} ?? []{% endif %}
{%- endif -%}
{%- endif -%},
{% endfor %}
{% if definition.additionalProperties %}
data: map,
Expand Down

0 comments on commit f875c96

Please sign in to comment.