### Installation Directory Setup Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo_relations/windows/CMakeLists.txt Configures installation directories for the application bundle, ensuring support files are placed correctly next to the executable. ```cmake # === Installation === # Support files are copied into place next to the executable, so that it can # run in place. This is done instead of making a separate bundle (as on Linux) # so that building and running from within Visual Studio will work. set(BUILD_BUNDLE_DIR "$") # Make the "install" step default, as it's required to run. set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Installation Configuration Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/many_to_many/linux/CMakeLists.txt Configures the installation process, setting the install prefix to a bundle directory and ensuring a clean build bundle on each installation. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/linux/CMakeLists.txt Sets the minimum CMake version and project name for the application. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) ``` -------------------------------- ### Define Installation Directories Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/windows/CMakeLists.txt Defines the destination directories for installing application data and libraries relative to the installation prefix. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Installation Configuration Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo_relations/linux/CMakeLists.txt Configures the installation process, setting the install prefix to a bundle directory and defining locations for data and libraries. It also handles installing the executable, ICU data, Flutter library, and bundled plugin libraries. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) # Copy the native assets provided by the build.dart from all packages. set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) # Fully re-copy the assets directory on each build to avoid having stale files ``` -------------------------------- ### Setup ObjectBox Dart Tests Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox_test/README.md Install dependencies and generate code before running tests. ```bash dart pub get dart run build_runner build ``` -------------------------------- ### Setup SyncClient for Multi-Device Data Synchronization Source: https://context7.com/objectbox/objectbox-dart/llms.txt Configures and starts a SyncClient to synchronize data across devices. Requires server URLs and credentials. Monitors connection, login, and data change events. ```dart import 'package:objectbox/objectbox.dart'; void setupSync(Store store) { if (!Sync.isAvailable()) { print('Sync not available in this build'); return; } final client = SyncClient( store, ['wss://sync.example.com:9999'], // WebSocket URL(s) [SyncCredentials.sharedSecretString('my-secret')], // Or use JWT: SyncCredentials.jwtIdToken(token) // Or: SyncCredentials.userAndPassword('user', 'pass') ); // React to connection state changes client.connectionEvents.listen((event) { print('Connection: $event'); // connected / disconnected }); client.loginEvents.listen((event) { if (event == SyncLoginEvent.loggedIn) print('Sync active'); if (event == SyncLoginEvent.credentialsRejected) print('Auth failed'); }); // React to incoming data changes client.changeEvents.listen((List changes) { for (final change in changes) { print('Entity ${change.entity}: ' '${change.puts.length} puts, ${change.removals.length} removals'); } }); client.start(); // initiate connection // Manual control // client.requestUpdates(subscribeForFuturePushes: true); // client.stop(); // client.close(); // fully release resources } ``` -------------------------------- ### Define Installation Directories Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/linux/CMakeLists.txt Defines the destination directories for data and libraries within the installation bundle. This organizes the installed application files. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Install Application Target and Files Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/linux/CMakeLists.txt Installs the application executable, ICU data, Flutter library, and bundled plugin libraries to their respective destinations within the installation bundle. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Configure Installation Prefix Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/linux/CMakeLists.txt Sets the installation prefix to a bundle directory within the build directory. This ensures the application is installed as a relocatable bundle. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Install Application Executable Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/windows/CMakeLists.txt Installs the main application executable to the runtime destination. This makes the executable available after the build process. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Recreate Example Platform Files Source: https://github.com/objectbox/objectbox-dart/blob/main/dev-doc/updating-examples.md After switching the SDK, delete platform-specific directories and certain configuration files within an example's directory. Then, recreate these files using `flutter create`. ```shell flutter create --platforms=android,ios,linux,macos,windows . ``` -------------------------------- ### Install Flutter Dependencies Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/README.md Run this command in your project directory to download and install all necessary Flutter packages. ```bash flutter pub get ``` -------------------------------- ### Installation Rules for Windows Executable Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/many_to_many/windows/CMakeLists.txt Configures the installation process for the application on Windows, ensuring runtime files are placed correctly next to the executable for in-place execution and Visual Studio compatibility. ```cmake # === Installation === # Support files are copied into place next to the executable, so that it can # run in place. This is done instead of making a separate bundle (as on Linux) # so that building and running from within Visual Studio will work. set(BUILD_BUNDLE_DIR "$") # Make the "install" step default, as it's required to run. set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) # Install the AOT library on non-Debug builds only. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/event_manager/linux/CMakeLists.txt Installs Flutter assets by removing the existing directory and then copying the new one. This is part of the runtime component installation. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Initialize ObjectBox Project Source: https://github.com/objectbox/objectbox-dart/blob/main/README.md Run this command after cloning the repository to generate code and prepare the project for development. Ensure you have the necessary build tools installed. ```bash ./tool/init.sh ``` -------------------------------- ### Installation Rules for Windows Executable Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/event_manager/windows/CMakeLists.txt Configures installation rules for the Windows build, ensuring support files are placed next to the executable for in-place running. It sets the installation prefix and defines directories for data and libraries. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Installing Application Target and Assets Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/many_to_many/linux/CMakeLists.txt Installs the application executable, ICU data, Flutter library, bundled plugin libraries, and assets to their respective destinations within the installation bundle. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Download ObjectBox Sync Library for Unit Tests Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/README.md Append the --sync argument to the install script to download the ObjectBox Sync variant for unit tests. ```bash bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-dart/main/install.sh) --sync ``` -------------------------------- ### Run Flutter Project Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/README.md Start the Flutter application on your connected device or emulator using this command. ```bash flutter run ``` -------------------------------- ### Install Application Bundle Components Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/event_manager/linux/CMakeLists.txt Defines installation rules for the application bundle, including the executable, ICU data, Flutter library, and bundled plugin libraries. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Install Flutter Library Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/windows/CMakeLists.txt Installs the main Flutter library file to the library directory. This is a core component for running Flutter applications. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Configure Installation Prefix for Windows Bundles Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/windows/CMakeLists.txt Sets the installation prefix to be next to the executable for Windows builds. This allows the application to run directly from the build directory without needing a separate bundle. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Install Flutter Assets and AOT Library Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/event_manager/windows/CMakeLists.txt Installs Flutter assets by recursively copying the directory and installs the AOT library for Profile and Release builds. It ensures assets are up-to-date by removing the old directory before copying. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Install Native Assets Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/linux/CMakeLists.txt Installs native assets provided by build.dart from all packages into the installation bundle's library directory. This ensures all necessary native components are included. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/many_to_many/linux/CMakeLists.txt Sets the minimum CMake version and project name. It also defines the executable name and application ID. Modern CMake behaviors are explicitly enabled. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "many_to_many") set(APPLICATION_ID "com.example.many_to_many") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Install AOT Library Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo_relations/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the data directory, but only for Profile and Release builds. ```cmake # Install the AOT library on non-Debug builds only. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Troubleshooting Dynamic Library Load Error Source: https://github.com/objectbox/objectbox-dart/blob/main/generator/integration-tests/README.md If you encounter 'Failed to load dynamic library 'lib/objectbox.dll'', ensure that 'objectbox-c' is installed globally or within the tested directory. Run the provided install script if necessary. ```bash ../../../install.sh ``` -------------------------------- ### Clean Build Bundle Directory on Install Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/linux/CMakeLists.txt Removes the build bundle directory before installation to ensure a clean state. This is part of the installation process. ```cmake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/windows/CMakeLists.txt Installs any bundled native libraries required by plugins to the library directory. This ensures plugins have their dependencies available at runtime. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Native Assets Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/windows/CMakeLists.txt Copies native assets provided by the build.dart script into the installation directory. These assets are typically required for the application to function correctly. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install AOT Library Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library for Release and Profile builds. This is used for performance optimization in non-debug configurations. ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### SyncClient Source: https://context7.com/objectbox/objectbox-dart/llms.txt Connect to an ObjectBox Sync Server to keep data in sync across devices. Create the `SyncClient` with server URLs and credentials, then call `start()`. Monitor state via `connectionEvents`, `loginEvents`, `completionEvents`, and `changeEvents` streams. ```APIDOC ## SyncClient — multi-device data synchronization Connect to an ObjectBox Sync Server to keep data in sync across devices. Create the `SyncClient` with server URLs and credentials, then call `start()`. Monitor state via `connectionEvents`, `loginEvents`, `completionEvents`, and `changeEvents` streams. ```dart import 'package:objectbox/objectbox.dart'; void setupSync(Store store) { if (!Sync.isAvailable()) { print('Sync not available in this build'); return; } final client = SyncClient( store, ['wss://sync.example.com:9999'], // WebSocket URL(s) [SyncCredentials.sharedSecretString('my-secret')], // Or use JWT: SyncCredentials.jwtIdToken(token) // Or: SyncCredentials.userAndPassword('user', 'pass') ); // React to connection state changes client.connectionEvents.listen((event) { print('Connection: $event'); // connected / disconnected }); client.loginEvents.listen((event) { if (event == SyncLoginEvent.loggedIn) print('Sync active'); if (event == SyncLoginEvent.credentialsRejected) print('Auth failed'); }); // React to incoming data changes client.changeEvents.listen((List changes) { for (final change in changes) { print('Entity ${change.entity}: ' '${change.puts.length} puts, ${change.removals.length} removals'); } }); client.start(); // initiate connection // Manual control // client.requestUpdates(subscribeForFuturePushes: true); // client.stop(); // client.close(); // fully release resources } ``` ``` -------------------------------- ### Install AOT Library Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/event_manager/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library on non-Debug builds. This ensures optimized performance for release versions. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Flutter Assets in CMakeLists.txt Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/linux/CMakeLists.txt Installs Flutter assets to the application bundle. This ensures that Flutter's UI resources are correctly placed for runtime access. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install( CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Find and check system dependencies with PkgConfig Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/event_manager/linux/flutter/CMakeLists.txt This section uses PkgConfig to find and check for required system libraries like GTK, GLIB, and GIO. Ensure these libraries are installed on your system and discoverable by PkgConfig. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### Run Generator Integration Tests Source: https://github.com/objectbox/objectbox-dart/blob/main/AGENTS.md Execute generator integration tests by navigating to the objectbox_test directory, getting dependencies, building the generator, and running tests. ```bash cd objectbox_test ``` ```bash dart pub get ``` ```bash dart run build_runner build ``` ```bash dart test ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo_relations/windows/CMakeLists.txt Removes existing Flutter assets and then copies the current build's assets to the application bundle's data directory. ```cmake # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Native Assets Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo_relations/windows/CMakeLists.txt Copies native assets provided by build.dart from all packages to the application bundle's library directory. ```cmake # Copy the native assets provided by the build.dart from all packages. set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### ObjectBox Dart CRUD and Query Example Source: https://github.com/objectbox/objectbox-dart/blob/main/README.md Demonstrates basic ObjectBox operations including entity definition, store opening, and CRUD (Create, Read, Update, Delete) operations. Also shows how to build and execute a query with multiple conditions. Ensure the 'Person_' class is generated by the ObjectBox build_runner. ```dart import 'package:objectbox/objectbox.dart'; @Entity() class Person { @Id() int id; String firstName; String lastName; Person({this.id = 0, required this.firstName, required this.lastName}); } final Store store = await openStore(directory: 'person-db'); final box = store.box(); var person = Person(firstName: 'Joe', lastName: 'Green'); final id = box.put(person); // Create person = box.get(id)!; // Read person.lastName = 'Black'; box.put(person); // Update box.remove(person.id); // Delete final query = box // Query .query(Person_.firstName.equals('Joe') & Person_.lastName.startsWith('B')) .build(); final List people = query.find(); query.close(); ``` -------------------------------- ### Flutter pubspec.yaml Dependencies for ObjectBox Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/README.md Example of how dependencies should look in your pubspec.yaml file after adding ObjectBox. ```yaml dependencies: objectbox: ^5.3.1 objectbox_flutter_libs: any # If you run the command for ObjectBox Sync it should add instead: # objectbox_sync_flutter_libs: any dev_dependencies: build_runner: ^2.4.11 objectbox_generator: any ``` -------------------------------- ### Switch Flutter SDK Version Source: https://github.com/objectbox/objectbox-dart/blob/main/dev-doc/updating-examples.md Before updating examples, switch your Flutter SDK to the lowest supported version. Ensure no IDEs or tools are using the current SDK before switching. ```shell # Make sure to close IDEs or tools using the Flutter or Dart SDK first. # Then, in the Flutter SDK directory: git checkout 3.16.9 flutter doctor ``` -------------------------------- ### Set CMake Minimum Version and Project Name Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/windows/CMakeLists.txt Specifies the minimum required CMake version and the project name. This is a standard CMake setup. ```cmake cmake_minimum_required(VERSION 3.14) project(objectbox_demo LANGUAGES CXX) ``` -------------------------------- ### Execute Queries with Query.find, Query.findFirst, Query.findUnique Source: https://context7.com/objectbox/objectbox-dart/llms.txt Retrieve query results efficiently. `find()` gets all matches, `findFirst()` gets the first or null, and `findUnique()` asserts exactly one match. `findIds()` is efficient for IDs only. Remember to `close()` the query. ```dart final box = store.box(); final query = box.query(Person_.name.startsWith('A')).build(); final all = query.find(); final first = query.findFirst(); final unique = query.findUnique(); final ids = query.findIds(); final n = query.count(); query.close(); ``` -------------------------------- ### Initialize Workspace and Download Native Libraries Source: https://github.com/objectbox/objectbox-dart/blob/main/AGENTS.md Run this script to initialize the workspace, download native libraries, and generate code. Use the --sync flag for sync-enabled libraries. ```bash ./tool/init.sh ``` ```bash ./install.sh ``` ```bash ./install.sh --sync ``` -------------------------------- ### Download ObjectBox Database Library for Unit Tests Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/README.md Run this script in your package directory to download the ObjectBox database library for running unit tests on your machine. ```bash bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-dart/main/install.sh) ``` -------------------------------- ### Download and Configure ObjectBox-C Prebuilt Library Source: https://github.com/objectbox/objectbox-dart/blob/main/flutter_libs/windows/CMakeLists.txt Fetches the ObjectBox-C prebuilt library for Windows based on the specified version and architecture. This is essential for integrating ObjectBox functionality. ```cmake set(OBJECTBOX_VERSION 5.3.1) set(OBJECTBOX_ARCH ${CMAKE_SYSTEM_PROCESSOR}) if (${OBJECTBOX_ARCH} MATCHES "AMD64") set(OBJECTBOX_ARCH x64) endif () include(FetchContent) FetchContent_Declare( objectbox-download URL https://github.com/objectbox/objectbox-c/releases/download/v${OBJECTBOX_VERSION}/objectbox-windows-${OBJECTBOX_ARCH}.zip ) FetchContent_GetProperties(objectbox-download) if(NOT objectbox-download_POPULATED) FetchContent_Populate(objectbox-download) endif() ``` -------------------------------- ### Install ICU Data File Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/windows/CMakeLists.txt Installs the ICU data file, which is necessary for internationalization and localization, to the data directory. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/README.md Change your current directory to either the 'event_manager' or 'many_to_many' folder to access the project files. ```bash cd event_manager (or cd many_to_many) ``` -------------------------------- ### Download and Add ObjectBox-C Prebuilt Library Source: https://github.com/objectbox/objectbox-dart/blob/main/sync_flutter_libs/windows/CMakeLists.txt Downloads the ObjectBox C library for the target architecture and makes it available for linking. This section configures the download URL based on the ObjectBox version and system processor. ```cmake set(OBJECTBOX_VERSION 5.3.1) set(OBJECTBOX_ARCH ${CMAKE_SYSTEM_PROCESSOR}) if (${OBJECTBOX_ARCH} MATCHES "AMD64") set(OBJECTBOX_ARCH x64) endif () include(FetchContent) FetchContent_Declare( objectbox-download URL https://github.com/objectbox/objectbox-c/releases/download/v${OBJECTBOX_VERSION}/objectbox-sync-windows-${OBJECTBOX_ARCH}.zip ) FetchContent_GetProperties(objectbox-download) if(NOT objectbox-download_POPULATED) FetchContent_Populate(objectbox-download) endif() set(objectbox_sync_flutter_libs_bundled_libraries "${objectbox-download_SOURCE_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}objectbox${CMAKE_SHARED_LIBRARY_SUFFIX}" PARENT_SCOPE ) add_library(objectbox SHARED IMPORTED GLOBAL) set_target_properties(objectbox PROPERTIES IMPORTED_LOCATION ${objectbox-download_SOURCE_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}objectbox${CMAKE_SHARED_LIBRARY_SUFFIX} IMPORTED_IMPLIB ${objectbox-download_SOURCE_DIR}/lib/${CMAKE_IMPORT_LIBRARY_PREFIX}objectbox${CMAKE_IMPORT_LIBRARY_SUFFIX} ) target_link_libraries(${PLUGIN_NAME} PRIVATE objectbox) ``` -------------------------------- ### Project and Build Configuration Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/many_to_many/windows/CMakeLists.txt Sets up the minimum CMake version, project name, executable name, and modern CMake policies. It also defines build configurations (Debug, Profile, Release) and handles multi-config generators. ```cmake cmake_minimum_required(VERSION 3.14) project(many_to_many LANGUAGES CXX) # The name of the executable created for the application. Change this to change # the on-disk name of your application. set(BINARY_NAME "many_to_many") # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. cmake_policy(SET CMP0063 NEW) # Define build configuration option. get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() ``` -------------------------------- ### Application and Plugin Build Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo_relations/windows/CMakeLists.txt Adds the application's runner subdirectory and includes generated plugin build rules. ```cmake # Application build; see runner/CMakeLists.txt. add_subdirectory("runner") # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Commit Message for C API Update Source: https://github.com/objectbox/objectbox-dart/blob/main/dev-doc/updating-c-library.md Example commit message format after updating the C API and its bindings. ```text Update C API [5.3.0 -> 5.3.1] ``` -------------------------------- ### Open or Create Database Store Source: https://context7.com/objectbox/objectbox-dart/llms.txt The Store is the central database instance. Open it once at app startup using the generated openStore() helper. Supports file-based and in-memory databases. ```dart import 'package:objectbox/objectbox.dart'; import 'objectbox.g.dart'; // generated late Store store; Future openDatabase(String appDocsDir) async { // Standard file-based store store = openStore(directory: '$appDocsDir/objectbox'); // Or: in-memory store (useful for tests) // store = Store(getObjectBoxModel(), directory: 'memory:test-db'); // Or: manual construction with extra options // store = Store( // getObjectBoxModel(), // directory: '$appDocsDir/objectbox', // maxDBSizeInKB: 512 * 1024, // 512 MB cap // queriesCaseSensitiveDefault: false, // macosApplicationGroup: 'TEAMID.myapp', // sandboxed macOS only // ); } void closeDatabase() => store.close(); bool isStoreOpen(String path) => Store.isOpen(path); ``` -------------------------------- ### Configure Include Directories and Dependencies Source: https://github.com/objectbox/objectbox-dart/blob/main/flutter_libs/windows/CMakeLists.txt Specifies the include directories for the plugin's source files and links necessary libraries. Plugin-specific dependencies should be added here. ```cmake target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include" ) target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) ``` -------------------------------- ### Dart pubspec.yaml Dependencies for ObjectBox Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/README.md Example of how dependencies should look in your pubspec.yaml file after adding ObjectBox to a Dart Native project. ```yaml dependencies: objectbox: ^5.3.1 dev_dependencies: build_runner: ^2.4.11 objectbox_generator: any ``` -------------------------------- ### Store(ModelDefinition, ...) Source: https://context7.com/objectbox/objectbox-dart/llms.txt Opens or creates the central database instance. It's recommended to open it once at app startup and close it on exit. Supports file-based and in-memory databases. ```APIDOC ## Store(ModelDefinition, ...) ### Description Opens or creates the central database instance. It's recommended to open it once at app startup and close it on exit. Supports file-based and in-memory databases. ### Method `openStore()` ### Parameters - `directory` (String) - Path to the database directory. Use 'memory:' for in-memory databases. - `getObjectBoxModel` (Function) - Function to get the model definition. - `maxDBSizeInKB` (int) - Optional: Maximum database size in kilobytes. - `queriesCaseSensitiveDefault` (bool) - Optional: Default case sensitivity for queries. - `macosApplicationGroup` (String) - Optional: For sandboxed macOS applications. ### Request Example ```dart import 'package:objectbox/objectbox.dart'; import 'objectbox.g.dart'; // generated late Store store; Future openDatabase(String appDocsDir) async { // Standard file-based store store = openStore(directory: '$appDocsDir/objectbox'); // Or: in-memory store (useful for tests) // store = Store(getObjectBoxModel(), directory: 'memory:test-db'); // Or: manual construction with extra options // store = Store( // getObjectBoxModel(), // directory: '$appDocsDir/objectbox', // maxDBSizeInKB: 512 * 1024, // 512 MB cap // queriesCaseSensitiveDefault: false, // macosApplicationGroup: 'TEAMID.myapp', // sandboxed macOS only // ); } void closeDatabase() => store.close(); bool isStoreOpen(String path) => Store.isOpen(path); ``` ``` -------------------------------- ### Set Minimum CMake Version Source: https://github.com/objectbox/objectbox-dart/blob/main/sync_flutter_libs/linux/CMakeLists.txt Ensures the Flutter tooling has CMake 3.10 or later installed. Do not increase this version to maintain compatibility. ```cmake cmake_minimum_required(VERSION 3.10) ``` -------------------------------- ### Populate ObjectBox Download Source: https://github.com/objectbox/objectbox-dart/blob/main/sync_flutter_libs/linux/CMakeLists.txt Fetches and populates the ObjectBox C library if it hasn't been already. This ensures the library is available for the build. ```cmake FetchContent_GetProperties(objectbox-download) if(NOT objectbox-download_POPULATED) FetchContent_Populate(objectbox-download) endif() ``` -------------------------------- ### Add Libraries and Include Directories Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo/windows/runner/CMakeLists.txt Links necessary libraries and specifies include directories for the application. Application-specific dependencies should also be added here. ```cmake # Add dependency libraries and include directories. Add any application-specific # dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Project and Build Configuration Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/event_manager/windows/CMakeLists.txt Sets up the minimum CMake version, project name, and handles multi-configuration generators. It also defines build types like Debug, Profile, and Release, and configures settings for the Profile build mode. ```cmake cmake_minimum_required(VERSION 3.14) project(event_manager_objectbox LANGUAGES CXX) set(BINARY_NAME "event_manager_objectbox") cmake_policy(SET CMP0063 NEW) get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Query.findWithScores() / Query.findIdsWithScores() Source: https://context7.com/objectbox/objectbox-dart/llms.txt Used with HNSW nearest-neighbor queries to get both the object (or ID) and the distance score. This allows for efficient retrieval of nearest neighbors along with their similarity scores. ```APIDOC ## `Query.findWithScores()` / `Query.findIdsWithScores()` — vector search results Used with HNSW nearest-neighbor queries to get both the object (or ID) and the distance score. ```dart @Entity() class City { @Id() int id = 0; String? name; @HnswIndex(dimensions: 2, distanceType: VectorDistanceType.geo) @Property(type: PropertyType.floatVector) List? location; // [latitude, longitude] City(this.name, this.location); } void nearestCities(Box box) { final madrid = [40.416775, -3.703790]; final query = box .query(City_.location.nearestNeighborsF32(madrid, 3)) .build(); // Objects + distances final withScores = query.findWithScores(); // List> for (final r in withScores) { print('${r.object.name}: ${r.score.toStringAsFixed(2)} km'); } // IDs only + distances (no object deserialization) final idScores = query.findIdsWithScores(); // List for (final r in idScores) { print('ID ${r.id}: distance ${r.score}'); } query.close(); } ``` ``` -------------------------------- ### CMake Policy Configuration Source: https://github.com/objectbox/objectbox-dart/blob/main/flutter_libs/windows/CMakeLists.txt Explicitly opts into modern CMake behaviors to avoid warnings with recent CMake versions. This ensures consistent behavior across different CMake installations. ```cmake cmake_policy(VERSION 3.14...3.25) ``` -------------------------------- ### Export Flutter Library and ICU Data Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/event_manager/windows/flutter/CMakeLists.txt Exports the Flutter library path and the Flutter ICU data file to the parent scope. This makes them available for other CMake targets and the installation step. ```cmake set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) ``` -------------------------------- ### Source Include Directories and Dependencies Source: https://github.com/objectbox/objectbox-dart/blob/main/sync_flutter_libs/windows/CMakeLists.txt Specifies include directories and links against necessary libraries. 'flutter' and 'flutter_wrapper_plugin' are essential for Flutter integration. ```cmake target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/objectbox/objectbox-dart/blob/main/flutter_libs/windows/CMakeLists.txt Applies a standard set of build settings configured in the application-level CMakeLists.txt. This can be removed if the plugin requires full control over build settings. ```cmake apply_standard_settings(${PLUGIN_NAME}) ``` -------------------------------- ### Configure Plugin Dependencies Source: https://github.com/objectbox/objectbox-dart/blob/main/sync_flutter_libs/linux/CMakeLists.txt Sets include directories and links necessary libraries for the plugin. 'flutter' and 'PkgConfig::GTK' are required dependencies. ```cmake target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include" ) target_link_libraries(${PLUGIN_NAME} PRIVATE flutter) target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Reactive Query Stream with `QueryBuilder.watch()` Source: https://context7.com/objectbox/objectbox-dart/llms.txt Use `watch()` to get a `Stream>` that emits the query whenever watched entities change. Combine with `.map()` and `.find()` for live result lists. Remember to cancel the subscription when done. ```dart final box = store.box(); // Emit current results immediately and on every subsequent change final Stream> livePersons = box .query(Person_.name.startsWith('A')) .order(Person_.name) .watch(triggerImmediately: true) .map((query) => query.find()); // In Flutter use with StreamBuilder: // StreamBuilder>( // stream: livePersons, // builder: (ctx, snap) => ListView(...), // ) // Cancel the subscription when done final sub = livePersons.listen((people) => print('${people.length} As')); sub.cancel(); ``` -------------------------------- ### Box.get() / Box.getMany() / Box.getAll() Source: https://context7.com/objectbox/objectbox-dart/llms.txt Retrieve objects from the box by their IDs. `get()` returns a single object or null if not found. `getMany()` retrieves multiple objects, returning null for any IDs not found. `getAll()` fetches all objects in the box. ```APIDOC ## `Box.get()` / `Box.getMany()` / `Box.getAll()` — read objects Retrieve objects by ID. Returns `null` for `get()` if not found; `getMany()` returns a list where missing items are represented as `null`. ```dart final box = store.box(); // Get single by ID final person = box.get(aliceId); // Person? — null if not found // Get multiple by IDs final some = box.getMany([1, 2, 3]); // List — nulls for missing // Get all (use queries for large datasets) final everyone = box.getAll(); // List // Count objects print(box.count()); // total count print(box.isEmpty()); // bool ``` ``` -------------------------------- ### Declare ObjectBox Download Source: https://github.com/objectbox/objectbox-dart/blob/main/sync_flutter_libs/linux/CMakeLists.txt Declares the ObjectBox C library download using FetchContent. The URL is constructed using the defined version and architecture. ```cmake include(FetchContent) FetchContent_Declare( objectbox-download URL https://github.com/objectbox/objectbox-c/releases/download/v${OBJECTBOX_VERSION}/objectbox-sync-linux-${OBJECTBOX_ARCH}.tar.gz ) ``` -------------------------------- ### Read Objects with Box.get, Box.getMany, Box.getAll Source: https://context7.com/objectbox/objectbox-dart/llms.txt Retrieve objects from the box by ID. `get()` returns a single object or null, `getMany()` returns a list with nulls for missing items, and `getAll()` retrieves all objects. Use `count()` and `isEmpty()` for metadata. ```dart final box = store.box(); final person = box.get(aliceId); final some = box.getMany([1, 2, 3]); final everyone = box.getAll(); print(box.count()); print(box.isEmpty()); ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo_relations/windows/runner/CMakeLists.txt Links necessary libraries (flutter, flutter_wrapper_app, dwmapi.lib) and sets include directories for the project. Add any application-specific dependencies here. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) ``` ```cmake target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") ``` ```cmake target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Project and Build Configuration Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/objectbox_demo_relations/linux/CMakeLists.txt Sets the minimum CMake version, project name, binary name, and application ID. It also configures build type and enables modern CMake behaviors. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) # The name of the executable created for the application. Change this to change # the on-disk name of your application. set(BINARY_NAME "objectbox_demo_relations") # The unique GTK application identifier for this application. See: # https://wiki.gnome.org/HowDoI/ChooseApplicationID set(APPLICATION_ID "com.example.objectbox_demo_relations") # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. cmake_policy(SET CMP0063 NEW) # Load bundled libraries from the lib/ directory relative to the binary. set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Root filesystem for cross-building. if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() # Define build configuration options. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### Flutter and System Dependencies Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/many_to_many/linux/CMakeLists.txt Includes the Flutter managed directory and finds PkgConfig and GTK libraries. Defines the application ID as a preprocessor macro. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Runtime Output Directory Configuration Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/many_to_many/linux/CMakeLists.txt Sets the runtime output directory for the executable to a subdirectory to ensure correct resource loading when bundled. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Generate Binding Code Source: https://github.com/objectbox/objectbox-dart/blob/main/objectbox/example/flutter/event_management_tutorial/README.md Execute this command to generate the necessary binding code for your project, typically required for code generation tools like build_runner. ```bash dart run build_runner build ```