Skip to content

Commit c7f35a4

Browse files
authored
fix: added code generatrion logic for multipart datetime (#874)
1 parent 6949876 commit c7f35a4

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

generator/lib/src/generator.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,15 +3221,20 @@ MultipartFile.fromFileSync(i.path,
32213221
final ele = p.type.element! as ClassElement;
32223222
if (_missingToJson(ele)) {
32233223
if (_isDateTime(p.type)) {
3224-
final expr = [
3225-
if (p.type.nullabilitySuffix == NullabilitySuffix.question)
3226-
refer(
3227-
p.displayName,
3228-
).nullSafeProperty('toIso8601String').call([])
3229-
else
3230-
refer(p.displayName).property('toIso8601String').call([]),
3231-
];
3232-
refer(dataVar).property('fields').property('add').call(expr);
3224+
if (p.type.nullabilitySuffix == NullabilitySuffix.question) {
3225+
blocks.add(Code('if (${p.displayName} != null) {'));
3226+
}
3227+
blocks.add(
3228+
refer(dataVar).property('fields').property('add').call([
3229+
refer('MapEntry').newInstance([
3230+
literal(fieldName),
3231+
refer(p.displayName).property('toIso8601String').call([]),
3232+
]),
3233+
]).statement,
3234+
);
3235+
if (p.type.nullabilitySuffix == NullabilitySuffix.question) {
3236+
blocks.add(const Code('}'));
3237+
}
32333238
} else {
32343239
throw Exception('toJson() method have to add to ${p.type}');
32353240
}

0 commit comments

Comments
 (0)