android – how to download file using Flutter with Laravel

0
226


I am trying to download the the excel file from laravel backend through my flutter app. I have used dio package to download that file. but I am getting this error while downloading the app.

[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: DioError [DioErrorType.response]: Http status error [405]
E/flutter (24963): Source stack:

**FLUTTER CODE **

void downloaddd() async {
    String name = "Excel-of-salaries";
    String path = await _getFilePath(name);
    String url =
        "http://10.0.2.2:8000/xxxxxxxxxxxxxx/${widget.masterID}";
    var data = await dio.download(url, path, data: {
      "id": 1,
    });
    print(data);
  }

LARAVEL CODE

class SalaryExportsController extends Controller
{
    public function export(Request $request, $id)
    {
        return Excel::download(new SalaryExports($request, $id), 'users.xlsx');
    }
}

api.php

Route::post('/xxxxxxxxxx/{id}', [SalaryExportsController::class, 'export']);