trevorwang / retrofit.dart

retrofit.dart is an dio client generator using source_gen and inspired by Chopper and Retrofit.
https://mings.in/retrofit.dart/
MIT License
1.06k stars 241 forks source link

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

Open dfdgsdfg opened 4 months ago

dfdgsdfg commented 4 months ago

Describe the bug In case multipart with required and nullable with File type, It generate compile error.

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,
    ),
  ));
}
irangareddy commented 3 months ago

Hey there, is this issue fixed fully?

mihir-kandoi commented 1 month ago

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