'How to Create Searchable Field or Searchable Dropdown in Flutter with Api?

I have to Create Searchable Field or Searchable Dropdown which search the data from api based on criteria.

Here is API to search data.

http://143.110.248.5:20080/api/v1/staff/search?s=criteria

This is my Function for get the data.

static const String API_GET_STAFF = "staff/search?";

Future<Staff?> getStaffDetails(String staff) async {
    User userData = DataManager.instance.getUser();
    Map<String, String> headers = {"Authorization": userData.authToken!};
    Map<String, String> params = {
      "s=": staff,
    };
    var req = RestRequest(reqUrl: API_GET_STAFF)
      ..reqMethod = RequestMethod.METHOD_GET
      ..header = headers
      ..params = params;

    Response res = await req.dioSend();

    return Staff.fromHashMap(res.data!["dataList"]);
  }

above function returns

Response ({"responseCode":406,"responseMessage":"Please provide search criteria!","data":null,"dataList":null,"excelDataList":null,"totalRecords":0,"pageRecords":0,"currentPageNumber":0,"totalPages":0})

and if i pass data in API_GET_STAFF api like below.

static const String API_GET_STAFF = "staff/search?s=dhaval";

its return proper response.

So here is my two problem.

First is the Response. and Second is How to Create Searchable Field or Searchable Dropdown for this api?



Solution 1:[1]

I believe this needs to be without the =

Map<String, String> params = {
  "s=": staff,
};

so like

Map<String, String> params = {
  "s": staff,
};

And your other question I think is too broad.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ivo Beckers