retrofit.dart
retrofit.dart copied to clipboard
Can't use both body() and Part() in the same api call
Describe the bug Hi guys, I've been trying to send a request with form data fields that contains an image file.. I ended up with incorrect dart generated file.
Reproduce Steps to reproduce the behavior:
1- Have this model that contains several properties:

2- The abstracted retrofit method:

3- The current generated file:

Expected behavior It should create a FormData variable in which we can add the model properties and the image file too
Screenshots

Retrofit and Dio Versions
dependencies:
dio: ^4.0.4
retrofit: ^3.0.1
dev_dependencies:
build_runner: ^2.0.0
retrofit_generator: ^3.0.1+1
Flutter Versions
[✓] Flutter (Channel stable, 2.10.2, on macOS 12.0.1 21A559 darwin-x64, locale en-IQ)
• Flutter version 2.10.2 at /Users/apple/Library/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 097d3313d8 (4 weeks ago), 2022-02-18 19:33:08 -0600
• Engine revision a83ed0e5e3
• Dart version 2.16.1
• DevTools version 2.9.2
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/apple/Library/Android/sdk
• Platform android-31, build-tools 31.0.0
• ANDROID_HOME = /Users/apple/.android
• ANDROID_SDK_ROOT = /Users/apple/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
[✓] VS Code (version 1.65.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.36.0
[✓] Connected device (3 available)
• iPad Pro (12.9-inch) (5th generation) (mobile) • E0AC40C8-C54E-4DA5-B674-462FA8047FEC • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS 12.0.1 21A559 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 99.0.4844.51
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Desktop (please complete the following information):
- OS: MacOs
- Browser: Chrome
- Version: 12
Smartphone (please complete the following information):
- Device: iPad Pro 12.9 inch
- OS: iOS
- Browser Chrome
- Version 15.4
@devmuaz Any luck? I am also facing the same issue.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
+1
Do it like this:
@Multipart()
@POST("/doctos/update")
Future<HttpResponse
It'll work
Is this solved?
any updates?
@devmuaz
It's by design. Body is used to submit plain text data like JSON.
Please use each filed in UpdateDoctorRequest with an @Part annotation here.
Hello @trevorwang
it doesn't work

it should generate something like this
final _data = FormData.fromMap(
body.toJson(),
);
It should be each field with a @part annotation .
{
@part String id,
@part File file,
@part String name,
}
feel free to reopen it if issue still exists.