retrofit.dart icon indicating copy to clipboard operation
retrofit.dart copied to clipboard

@Part(name: 'param') required File? param has compile error

Open dfdgsdfg opened this issue 11 months ago • 3 comments

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,
    ),
  ));
}

dfdgsdfg avatar Mar 06 '24 07:03 dfdgsdfg

Hey there, is this issue fixed fully?

irangareddy avatar Apr 03 '24 16:04 irangareddy

I had this same issue a while back. Can you try changing your request to accept the File as an optional parameter instead?

mihir-kandoi avatar Jun 19 '24 17:06 mihir-kandoi

I have same issue.

htetaunglin avatar Sep 28 '24 16:09 htetaunglin