diff --git a/generator/lib/src/generator.dart b/generator/lib/src/generator.dart index b3b8a2ca..fa8abf0b 100644 --- a/generator/lib/src/generator.dart +++ b/generator/lib/src/generator.dart @@ -1867,6 +1867,9 @@ ${bodyName.displayName} == null final contentType = r.peek('contentType')?.stringValue; if (isFileField) { + if (p.type.isNullable) { + blocks.add(Code('if (${p.displayName} != null){')); + } final fileNameValue = r.peek('fileName')?.stringValue; final fileName = fileNameValue != null ? literalString(fileNameValue) @@ -1907,6 +1910,9 @@ ${bodyName.displayName} == null } else { blocks.add(returnCode); } + if (p.type.isNullable) { + blocks.add(Code('}')); + } } else if (_displayString(p.type) == 'List') { final optionalFile = m.parameters .firstWhereOrNull((pp) => pp.displayName == p.displayName)