objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
927 stars 115 forks source link

error trying to pass two or more parameters to a query #551

Closed rodriger06 closed 8 months ago

rodriger06 commented 9 months ago

hi,

I have a query in objectbox that takes two parameters. here is my code

  Query<Income> getGroupIncomeList() {
    return incomeBox.query(Income_.id.greaterThan(0) & Income_.groupId.equals(0)).build();
  }

i am calling my function as

 final query= _myService.myVariable.getGroupIncomeList();
      final queryResult = (query..param(Income_.Id).value =  6 , query..param(Income_.groupId).value =  123);
      List<Income> incomes = queryResult.find();

where _myservice.myvariable is a reference to objectbox flutter which then call my function. i am getting error in line List incomes = queryResult.find();

The method 'find' isn't defined for the type '<unknown>'. (Documentation)  Try correcting the name to the name of an existing method, or defining a method named 'find'.

if i remove one parameter from the function so that i looks like this

      final queryResult = ( query..param(Income_.groupId).value =  123);

then the error goes away. I want to be able to pass two or more parameters to my query. how can i do this? can someone provide sample code? the documentation doesnt say anything about passing two or more parameters.

greenrobot-team commented 9 months ago

The double dot notation (..) is a special Dart syntax called a cascade.

Try something like:

query
  ..param(Income_.Id).value =  6
  ..param(Income_.groupId).value =  123;

Or do not use the cascade syntax and just call the methods separately:

query.param(Income_.Id).value =  6;
query.param(Income_.groupId).value =  123;
github-actions[bot] commented 8 months ago

Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue.