Search code examples
flutterdartransack

Two keys in a map literal shouldn't be equal. Change or remove the duplicate key


We would like to filter data where the paymentStatus is "Coming Due" and "Overdue" using Ransack, but only get "Overdue" data.

Future<ListResponse?> getData(
      GetParams params) async {
    Map<String, dynamic> commonParams = {
            ....
      "q[payment_status_in][]": "Coming Due",
      "q[payment_status_in][]": "Overdue"
    };

    Response response = await Dio()
        .get('$kBaseUrl/xxx', queryParameters: commonParams);

    var res = ListResponse.fromJson(response.data);

    if (res.status != true) {
      throw ServerException(res.errorMessage![0]);
    }

    return res;
  }

Here the warning message:

Two keys in a map literal shouldn't be equal. Change or remove the duplicate key


Solution

  • Why are there duplicate keys on the map? The last value will obviously replace the previous one with the same key. If you want to send a list as query parameters, try

    "q[payment_status_in]": ["Coming Due", "Overdue"]