I want to upload an image from flutter to the server but I am failed. I tried with http package but it not worked. Then i found dio package useful and easy but I am getting following error when I use FormData.
the name 'FormData' is defined in the libraries 'package:dio/src/form_data.dart (via package:dio/dio.dart)' and 'package:get/get_connect/http/src/multipart/form_data.dart'. Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.
code
static createNewSupervisor(String name, String email, String address,
String site, String mobileNumber, String password, File? image) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var token = prefs.getString("token");
var dio = Dio();
var fd = FormData.fromMap({
"full_name": name,
"address": address,
"mobile_no": mobileNumber,
"email": email,
"site_name": site,
"password": password,
// "image": baseimage,
});
var response = await dio.post("$baseURL/api/create",
data: fd,
options: Options(headers: {
'Authorization': 'Bearer $token',
} // set content-length
));
print(response);
}