yoohoo
yoohoo

Reputation: 1217

passing parameter to object box query

I am new to object box. I am struggling on finding a way to pass parameters to my query. i looked at the documentation but still struggling.

this is my code

late Stream<List<dynamic>> _stream;

_stream =  _Mystore
        .box<Income>()
        .query()
        .watch(triggerImmediately: true)
        .map((query) => query.find());

return StreamBuilder<List<dynamic>>(
      stream: _stream,
      builder: (context, snapshot) {
        final activeIncomes = snapshot.data;

        if (!snapshot.hasData || activeIncomes!.length == 0) {
          return  Align(
              alignment: Alignment.center,
              child: noData()
          );
        }
        return itemList(activeIncomes!);
      },
    );

the above query will get all the rows from entity Income. however, i want to filter the rows by passing parameters value. I tried the following but didnt work

late Stream<List<dynamic>> _stream;

_stream =  _Mystore
        .box<Income>()
        .query()
        .watch(triggerImmediately: true)
        .map((query) => query.param.(Income_.monthNumber.equals(6))find());


i added param.(Income_.monthNumber.equals(6) to query but i get error. The argument type 'Condition' can't be assigned to the parameter type 'QueryProperty<dynamic, dynamic>'.

can someone help me and show me how to add parameters to query in objectbox so that i can use that query with my stream?

thanks

Upvotes: 0

Views: 215

Answers (1)

Uwe - ObjectBox
Uwe - ObjectBox

Reputation: 1327

Pass conditions to the query() method. Using your example:

box().query(Income_.monthNumber.equals(6))

Source: https://docs.objectbox.io/queries

Upvotes: 1

Related Questions