### Installation Prefix and Bundle Directory Setup Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/CMakeLists.txt Configures the installation prefix to the build bundle directory and sets up directories for data and libraries within the bundle. This prepares for creating a relocatable application bundle. ```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") ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Initializes the CMake build system and sets the project name and language. This is a standard starting point for any CMake project. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) ``` -------------------------------- ### Installing Application Executable Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Installs the main application executable to the root of the installation prefix. This is a Runtime component installation. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Configure iOS Build Mode (CocoaPods) Source: https://github.com/openflutter/fluwx/blob/main/doc/DEVELOPMENT.md Disable Swift Package Manager and install CocoaPods dependencies for the iOS example app. ```bash # CocoaPods mode flutter config --no-enable-swift-package-manager cd packages/fluwx/example/ios && pod install ``` -------------------------------- ### Run Example App (fluwx) Source: https://github.com/openflutter/fluwx/blob/main/doc/DEVELOPMENT.md Navigate to the example directory for the fluwx package (with WeChat Pay) and run the app. ```bash # fluwx (with Pay) cd packages/fluwx/example flutter pub get flutter run ``` -------------------------------- ### Run Example App (fluwx_no_pay) Source: https://github.com/openflutter/fluwx/blob/main/doc/DEVELOPMENT.md Navigate to the example directory for the fluwx_no_pay package (without Pay) and run the app. ```bash # fluwx_no_pay (without Pay) cd packages/fluwx_no_pay/example flutter pub get flutter run ``` -------------------------------- ### Installing Bundled Plugin Libraries Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Installs all bundled libraries provided by plugins to the lib directory. This loop iterates through PLUGIN_BUNDLED_LIBRARIES and installs each as a Runtime component. ```cmake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Installing Flutter Library Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Installs the main Flutter library file to the lib directory within the bundle. This is a Runtime component installation. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Defining Installation Directories Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Sets variables for the installation directories within the bundle: 'data' for assets and 'lib' for libraries. These are used for subsequent install commands. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Setting Installation Prefix Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Configures the installation prefix to the build bundle directory if it's initialized to the default. This ensures the application is installed within a self-contained 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() ``` -------------------------------- ### Installing Application Executable and Data Files Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/CMakeLists.txt Installs the application executable, ICU data file, Flutter library, and bundled plugin libraries into the designated installation directories within the bundle. This ensures all necessary components are included in the final package. ```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) ``` -------------------------------- ### Installing AOT Library Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the lib directory, but only for non-Debug builds. This is an optimization for release and profile builds. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### OpenHarmony WeChat Installation Check Configuration Source: https://github.com/openflutter/fluwx/blob/main/README.md Configure your module.json5 file on OpenHarmony to check for WeChat installation by adding 'weixin' to querySchemes. ```json5 { "module": { "querySchemes": [ "weixin" ] } } ``` -------------------------------- ### Installing AOT Library Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library into the bundle's library directory, but only for non-Debug builds. This optimizes performance for release and profile builds. ```cmake # Install the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Installing Flutter Assets Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/CMakeLists.txt Installs the Flutter assets into the bundle's data directory, ensuring that all Flutter-specific resources are included. The directory is cleared before copying to prevent stale files. ```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) ``` -------------------------------- ### Cleaning Build Bundle Directory on Install Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Removes the build bundle directory before installation to ensure a clean state. This is part of the installation process for the Runtime component. ```cmake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Clone and Bootstrap Monorepo Source: https://github.com/openflutter/fluwx/blob/main/doc/DEVELOPMENT.md Clone the repository and install workspace dependencies using Melos. Ensure git is configured for symlinks on Windows. ```bash git clone https://github.com/OpenFlutter/fluwx.git cd fluwx # Install workspace dependencies and link packages dart pub get melos bootstrap ``` -------------------------------- ### Installing Native Assets Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Installs native assets provided by build.dart from all packages into the lib directory of the bundle. This ensures that platform-specific assets are available at runtime. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installing Native Assets Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/CMakeLists.txt Installs native assets provided by build.dart into the bundle's library directory. This ensures that any platform-specific assets required by plugins are correctly packaged. ```cmake # 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) ``` -------------------------------- ### Installing ICU Data File Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Installs the ICU data file to the data directory within the bundle. This is required for internationalization and is part of the Runtime component. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Initiate WeChat Authentication Source: https://github.com/openflutter/fluwx/blob/main/doc/AUTH.md Use this snippet to start the WeChat login process by requesting user authorization. Note that `fluwx` does not handle `access_token` retrieval; this should be managed on the backend. ```dart Fluwx fluwx = Fluwx(); fluwx.authBy(which: NormalAuth(scope: 'snsapi_userinfo', state: 'wechat_sdk_demo_test')); ``` -------------------------------- ### Ensuring Fresh Asset Installation Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Removes the Flutter assets directory before copying new assets to prevent stale files. This ensures that the installed assets are always up-to-date. ```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) ``` -------------------------------- ### Open Customer Service Chat Source: https://github.com/openflutter/fluwx/blob/main/doc/Customer_Service.md Checks if WeChat is installed before attempting to open a customer service chat. If WeChat is not installed, it handles redirection to the App Store on iOS or shows a toast message on other platforms. Requires `fluwx` and `easy_loading` packages. ```dart static Fluwx _fluwx = Fluwx(); static Future openCustomerServiceChat() async { bool isInstall = await _fluwx.isWeChatInstalled; if (!isInstall) { if (Platform.isIOS) { jumpToAppStore(); } else { EasyLoading.showToast("UnInstall"); } return; } CustomerServiceChat chat = CustomerServiceChat( corpId: "wwdxxxxxx", url: "https://work.weixin.qq.com/kfid/kfcxxxxxx"); _fluwx.open(target: chat); } jumpToAppStore() async { final uri = Uri.parse('https://apps.apple.com/app/id414478124'); if (await canLaunchUrl(uri)) { await launchUrl(uri); } } ``` -------------------------------- ### Check Symlinks Source: https://github.com/openflutter/fluwx/blob/main/doc/DEVELOPMENT.md Verify that all symlinks are correctly set up after bootstrapping the monorepo. ```bash melos run symlinks:check ``` -------------------------------- ### System Dependencies and Runner Integration Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/CMakeLists.txt Finds PkgConfig and GTK+ 3.0, then adds the runner subdirectory for application-specific build rules. This ensures necessary system libraries are available and integrates the main application logic. ```cmake # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) # Application build; see runner/CMakeLists.txt. add_subdirectory("runner") ``` -------------------------------- ### Configure iOS Build Mode (SPM) Source: https://github.com/openflutter/fluwx/blob/main/doc/DEVELOPMENT.md Enable Swift Package Manager for iOS builds. ```bash # SPM mode flutter config --enable-swift-package-manager ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/runner/CMakeLists.txt Applies a standard set of build settings to the specified target. This can be customized if the application requires different build configurations. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Handle Launch App from H5 Responses Source: https://github.com/openflutter/fluwx/blob/main/doc/LAUNCH_APP_FROM_H5.md Subscribe to Fluwx responses to handle app launches initiated from H5. Differentiate between Android (`WeChatShowMessageFromWXRequest`) and iOS (`WeChatLaunchFromWXRequest`) events, or handle them collectively. ```dart void handle_launch_from_h5() { Fluwx fluwx = Fluwx(); fluwx.addSubscriber((response) { // 1. Handle responses separately for android and ios if (response is WeChatShowMessageFromWXRequest) { debugPrint("launch-app-from-h5 on android"); // do something here only for android after launch from wechat } else if (response is WeChatLaunchFromWXRequest) { debugPrint("launch-app-from-h5 on ios"); // do something here only for android after launch from wechat } // 2. Or handling responses together for android and ios if (response is WeChatLaunchFromWXRequest || response is WeChatShowMessageFromWXRequest) { debugPrint("launch-app-from-h5"); // do something here for both android and ios after launch from wechat } }); } ``` -------------------------------- ### Finding System Dependencies Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Checks for and imports the 'gtk+-3.0' package using PkgConfig. This ensures that GTK+ 3 development libraries are available for the build. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Analyze All Packages Source: https://github.com/openflutter/fluwx/blob/main/doc/DEVELOPMENT.md Run the Flutter analysis command on all packages within the monorepo using Melos. ```bash melos exec -- flutter analyze ``` -------------------------------- ### Test All Packages Source: https://github.com/openflutter/fluwx/blob/main/doc/DEVELOPMENT.md Execute the Flutter test command on all packages within the monorepo using Melos. ```bash melos exec -- flutter test ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/windows/runner/CMakeLists.txt Links necessary libraries, such as 'flutter' and 'flutter_wrapper_app', and the 'dwmapi.lib' for Windows-specific functionality. It also specifies include directories for the project. ```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}") ``` -------------------------------- ### Find System Libraries with PkgConfig Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/flutter/CMakeLists.txt This section uses PkgConfig to find and check for required system libraries like GTK, GLIB, and GIO. These are essential for the Flutter Linux embedding. ```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) ``` -------------------------------- ### Define Executable Target and Source Files Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/windows/runner/CMakeLists.txt Defines the main executable for the Windows runner and lists all its source files, including C++ files, generated plugin registration, and resource files. This is where new source files should be added. ```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" ) ``` -------------------------------- ### Add Include Directories Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/runner/CMakeLists.txt Specifies include directories for the application target, allowing it to find header files. ```cmake target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Enabling Modern CMake Behaviors Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Explicitly opts into modern CMake features to avoid warnings and ensure compatibility with newer CMake versions. This promotes best practices in CMake usage. ```cmake cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Including Runner Build Rules Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Includes the build rules for the application runner from the 'runner' subdirectory. This allows the main application logic to be built. ```cmake add_subdirectory("runner") ``` -------------------------------- ### WeChatImage Constructors Source: https://github.com/openflutter/fluwx/blob/main/doc/BASIC_KNOWLEDGE.md Demonstrates the different ways to construct a WeChatImage object for sharing. Supports network, file, asset, and binary image sources. ```dart WeChatImage.network(String source, {String suffix}); ``` ```dart WeChatImage.file(File source, {String suffix = ".jpeg"}); ``` ```dart WeChatImage.asset(String source, {String suffix}); ``` ```dart WeChatImage.binary(Uint8List source, {String suffix = ".jpeg"}); ``` -------------------------------- ### Configure Info.plist for WeChat on iOS Source: https://github.com/openflutter/fluwx/blob/main/doc/QA.md Add these keys to your app's Info.plist file to ensure WeChat can be queried and launched on iOS. This is necessary for features like sharing and login. ```xml LSApplicationQueriesSchemes weixin NSAppTransportSecurity NSAllowsArbitraryLoads ``` -------------------------------- ### Runtime Output Directory Configuration Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/CMakeLists.txt Sets the runtime output directory for the main executable to a subdirectory within the build directory. This prevents users from accidentally running the unbundled executable. ```cmake # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of # the default top-level location. set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Configuring Runtime Library Path Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Sets the runtime search path for libraries to include the 'lib' directory relative to the executable. This ensures that bundled libraries can be found at runtime. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Project and Executable Naming Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/CMakeLists.txt Sets the minimum CMake version, project name, executable name, and application identifier. This is essential for defining the project's basic properties. ```cmake cmake_minimum_required(VERSION 3.13) 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 "fluwx_example") # The unique GTK application identifier for this application. See: # https://wiki.gnome.org/HowDoI/ChooseApplicationID set(APPLICATION_ID "com.jarvan.fluwx_example") ``` -------------------------------- ### Including Flutter Build Rules Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Includes the Flutter build rules from the bundled 'flutter' directory. This is essential for integrating Flutter's build system with the native build. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Cross-Building Sysroot Configuration Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/CMakeLists.txt Configures the sysroot and find root path settings for cross-compilation. This is used when building for a different architecture or environment. ```cmake # 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() ``` -------------------------------- ### Including Generated Plugin Rules Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Includes the CMake rules for building generated plugins. This is automatically managed and crucial for integrating native plugin code. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Setting Executable and Application IDs Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Defines the name of the executable binary and the unique application identifier for the GTK application. These are crucial for application deployment and system integration. ```cmake set(BINARY_NAME "fluwx_example") set(APPLICATION_ID "com.jarvan.fluwx_example") ``` -------------------------------- ### Define Flutter Library Headers Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/flutter/CMakeLists.txt Lists the header files for the Flutter Linux embedding. The `list_prepend` function is used to add the correct include path. ```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/") ``` -------------------------------- ### Flutter and Plugin Integration Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/CMakeLists.txt Includes the Flutter managed directory and generated plugin CMake files. This integrates Flutter's build system and plugin configurations into the project. ```cmake # Flutter library and tool build rules. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Setting Runtime Output Directory Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Configures the runtime output directory for the executable to a specific subdirectory. This prevents users from accidentally running the unbundled executable. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run") ``` -------------------------------- ### Initiate WeChat Payment Source: https://github.com/openflutter/fluwx/blob/main/doc/PAYMENT.md Call the fluwx.pay method with a Payment object containing all necessary details obtained from the server. Ensure all string parameters are correctly formatted. ```dart fluwx.pay( which: Payment( appId: result['appid'].toString(), partnerId: result['partnerid'].toString(), prepayId: result['prepayid'].toString(), packageValue: result['package'].toString(), nonceStr: result['noncestr'].toString(), timestamp: result['timestamp'], sign: result['sign'].toString(), )); ``` -------------------------------- ### Link Dependencies Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/runner/CMakeLists.txt Links the necessary libraries for the application target. This includes the Flutter engine and GTK libraries. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Import Fluwx with Alias to Avoid Naming Conflicts Source: https://github.com/openflutter/fluwx/blob/main/doc/QA.md If ResponseType from fluwx conflicts with other packages like Dio, use an alias during import to resolve the naming collision. ```dart import 'package:fluwx/fluwx.dart' as fluwx; ``` -------------------------------- ### Check Kotlin and Gradle Versions for Android Build Failures Source: https://github.com/openflutter/fluwx/blob/main/doc/QA.md Ensure your project's Kotlin and Gradle plugin versions are compatible with fluwx. Mismatched versions can lead to build errors. ```gradle buildscript { ······ ext.kotlin_version = '1.3.11' ······ } classpath 'com.android.tools.build:gradle:3.2.1' ``` -------------------------------- ### Create Flutter Interface Library Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/flutter/CMakeLists.txt Defines an INTERFACE library for Flutter, setting include directories and linking against the Flutter library and system dependencies. ```cmake 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 ) ``` -------------------------------- ### Define Executable Target Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/runner/CMakeLists.txt Defines the main executable for the application. Source files, including generated plugin registrants, are listed here. Ensure BINARY_NAME is consistent with the top-level CMakeLists.txt for `flutter run` compatibility. ```cmake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) ``` -------------------------------- ### Add Preprocessor Definitions for Build Version Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/windows/runner/CMakeLists.txt Adds preprocessor definitions to the build configuration to include version information of the Flutter project. This allows the application to access version details at compile time. ```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}") ``` -------------------------------- ### Applying Standard Compilation Settings Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Defines a function to apply common compilation settings to targets, including C++ standard, warning levels, optimization, and NDEBUG definition. This promotes code quality and performance. ```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() ``` -------------------------------- ### Add Fluwx Dependency to pubspec.yaml Source: https://github.com/openflutter/fluwx/blob/main/README.md Include the fluwx package in your pubspec.yaml file. Replace ^${latestVersion} with the actual latest version number from pub.dev. ```yaml dependencies: fluwx: ^${latestVersion} ``` -------------------------------- ### Preserve OkHttp Public Suffix Package Source: https://github.com/openflutter/fluwx/blob/main/packages/_shared/android/consumer-proguard-rules.txt This rule preserves the package name for OkHttp's Public Suffix Database implementation, as a resource is loaded using a relative path. ```proguard -keeppackagenames okhttp3.internal.publicsuffix.* -adaptresourcefilenames okhttp3/internal/publicsuffix/PublicSuffixDatabase.gz ``` -------------------------------- ### Configure Flutter Library and Paths Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/flutter/CMakeLists.txt Sets variables for the Flutter library, ICU data file, project build directory, and AOT library path. These are published to the parent scope for use in other build 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) ``` -------------------------------- ### Standard Compilation Settings Function Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/CMakeLists.txt Defines a function to apply standard compilation settings like C++ standard, warning levels, optimization, and NDEBUG definition. This promotes consistent build configurations. ```cmake # Compilation settings that should be applied to most targets. # # Be cautious about adding new options here, as plugins use this function by # default. In most cases, you should add new options to specific targets instead # of modifying this function. 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() ``` -------------------------------- ### Custom Command for Flutter Tool Backend Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/flutter/CMakeLists.txt This custom command invokes the Flutter tool backend script to generate necessary files like the Flutter library and headers. A phony target is used to ensure it runs 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 Application ID Preprocessor Definition Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/runner/CMakeLists.txt Adds a preprocessor definition for the application ID, making it available during compilation. ```cmake add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Keep WeChat SDK Classes Source: https://github.com/openflutter/fluwx/blob/main/packages/_shared/android/consumer-proguard-rules.txt These rules ensure that classes from the WeChat SDK (com.tencent.mm.opensdk, com.tencent.wxop, com.tencent.mm.sdk) are not removed or obfuscated by ProGuard. ```proguard -keep class com.tencent.mm.opensdk.** {*;} -keep class com.tencent.wxop.** {*;} -keep class com.tencent.mm.sdk.** {*;} ``` -------------------------------- ### Define list_prepend Function in CMake Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/flutter/CMakeLists.txt This custom CMake function prepends a prefix to each element in a list. It's used here as a workaround for older CMake versions that lack the list(TRANSFORM ... PREPEND ...) command. ```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() ``` -------------------------------- ### Build Type Configuration Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/CMakeLists.txt Sets the default build type to 'Debug' if not already defined, and restricts it to 'Debug', 'Profile', or 'Release'. This controls the compilation mode. ```cmake # 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() ``` -------------------------------- ### Register WxAPI with Fluwx Source: https://github.com/openflutter/fluwx/blob/main/README.md Register your app's API with Fluwx using your WeChat App ID and a universal link for iOS. This should be done as early as possible in your application's lifecycle. ```dart Fluwx fluwx = Fluwx(); final success = fluwx.registerApi(appId: "wxd930ea5d5a228f5f",universalLink: "https://your.univerallink.com/link/"); print("register API success: $success"); ``` -------------------------------- ### Modern CMake Policy and RPATH Configuration Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/CMakeLists.txt Explicitly opts into modern CMake behaviors and sets the RPATH to load bundled libraries from the 'lib/' directory relative to the binary. This ensures compatibility and proper library loading. ```cmake # 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") ``` -------------------------------- ### Cross-Building Sysroot Configuration Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Configures CMake for cross-compilation by setting the sysroot and adjusting find root path modes. This is essential when building for a different architecture or environment. ```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() ``` -------------------------------- ### Ignore OkHttp Platform Warnings Source: https://github.com/openflutter/fluwx/blob/main/packages/_shared/android/consumer-proguard-rules.txt These rules suppress warnings for OkHttp platform-related classes and security providers (Conscrypt, Bouncycastle, OpenJSSE) when they are not available or not used on the JVM. ```proguard -dontwarn okhttp3.internal.platform.** -dontwarn org.conscrypt.** -dontwarn org.bouncycastle.** -dontwarn org.openjsse.** ``` -------------------------------- ### Add Flutter Build Tool Dependency Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/windows/runner/CMakeLists.txt Ensures that the Flutter build tool's assembly process is completed before the application target is built. This is a mandatory step for Flutter projects. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Remove AppDelegate Overrides for WeChat Handling (iOS) Source: https://github.com/openflutter/fluwx/blob/main/doc/QA.md Since fluwx 1.0.0, overriding AppDelegate methods for WeChat URL handling is no longer necessary. Remove these if they were previously added to avoid conflicts. ```objective-c - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [WXApi handleOpenURL:url delegate:[FluwxResponseHandler defaultManager]]; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { return [WXApi handleOpenURL:url delegate:[FluwxResponseHandler defaultManager]]; } ``` -------------------------------- ### Kotlin Coroutines ServiceLoader Support Source: https://github.com/openflutter/fluwx/blob/main/packages/_shared/android/consumer-proguard-rules.txt These rules are for ServiceLoader support in Kotlin Coroutines, ensuring specific classes are not mangled by ProGuard. ```proguard -keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {} -keepnames class kotlinx.coroutines.CoroutineExceptionHandler {} -keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {} -keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {} ``` -------------------------------- ### Add Flutter Assemble Target Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/flutter/CMakeLists.txt Creates a custom target 'flutter_assemble' that depends on the generated Flutter library and its headers, ensuring they are built before other targets that might use them. ```cmake add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Setting Default Build Type Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/linux/CMakeLists.txt Sets the default build type to 'Debug' if not already specified. This ensures a consistent build mode for development. Supported types are Debug, Profile, and Release. ```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() ``` -------------------------------- ### Add Flutter library interface target in CMake Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/flutter/CMakeLists.txt This creates an INTERFACE library target for Flutter, specifying include directories and linking against system libraries found via PkgConfig. It also adds a dependency on the flutter_assemble target. ```cmake 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) ``` -------------------------------- ### Flutter Assemble Dependency Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx_no_pay/example/linux/CMakeLists.txt Adds a dependency on 'flutter_assemble' to the main executable. This ensures that the Flutter assets and code are assembled before the application is built. ```cmake # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Share Content Source: https://github.com/openflutter/fluwx/blob/main/doc/SHARE.md This function allows you to share text content to WeChat. You can specify the destination scene, which can be SESSION, TIMELINE, or FAVORITE. ```APIDOC ## Share Content ### Description This function allows you to share text content to WeChat. You can specify the destination scene, which can be SESSION, TIMELINE, or FAVORITE. ### Method Signature ```dart fluwx.share(WeChatShareTextModel("source text", scene: WeChatScene.SESSION)); ``` ### Parameters - `model`: An instance of a WeChat share model (e.g., `WeChatShareTextModel`). - `scene`: The destination scene for the share. Possible values are: - `WeChatScene.session`: Share to a WeChat conversation. - `WeChatScene.timeline`: Share to WeChat Moments. - `WeChatScene.favorite`: Share to WeChat Favorites. ### Supported Share Models - `WeChatShareTextModel` - `WeChatShareMiniProgramModel` - `WeChatShareImageModel` - `WeChatShareMusicModel` - `WeChatShareVideoModel` - `WeChatShareWebPageModel` - `WeChatShareFileModel` ``` -------------------------------- ### Share Text Content Source: https://github.com/openflutter/fluwx/blob/main/doc/SHARE.md Use this to share simple text messages. The destination can be SESSION (default), TIMELINE, or FAVORITE. ```dart fluwx.share(WeChatShareTextModel("source text", scene: WeChatScene.SESSION)); ``` -------------------------------- ### Subscribe to WeChat Responses Source: https://github.com/openflutter/fluwx/blob/main/doc/BASIC_KNOWLEDGE.md Use this to subscribe to and unsubscribe from responses from WeChat API calls. The listener will be called with the response object. ```dart var listener = (response) { if (response is WeChatAuthResponse) { } }; fluwx.addSubscriber(listener); // subscribe response from WeChat fluwx.removeSubscriber(listener);// unsubscribe response from WeChat ``` ```dart var cancelable = fluwx.addSubscriber(listener); cancelable.cancel(); // unsubscribe response from WeChat ``` -------------------------------- ### Ensure Super Call in AppDelegate Overrides (iOS) Source: https://github.com/openflutter/fluwx/blob/main/doc/QA.md If you must override AppDelegate's URL handling methods, ensure that the superclass methods are called to maintain proper application functionality. ```objective-c - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [super application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { return [super application:application openURL:url options:options]; } ``` -------------------------------- ### WeChat Share Scene Enum Source: https://github.com/openflutter/fluwx/blob/main/doc/SHARE.md Defines the possible destinations for sharing content within WeChat. ```dart ///[WeChatScene.session]会话 ///[WeChatScene.timeline]朋友圈 ///[WeChatScene.favorite]收藏 enum WeChatScene { session, timeline, favorite } ``` -------------------------------- ### Handle WeChat Response Subscription Cancellation Source: https://github.com/openflutter/fluwx/blob/main/doc/QA.md To prevent issues like multiple calls to listeners, ensure that StreamSubscriptions are cancelled when no longer needed, typically in the dispose method. ```dart StreamSubscription _wxlogin; _wxlogin = fluwx.responseFromAuth.listen((val) {}) @override void dispose() { _wxlogin.cancel(); } ``` -------------------------------- ### Keep Kotlin Coroutines Main Dispatcher Factory Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/android/consumer-proguard-rules.txt This rule preserves the 'MainDispatcherFactory' class from Kotlin Coroutines, which is necessary for the ServiceLoader mechanism to find and use the main dispatcher on Android. ```proguard -keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {} ``` -------------------------------- ### Keep Kotlin Coroutines Exception Handling Classes Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/android/consumer-proguard-rules.txt These rules ensure that Kotlin Coroutines' exception handling-related classes are not obfuscated, maintaining the integrity of error handling mechanisms. ```proguard -keepnames class kotlinx.coroutines.CoroutineExceptionHandler {} -keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {} -keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {} ``` -------------------------------- ### Disable Conflicting Windows Macros Source: https://github.com/openflutter/fluwx/blob/main/packages/fluwx/example/windows/runner/CMakeLists.txt Disables Windows-specific macros like NOMINMAX that might conflict with standard C++ library functions, preventing potential naming collisions. ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") ``` -------------------------------- ### Ignore Animal Sniffer Warnings Source: https://github.com/openflutter/fluwx/blob/main/packages/_shared/android/consumer-proguard-rules.txt This rule suppresses warnings from the Animal Sniffer compileOnly dependency, which is used to ensure API compatibility with older Java versions. ```proguard -dontwarn org.codehaus.mojo.animal_sniffer.* ``` -------------------------------- ### Ignore JSR 305 Annotations Warnings Source: https://github.com/openflutter/fluwx/blob/main/packages/_shared/android/consumer-proguard-rules.txt This rule suppresses warnings related to JSR 305 annotations, which are used for embedding nullability information and are not critical for runtime. ```proguard -dontwarn javax.annotation.** ``` -------------------------------- ### Keep Volatile Fields in Kotlin Coroutines Source: https://github.com/openflutter/fluwx/blob/main/packages/_shared/android/consumer-proguard-rules.txt This rule preserves volatile fields in Kotlin Coroutines classes, which are often updated with AFU (Ahead-of-Time compilation) and should not be mangled. ```proguard -keepclassmembernames class kotlinx.** { volatile ; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.