retrofit.dart
retrofit.dart copied to clipboard
@Part(name: 'param') required File? param has compile error
Describe the bug In case multipart with required and nullable with File type, It generate compile error.
-
@Part(name: 'param') required File? param
- Compile Error: Property 'path' cannot be accessed on 'File?' because it is potentially null.
Errors occur only with the File type.
// @Part(name: 'param') required File? param
// g.dart
_data.files.add(MapEntry(
'param',
MultipartFile.fromFileSync(
portraitImage.path, // Compile Error: Property 'path' cannot be accessed on 'File?' because it is potentially null.
filename: param.path.split(Platform.pathSeparator).last,
),
));
// @Part(name: 'param') File? param
// g.dart
if (param != null) {
_data.files.add(MapEntry(
'param',
MultipartFile.fromFileSync(
portraitImage.path,
filename: param.path.split(Platform.pathSeparator).last,
),
));
}
Hey there, is this issue fixed fully?
I had this same issue a while back. Can you try changing your request to accept the File
as an optional parameter instead?
I have same issue.