Skip to content

Commit 460277b

Browse files
committed
fix required array in dart serialization
1 parent cdcfb4b commit 460277b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

templates/dart/lib/src/models/model.dart.twig

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,25 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} implements Model
2424
factory {{ definition.name | caseUcfirst | overrideIdentifier}}.fromMap(Map<String, dynamic> map) {
2525
return {{ definition.name | caseUcfirst | overrideIdentifier }}(
2626
{% for property in definition.properties %}
27-
{{ 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 %},
27+
{{ property.name | escapeKeyword }}:{{' '}}
28+
{%- if property.sub_schema -%}
29+
{%- if property.type == 'array' -%}
30+
List<{{property.sub_schema | caseUcfirst | overrideIdentifier}}>.from(map['{{property.name | escapeDollarSign }}'].map((p) => {{property.sub_schema | caseUcfirst | overrideIdentifier}}.fromMap(p)))
31+
{%- else -%}
32+
{{property.sub_schema | caseUcfirst | overrideIdentifier}}.fromMap(map['{{property.name | escapeDollarSign }}'])
33+
{%- endif -%}
34+
{%- else -%}
35+
map['{{property.name | escapeDollarSign }}']
36+
{%- if property.type == "number" -%}
37+
{%- if not property.required %}?{% endif %}.toDouble()
38+
{%- endif -%}
39+
{%- if property.type == "string" -%}
40+
{%- if not property.required %}?{% endif %}.toString()
41+
{%- endif -%}
42+
{%- if property.type == "array" -%}
43+
{% if property.required %} ?? []{% endif %}
44+
{%- endif -%}
45+
{%- endif -%},
2846
{% endfor %}
2947
{% if definition.additionalProperties %}
3048
data: map,

0 commit comments

Comments
 (0)