### Install Application Executable Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Installs the main application executable to the runtime destination. This makes the application available for execution. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Set Installation Prefix and Bundle Directory Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/CMakeLists.txt Configures the installation prefix and the directory for the application bundle. This ensures the application is installed to a predictable location. ```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() ``` -------------------------------- ### Define Installation Directories Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/CMakeLists.txt Sets variables for the installation directories within the bundle, specifically for data and libraries. These are used in subsequent install commands. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Run Flutter Example Source: https://github.com/getstream/stream-feeds-flutter/blob/main/packages/stream_feeds/example/README.md Commands to create and run the Stream Feeds Flutter example application, primarily targeting Chrome for web testing. ```bash flutter create . flutter run -d chrome ``` -------------------------------- ### Install Flutter Library Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Installs the main Flutter library file to the root of the application bundle's installation directory. This is a core component for running Flutter applications. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Define Installation Directories Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Defines variables for the installation directories within the bundle, specifically for data files and libraries. These paths are relative to the CMAKE_INSTALL_PREFIX. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Setup and Code Generation Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md Commands for bootstrapping dependencies, generating code, running tests, linting, and cleaning the Flutter project using Melos. ```bash # Setup melos bootstrap # Generate code melos run generate:all # Test melos run test:all # Format & lint melos run lint:all # Clean melos run clean:flutter ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Installs any bundled plugin libraries to the application bundle's library directory. This ensures that plugins are available at runtime. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/CMakeLists.txt Iterates through a list of bundled libraries (likely from plugins) and installs each one to the library directory. This ensures all necessary plugin code is available at runtime. ```cmake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Clean Build Bundle Directory on Install Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/CMakeLists.txt Installs a code block that removes the build bundle directory before installation. This ensures a clean state for each installation. ```cmake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Find System Dependencies Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/CMakeLists.txt Finds and checks for required system-level dependencies using PkgConfig. This example specifically checks for 'gtk+-3.0'. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Install AOT Library for Release Builds Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library, but only for 'Profile' and 'Release' configurations. This optimizes runtime performance for non-debug builds. ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Installs the Flutter assets directory. It first removes any existing assets to ensure a clean copy, then copies the assets from the build directory to the application's data directory. ```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) ``` -------------------------------- ### Set Installation Prefix for Bundled App Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Configures the installation prefix to be next to the executable, facilitating in-place running, especially for Visual Studio builds. It forces the prefix if it was initialized to default. ```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 Native Assets Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/CMakeLists.txt Installs native assets provided by packages to the library directory. These assets are typically platform-specific code or resources required by plugins. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Repository Pattern with Result Example Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md Example of a repository method returning a `Result` type, handling potential network exceptions and mapping API responses to domain models. ```dart Future> getActivity(String id) async { try { final result = await apiClient.getActivity(id: id); if (result == null) { return Result.failure(NetworkException('No data returned')); } return Result.success(result.toModel()); } on ClientException catch (e) { return Result.failure(_mapClientException(e)); } } ``` -------------------------------- ### Install ICU Data File Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Installs the ICU data file, which is necessary for internationalization and localization, to the data directory of the application bundle. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Freezed Data Model Example Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md Example of a data class using `@freezed` with mixed mode syntax, including required fields and custom data. ```dart @freezed class ActivityData with _$ActivityData { const ActivityData({ required this.id, required this.user, this.custom, }); @override final String id; @override final UserData user; @override final Map? custom; } ``` -------------------------------- ### Initialize StreamFeedsClient and Add Activity Source: https://github.com/getstream/stream-feeds-flutter/blob/main/README.md Initialize the StreamFeedsClient with your API key and user token, then connect to the service. This snippet demonstrates creating or getting a feed and adding a new activity to it. ```dart // Import the package import 'package:stream_feeds/stream_feeds.dart'; // Initialize the client final client = StreamFeedsClient( apiKey: '', user: User(id: 'john'), tokenProvider: TokenProvider.static(UserToken('')), ); await client.connect(); // Create a feed (or get its data if exists) final feed = client.feed(group: 'user', id: 'john'); final result = await feed.getOrCreate(); // Add activity final activity = await feed.addActivity( request: FeedAddActivityRequest(type: 'post', text: 'Hello, Stream Feeds!'), ); ``` -------------------------------- ### Install Native Assets Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Installs native assets provided by build.dart from all packages into the application bundle's library directory. This ensures that native code dependencies are correctly deployed. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Initialize StreamFeeds Client and Add Activity Source: https://github.com/getstream/stream-feeds-flutter/blob/main/packages/stream_feeds/README.md Initialize the StreamFeedsClient with your API key and user token, then connect to the service. After connecting, you can create a feed, get its data, and add a new activity to it. ```dart // Import the package import 'package:stream_feeds/stream_feeds.dart'; // Initialize the client final client = StreamFeedsClient( apiKey: '', user: User(id: 'john'), tokenProvider: TokenProvider.static(UserToken('')), ); await client.connect(); // Create a feed (or get its data if exists) final feed = client.feed(group: 'user', id: 'john'); final result = await feed.getOrCreate(); // Add activity final activity = await feed.addActivity( request: FeedAddActivityRequest(type: 'post', text: 'Hello, Stream Feeds!'), ); ``` -------------------------------- ### Example Feed Operation Test Source: https://github.com/getstream/stream-feeds-flutter/blob/main/packages/stream_feeds_test/README.md Demonstrates how to use the `feedTest` helper to test adding an activity to a feed. It includes setting up API mocks, performing the action, and verifying the result and API calls. ```dart import 'package:stream_feeds/stream_feeds.dart'; import 'package:stream_feeds_test/stream_feeds_test.dart'; void main() { group('Feed Operations', () { feedTest( 'adds activity successfully', build: (client) => client.feed(group: 'user', id: 'john'), setUp: (tester) { tester.mockApi( (api) => api.addActivity(addActivityRequest: any(named: 'addActivityRequest')), result: createDefaultActivityResponse(id: 'new-activity'), ); }, body: (tester) async { final result = await tester.feed.addActivity( FeedAddActivityRequest(verb: 'post', object: 'picture:1'), ); expect(result, isA>()); expect(result.getOrThrow().id, 'new-activity'); }, verify: (tester) { tester.verifyApi( (api) => api.addActivity(addActivityRequest: any(named: 'addActivityRequest')), ); }, ); }); } ``` -------------------------------- ### Install AOT Library for Non-Debug Builds Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the library directory, but only for non-Debug build configurations. This is used for performance optimization in release builds. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Set Project Minimum Version and Name Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/CMakeLists.txt Specifies the minimum required CMake version and the project name. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) ``` -------------------------------- ### Add Stream SDK to Flutter Project via CLI Source: https://github.com/getstream/stream-feeds-flutter/blob/main/README.md Use the flutter pub add command to automatically install the latest Stream SDK package. ```shell flutter pub add stream_feeds ``` -------------------------------- ### Configure Flutter library and headers Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/flutter/CMakeLists.txt Defines the path to the Flutter Linux GTK shared library and its header files. These are then exposed to the parent scope for use in installation steps. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) ``` -------------------------------- ### Add StreamFeeds SDK via Flutter CLI Source: https://github.com/getstream/stream-feeds-flutter/blob/main/packages/stream_feeds/README.md Use the flutter pub add command in the terminal to install the latest Stream SDK package. ```shell flutter pub add stream_feeds ``` -------------------------------- ### Set Minimum CMake Version and Project Name Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Specifies the minimum required CMake version and defines the project name. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.14) project(sample LANGUAGES CXX) ``` -------------------------------- ### Testing Feed Delete Activity Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md This example shows how to test the `deleteActivity` method of a `Feed` object using `feedTest`. It includes mocking the API call and verifying the deletion. ```dart feedTest( 'deleteActivity() - should delete activity', build: (client) => client.feedFromId(feedId), setUp: (tester) => tester.getOrCreate(), body: (tester) async { tester.mockApi( (api) => api.deleteActivity(id: 'activity-1', hardDelete: false), result: const DeleteActivityResponse(duration: '0ms'), ); final result = await tester.feed.deleteActivity(id: 'activity-1'); expect(result.isSuccess, isTrue); }, verify: (tester) => tester.verifyApi( (api) => api.deleteActivity(id: 'activity-1', hardDelete: false), ), ); ``` -------------------------------- ### Configure Cross-Building Sysroot Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/CMakeLists.txt Sets up the sysroot and find root paths for cross-compilation. This is used when building for a different target platform than the host. ```cmake 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() ``` -------------------------------- ### Find and check PkgConfig modules Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/flutter/CMakeLists.txt This snippet uses PkgConfig to find and check for required system libraries: gtk+-3.0, glib-2.0, and gio-2.0. It imports these as targets for linking. ```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) ``` -------------------------------- ### Configure Build Configurations (Multi-config Generators) Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Sets the available build configurations (Debug, Profile, Release) for multi-configuration generators like Visual Studio. The FORCE option overwrites any existing cache entry. ```cmake set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/runner/CMakeLists.txt Applies a standard set of build settings to the specified target. This can be removed if custom build settings are required. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Generate OpenAPI Client Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md Generate the OpenAPI client code. This process requires the OpenAPI specification file to be present and up-to-date. ```bash melos run gen:feeds ``` -------------------------------- ### Enable Unicode Support Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Adds preprocessor definitions to enable Unicode support for all projects. This is crucial for handling international characters correctly. ```cmake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Flutter Tool Backend Custom Command Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/flutter/CMakeLists.txt Sets up a custom command to execute the Flutter tool backend script, which is responsible for generating build artifacts. A phony output file is used to ensure the command runs on every build. ```cmake # === Flutter tool backend === # _phony_ is a non-existent file to force this command to run every time, # since currently there's no way to get a full input/output list from the # flutter tool. set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Enable Modern CMake Behaviors Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/CMakeLists.txt Explicitly opts into modern CMake behaviors to avoid warnings in newer CMake versions. This ensures compatibility and cleaner build output. ```cmake cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Run All Code Generation Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md Execute all code generation tasks for both Dart and Flutter packages. This command ensures all generated files are up-to-date. ```bash melos run generate:all ``` -------------------------------- ### Running All Tests Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md Execute all tests within the project using the `melos run test:all` command. ```bash # Run all tests melos run test:all ``` -------------------------------- ### Set Include Directories Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/runner/CMakeLists.txt Specifies the include directories for the application target, making source files accessible during compilation. ```cmake target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Define Executable Target and Source Files Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/runner/CMakeLists.txt Defines the main executable target for the Windows runner and lists all source files, including C++ files, generated plugin registration, and resource files. Ensure BINARY_NAME is consistent with the top-level CMakeLists.txt for `flutter run` compatibility. ```cmake add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) ``` -------------------------------- ### Configure Flutter Wrapper Plugin Library Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/flutter/CMakeLists.txt Defines and configures the static library for the Flutter wrapper plugin, including core and plugin-specific source files and linking against the Flutter library. ```cmake list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") # Wrapper sources needed for a plugin. add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/runner/CMakeLists.txt Links the necessary Flutter libraries and the wrapper application library to the target. Also adds the source directory to the include paths for header resolution. Application-specific dependencies should be added 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}") ``` -------------------------------- ### Link Application Libraries Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/runner/CMakeLists.txt Links necessary libraries to the application target. Includes the Flutter engine and GTK via PkgConfig. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Configure Flutter Wrapper App Library Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/flutter/CMakeLists.txt Defines and configures the static library for the Flutter wrapper application, including core and app-specific source files and linking against the Flutter library. ```cmake # Wrapper sources needed for the runner. add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/CMakeLists.txt Defines a function to apply common compilation settings like C++ standard, warning options, optimization levels, and preprocessor definitions. This promotes consistency across targets. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Set Runtime Library Path Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/CMakeLists.txt Configures the runtime search path for libraries, ensuring bundled libraries in the 'lib' directory are found. This is important for relocatable application bundles. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Define Application Target Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/runner/CMakeLists.txt Defines the main executable target for the application. Ensure BINARY_NAME is consistent with the top-level CMakeLists.txt for `flutter run` compatibility. Add any new source files to this list. ```cmake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) ``` -------------------------------- ### Run Flutter Package Code Generation Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md Generate code for the Flutter packages. This is necessary when Flutter-specific code or dependencies are involved. ```bash melos run generate:flutter ``` -------------------------------- ### Define Executable and Application IDs Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/CMakeLists.txt Sets the name of the executable binary and the unique application identifier. These are crucial for application identification and packaging. ```cmake set(BINARY_NAME "sample") set(APPLICATION_ID "io.getstream.feeds.flutter.sample") ``` -------------------------------- ### Define Profile Build Mode Linker and Compiler Flags Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Sets linker and compiler flags for the 'Profile' build mode, typically by copying settings from the 'Release' configuration. This ensures consistent performance tuning. ```cmake 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}") ``` -------------------------------- ### Define Flutter library interface target Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/flutter/CMakeLists.txt Creates an INTERFACE library target named 'flutter' and configures its include directories and link libraries. This includes system headers, the Flutter library, and PkgConfig modules. ```cmake list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Run Code Quality Checks with Melos Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md Execute code formatting, verification, static analysis, and linting using Melos commands. Ensure code adheres to project standards. ```bash # Format code melos run format # Verify formatting melos run format:verify # Run static analysis melos run analyze # Run linting + formatting melos run lint:all ``` -------------------------------- ### Add Preprocessor Definitions for Build Version Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/runner/CMakeLists.txt Sets preprocessor definitions for the build version, including major, minor, patch, and build numbers. These are useful for embedding version information directly into the compiled code. ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") ``` -------------------------------- ### Add StreamFeeds SDK to Flutter Project Source: https://github.com/getstream/stream-feeds-flutter/blob/main/packages/stream_feeds/README.md Add the latest dependencies for the SDK to your pubspec.yaml file or use the flutter pub add command. ```yaml dependencies: stream_feeds: ^latest ``` -------------------------------- ### Set Runtime Output Directory Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/CMakeLists.txt Configures the runtime output directory for the main executable. Placing it in 'intermediates_do_not_run' prevents accidental execution of unbundled copies. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Add Stream SDK to Flutter Project Source: https://github.com/getstream/stream-feeds-flutter/blob/main/README.md Add the latest dependencies for the Stream SDK to your pubspec.yaml file or use the flutter pub add command. ```yaml dependencies: stream_feeds: ^latest ``` -------------------------------- ### Define list_prepend function for CMake < 3.10 Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/flutter/CMakeLists.txt This custom function replicates the functionality of list(TRANSFORM ... PREPEND ...) for older CMake versions (prior to 3.10). It prepends a given prefix to each element in a list. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Configure Build Configuration (Single-config Generators) Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Sets the default build type to 'Debug' for single-configuration generators if not already specified. It also defines the allowed string values for the build type. ```cmake 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() ``` -------------------------------- ### Set Executable Binary Name Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Defines the name of the executable file that will be created. This can be changed to alter the application's on-disk name. ```cmake set(BINARY_NAME "sample") ``` -------------------------------- ### Include Flutter Managed Directory Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Adds the Flutter managed directory to the build. This typically includes Flutter's internal build rules and configurations. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Avoid Mocking SDK Internals Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md Do not use `any()` to mock SDK methods as it bypasses actual request matching. Avoid testing internal mappers or directly instantiating repositories and notifiers, as these test implementation details rather than the public API. ```dart // ❌ Using any() — mock matches regardless of what the SDK sends tester.mockApi( (api) => api.addActivity(addActivityRequest: any(named: 'addActivityRequest')), result: ... ); // ❌ Testing internal mapper directly final response = createDefaultActivityResponse(id: 'act-1'); final model = response.toModel(); // tests implementation detail, not public API expect(model.id, 'act-1'); // ❌ Instantiating a repository directly final repo = ActivitiesRepository(apiClient); final result = await repo.addActivity(request); // ❌ Instantiating a StateNotifier directly final notifier = FeedStateNotifier(feedId, repo); notifier.state; ``` -------------------------------- ### Add Application ID Preprocessor Definition Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/runner/CMakeLists.txt Adds a preprocessor definition for the application ID, making it available during compilation. ```cmake add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Testing FeedsClient Upsert Activities Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md This snippet demonstrates how to test the `upsertActivities` method of `FeedsClient` using `feedsClientTest`. It shows how to mock the API call with a specific request and verify the SDK's interaction. ```dart import 'package:stream_feeds/stream_feeds.dart'; // ✅ public API only import 'package:stream_feeds_test/stream_feeds_test.dart'; feedsClientTest( 'should upsert activities successfully', body: (tester) async { final activities = [ const ActivityRequest(feeds: ['user:123'], id: '1', text: 'Hello', type: 'post'), ]; const request = UpsertActivitiesRequest(activities: activities); tester.mockApi( (api) => api.upsertActivities(upsertActivitiesRequest: request), result: createDefaultUpsertActivitiesResponse(count: 1), ); final result = await tester.client.upsertActivities(activities: activities); expect(result.isSuccess, isTrue); tester.verifyApi( (api) => api.upsertActivities(upsertActivitiesRequest: request), ); }, ); ``` -------------------------------- ### Mocking API with Primitive/Nullable Parameters Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md When mocking API calls with nullable or primitive parameters, pass the exact expected value. This ensures accurate stubbing and verification. ```dart // ✅ pass the actual expected value tester.mockApi( (api) => api.deleteActivity(id: 'activity-1', hardDelete: false), result: const DeleteActivityResponse(duration: '0ms'), ); ``` -------------------------------- ### Include Generated Plugins Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Includes the CMake script that manages building and integrating generated plugins into the application. This is essential for using Flutter plugins. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Opt-in to Modern CMake Behaviors Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Explicitly enables modern CMake behaviors to suppress warnings in newer CMake versions. This ensures compatibility and adherence to current CMake practices. ```cmake cmake_policy(VERSION 3.14...3.25) ``` -------------------------------- ### Set Flutter Library and Headers Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/flutter/CMakeLists.txt Defines the Flutter library and its associated header files, making them available for linking and inclusion in the build process. ```cmake set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) # TODO: Move the rest of this into files in ephemeral. See # https://github.com/flutter/flutter/issues/57146. set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") # Set fallback configurations for older versions of the flutter tool. if (NOT DEFINED FLUTTER_TARGET_PLATFORM) set(FLUTTER_TARGET_PLATFORM "windows-x64") endif() # === Flutter Library === set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "flutter_export.h" "flutter_windows.h" "flutter_messenger.h" "flutter_plugin_registrar.h" "flutter_texture_registrar.h" ) list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Define Standard Compilation Settings Function Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt A function to apply common compilation settings to targets, including C++17 standard, warning levels, and exception handling. Use with caution, as it applies broadly. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() ``` -------------------------------- ### Include Runner Subdirectory Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/CMakeLists.txt Includes the 'runner' subdirectory, which contains the build rules for the application's runner component. This is where the main application logic is typically built. ```cmake add_subdirectory("runner") ``` -------------------------------- ### Custom command for Flutter tool backend Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/linux/flutter/CMakeLists.txt This custom command invokes the Flutter tool's backend script to generate necessary build artifacts like the Flutter library and headers. It uses a phony target to ensure execution on every build. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Execute Flutter Build Tooling Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/runner/CMakeLists.txt Ensures that the Flutter tool's build process is executed as part of the CMake build. This dependency must not be removed for the Flutter build to function correctly. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Run Dart Package Code Generation Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md Generate code specifically for the Dart packages within the project. Use this when changes are confined to Dart-only components. ```bash melos run generate:dart ``` -------------------------------- ### Emit WebSocket Events in Tests Source: https://github.com/getstream/stream-feeds-flutter/blob/main/packages/stream_feeds_test/README.md Shows how to emit WebSocket events and wait for their processing using `tester.pump()`. This is useful for testing real-time updates. ```dart await tester.emitEvent(ActivityAddedFeedEvent(...)); await tester.pump(); // Wait for event processing ``` -------------------------------- ### Running Flutter Tests Only Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md Execute only the Flutter-related tests by running `melos run test:flutter`. ```bash # Run Flutter tests only melos run test:flutter ``` -------------------------------- ### Running Dart Tests Only Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md To run only the Dart-specific tests, use the `melos run test:dart` command. ```bash # Run Dart tests only melos run test:dart ``` -------------------------------- ### Add Stream Feeds Test as Dev Dependency Source: https://github.com/getstream/stream-feeds-flutter/blob/main/packages/stream_feeds_test/README.md Add this package as a dev dependency in your pubspec.yaml file to use the testing utilities. ```yaml dev_dependencies: stream_feeds_test: path: ../stream_feeds_test ``` -------------------------------- ### Mocking API with Specific Request Object Source: https://github.com/getstream/stream-feeds-flutter/blob/main/AGENTS.md Use specific request objects when mocking API calls with `tester.mockApi`. This ensures the mock only responds to the exact request sent by the SDK, helping to catch bugs. This pattern is recommended over using `any()` matchers. ```dart const request = CreateDeviceRequest( id: 'firebase-token-123', pushProvider: CreateDeviceRequestPushProvider.firebase, pushProviderName: 'MyApp Firebase', ); // Stub the API response for the specific request tester.mockApi( (api) => api.createDevice(createDeviceRequest: request), result: createDefaultCreateDeviceResponse(), ); // Call the SDK method final result = await tester.client.createDevice( id: 'firebase-token-123', pushProvider: PushNotificationsProvider.firebase, pushProviderName: 'MyApp Firebase', ); // Verify that the SDK made the expected API call tester.verifyApi((api) => api.createDevice(createDeviceRequest: request)); ``` ```dart // ❌ WRONG — any() matches anything; the mock returns the response even if the SDK // sends the wrong request, hiding bugs tester.mockApi( (api) => api.createDevice(createDeviceRequest: any(named: 'createDeviceRequest')), result: createDefaultCreateDeviceResponse(), ); ``` -------------------------------- ### Disable Conflicting Windows Macros Source: https://github.com/getstream/stream-feeds-flutter/blob/main/sample_app/windows/runner/CMakeLists.txt Disables the NOMINMAX macro to prevent conflicts between Windows API macros and C++ standard library functions. ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.