Closed rodriger06 closed 2 years ago
You can pass an empty string to the query and assign it an alias when building the query. Then in main.dart, you will only need to pass the alias every time you want to use a different parameter value. Have a look at this part of the ObjectBox Queries docs for more details.
Hi all, i am new to objectbox. I have an issue trying to pass parameters to object box. I am using the example located in https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/lib/objectbox.dart
in the objecbox.dart, there is a query such as final qBuilder = noteBox.query() ..order(Note_.date, flags: Order.descending); queryStream = qBuilder.watch(triggerImmediately: true);
i was trying to modify the query so that I can pass parameters to objectbox.dart and be used in the query above. I can see that the main class is calling the objectbox.dart as:
/// Provides access to the ObjectBox Store throughout the app. late ObjectBox objectbox;
Future main() async {
// This is required so ObjectBox can get the application directory
// to store the database in.
WidgetsFlutterBinding.ensureInitialized();
objectbox = await ObjectBox.create();
runApp(const MyApp()); }
I want to pass two parameters. one is an integer and the other parameters is a string. throughout my modified version of this example, i want to keep passing different values to the parameters and query the data based on the parameters which will serve as filters.
can someone show me how to modify the existing class in this example https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/lib/objectbox.dart so that I can pass parameters of integer and strings to be used in the query inside objectbox.dart
final qBuilder = noteBox.query() ..order(Note_.date, flags: Order.descending); queryStream = qBuilder.watch(triggerImmediately: true);
https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/lib/main.dart https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/lib/objectbox.dart
thanks in advance