[dart-gen] Fix lists containing atomic types (#3210)

This commit is contained in:
fondoger 2023-05-09 05:00:46 +08:00 committed by GitHub
parent 1853428011
commit c22bc1c8ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -45,8 +45,10 @@ class {{.Name}} {
return {{.Name}}(
{{range .Members}}
{{lowCamelCase .Name}}: {{appendNullCoalescing .}}
{{if isDirectType .Type.Name}}
{{if isAtomicType .Type.Name}}
m['{{getPropertyFromMember .}}'] {{appendDefaultEmptyValue .Type.Name}}
{{else if isAtomicListType .Type.Name}}
m['{{getPropertyFromMember .}}']?.cast<{{getCoreType .Type.Name}}>() {{appendDefaultEmptyValue .Type.Name}}
{{else if isClassListType .Type.Name}}
((m['{{getPropertyFromMember .}}'] {{appendDefaultEmptyValue .Type.Name}}) as List<dynamic>).map((i) => {{getCoreType .Type.Name}}.fromJson(i)).toList()
{{else}}

View File

@ -71,7 +71,11 @@ func isListType(s string) bool {
}
func isClassListType(s string) bool {
return strings.HasPrefix(s, "List<") && !isAtomicType(getCoreType(s))
return isListType(s) && !isAtomicType(getCoreType(s))
}
func isAtomicListType(s string) bool {
return isListType(s) && isAtomicType(getCoreType(s))
}
func isListItemsNullable(s string) bool {

View File

@ -6,8 +6,10 @@ var funcMap = template.FuncMap{
"getBaseName": getBaseName,
"getPropertyFromMember": getPropertyFromMember,
"isDirectType": isDirectType,
"isAtomicType": isAtomicType,
"isNumberType": isNumberType,
"isClassListType": isClassListType,
"isAtomicListType": isAtomicListType,
"isListItemsNullable": isListItemsNullable,
"isNullableType": isNullableType,
"appendNullCoalescing": appendNullCoalescing,