Unable to add header for post method in dio in Flutter

Dio library key working perfectly fine in my case if we pass small case key value For example, Dio dio = new Dio(); dio.options.headers[‘content-Type’] = ‘application/json’; dio.options.headers[“authorization”] = “token ${token}”; response = await dio.post(url, data: data); make sure you write key in small case, that’s work for me.

Flutter Dio : How to Upload Image?

In Dio latest version, UploadFileInfo method has been replaced by MultipartFile class. And here the way how to use to post image, video or any file: Future<String> uploadImage(File file) async { String fileName = file.path.split(“https://stackoverflow.com/”).last; FormData formData = FormData.fromMap({ “file”: await MultipartFile.fromFile(file.path, filename:fileName), }); response = await dio.post(“/info”, data: formData); return response.data[‘id’]; }