I'm new to flutter programming and i need to be able to download an excel file from http post request. I have two issues:
- The response in flutter is null whereas in postman it displays something. The details below
The Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
- I dont know how to process that response to actually get the file downloaded in the location specified by the user
Can someone help me please
This is what i have soo far
Dio? http;
BaseOptions options = new BaseOptions(
baseUrl: "****/",
headers: {
'Accept': 'application/json',
'Content-type': 'application/json'
},
responseType: ResponseType.json,
);
http = new Dio(options);
static Future<dynamic> getClientsFile(String sheetName) async {
Directory dir = await getApplicationDocumentsDirectory();
String fileLocation = dir.path + "/" + sheetName + ".xlsx";
return http!
.download(
"clients/exports",
fileLocation,
data: {"sheetName": sheetName, "type": "xlsx"},
options: Options(method: "POST", responseType: ResponseType.bytes),
)
.then((value) => print(value));
}
await ClientController.getClientsFile(sheetName);