-
Notifications
You must be signed in to change notification settings - Fork 189
Flutter Response Model with Refactored SDK #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TorstenDittmann
merged 11 commits into
appwrite:master
from
lohanidamodar:feat-refactored-response-model
Sep 23, 2021
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d29f61d
response definitions
lohanidamodar 051196c
Merge branch 'master' into feat-refactored-response-model
lohanidamodar 5f595a4
re-arrange
lohanidamodar 1287610
Merge branch 'master' into feat-refactored-response-model
lohanidamodar 97487ac
fix test responses
lohanidamodar f7468b8
more meaningful replace
lohanidamodar b1f621b
upgrade flutter web auth
lohanidamodar e55150b
upgrade dependencies
lohanidamodar 7cf5282
fixing hardcoded stuff
lohanidamodar c9d27ee
remove late modifier
lohanidamodar 31943db
Merge branch 'master' into feat-refactored-response-model
lohanidamodar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| library {{ language.params.packageName }}.models; | ||
|
|
||
| {% for definition in spec.definitions %} | ||
| part 'src/models/{{definition.name | caseSnake}}.dart'; | ||
| {% endfor %} |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| {% macro sub_schema(property) %}{% if property.sub_schema %}{% if property.type == 'array' %}List<{{property.sub_schema | caseUcfirst}}>{% else %}{{property.sub_schema | caseUcfirst}}{% endif %}{% else %}{{property.type | typeName}}{% endif %}{% endmacro %} | ||
| part of {{ language.params.packageName }}.models; | ||
|
|
||
| class {{ definition.name | caseUcfirst }} { | ||
| {% for property in definition.properties %} | ||
| final {% if not property.required %}{{_self.sub_schema(property)}}? {{ property.name | escapeKeyword }}{% else %}{{_self.sub_schema(property)}} {{ property.name | escapeKeyword }}{% endif %}; | ||
| {% endfor %} | ||
| {% if definition.additionalProperties %} | ||
| final Map<String, dynamic> data; | ||
| {% endif %} | ||
|
|
||
| {{ definition.name | caseUcfirst}}({ | ||
| {% for property in definition.properties %}{% if property.required %} | ||
| required {% endif %}this.{{ property.name | escapeKeyword }}, | ||
| {% endfor %} | ||
| {% if definition.additionalProperties %} | ||
| required this.data, | ||
| {% endif %} | ||
| }); | ||
|
|
||
| factory {{ definition.name | caseUcfirst}}.fromMap(Map<String, dynamic> map) { | ||
| return {{ definition.name | caseUcfirst }}( | ||
| {% for property in definition.properties %} | ||
| {{ property.name | escapeKeyword }}: {% if property.sub_schema %}{% if property.type == 'array' %}List<{{property.sub_schema | caseUcfirst}}>.from(map['{{property.name | escapeDollarSign }}'].map((p) => {{property.sub_schema | caseUcfirst}}.fromMap(p))){% else %}{{property.sub_schema | caseUcfirst}}.fromMap(map['{{property.name | escapeDollarSign }}']){% endif %}{% else %}map['{{property.name | escapeDollarSign }}']{% if property.type == "number" %}.toDouble(){% endif %}{% endif %}, | ||
| {% endfor %} | ||
| {% if definition.additionalProperties %} | ||
| data: map, | ||
| {% endif %} | ||
| ); | ||
| } | ||
|
|
||
| Map<String, dynamic> toMap() { | ||
| return { | ||
| {% for property in definition.properties %} | ||
| "{{ property.name | escapeDollarSign }}": {% if property.sub_schema %}{% if property.type == 'array' %}{{property.name | escapeKeyword}}.map((p) => p.toMap()){% else %}{{property.name | escapeKeyword}}.toMap(){% endif %}{% else %}{{property.name | escapeKeyword }}{% endif %}, | ||
| {% endfor %} | ||
| {% if definition.additionalProperties %} | ||
| "data": data, | ||
| {% endif %} | ||
| }; | ||
| } | ||
| {% if definition.additionalProperties %} | ||
|
|
||
| T convertTo<T>(T Function(Map) fromJson) => fromJson(data); | ||
| {% endif %} | ||
| {% for property in definition.properties %} | ||
| {% if property.sub_schema %} | ||
| {% for def in spec.definitions %} | ||
| {% if def.name == property.sub_schema and def.additionalProperties and property.type == 'array' %} | ||
|
|
||
| List<T> convertTo<T>(T Function(Map) fromJson) => | ||
| {{property.name}}.map((d) => d.convertTo<T>(fromJson)).toList(); | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% endif %} | ||
| {% endfor %} | ||
| } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to delay at both the start and end of the test?