### Installation Bundle Directory Setup Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/example/linux/CMakeLists.txt Configures the installation prefix to create a relocatable bundle and ensures the build bundle directory is clean. ```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) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/connectivity_plus/connectivity_plus/example/linux/CMakeLists.txt Sets up the minimum CMake version, project name, and binary/application IDs. It also configures the installation path for libraries. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "example") set(APPLICATION_ID "io.flutter.plugins.example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Installation Configuration for Executable and Data Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/network_info_plus/network_info_plus/example/windows/CMakeLists.txt Sets up installation directories and installs the main executable, ICU data, and Flutter library. ```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) ``` -------------------------------- ### Basic CMake Setup for Flutter Plugin Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/network_info_plus/network_info_plus/example/linux/CMakeLists.txt Sets up the minimum CMake version, project name, and binary/application IDs. Configures build type and installation path. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "example") set(APPLICATION_ID "io.flutter.plugins.example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Configure build 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() ``` -------------------------------- ### Installation Bundle Configuration Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/example/linux/CMakeLists.txt Configures the installation process, setting up the build bundle directory and initial cleanup. ```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) ``` -------------------------------- ### Run Sensors Plus Example App Source: https://github.com/fluttercommunity/plus_plugins/blob/main/CONTRIBUTING.md Navigate to the example directory of the sensors_plus plugin and run the example application using `flutter run`. Changes made locally to plugins are automatically reflected in example applications when using Melos. ```bash cd packages/sensors_plus/sensors_plus/example flutter run ``` -------------------------------- ### Installation Bundle Configuration Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/connectivity_plus/connectivity_plus/example/linux/CMakeLists.txt Configures the installation process to create a relocatable bundle. It sets the install prefix and ensures the build bundle directory is clean before installation. ```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") ``` -------------------------------- ### Define Installation Paths Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/package_info_plus/package_info_plus/example/linux/CMakeLists.txt Sets the destination directories for data and libraries within the installation bundle. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Install Application Executable and Data Files Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/connectivity_plus/connectivity_plus/example/linux/CMakeLists.txt Installs the application executable, ICU data file, Flutter library, and bundled plugin libraries to the specified 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) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Define Installation Directories Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/example/windows/CMakeLists.txt Sets variables for the installation directories of bundle data and libraries. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Get Application Package Information with package_info_plus Source: https://context7.com/fluttercommunity/plus_plugins/llms.txt Query app name, package name, version, build number, and installer store. Essential for displaying version info and determining app distribution source. ```dart import 'package:package_info_plus/package_info_plus.dart'; // Ensure binding is initialized if called before runApp() WidgetsFlutterBinding.ensureInitialized(); // Get package info PackageInfo packageInfo = await PackageInfo.fromPlatform(); String appName = packageInfo.appName; // e.g., "My App" String packageName = packageInfo.packageName; // e.g., "com.example.myapp" String version = packageInfo.version; // e.g., "1.2.3" String buildNumber = packageInfo.buildNumber; // e.g., "42" print('$appName v$version ($buildNumber)'); // Determine installer source for directing users to correct store String? installerStore = packageInfo.installerStore; switch (installerStore) { case 'com.android.vending': print('Installed from Google Play Store'); break; case 'com.apple': print('Installed from App Store'); break; case 'com.apple.testflight': print('Installed from TestFlight'); break; case 'com.amazon.venezia': print('Installed from Amazon Appstore'); break; default: print('Installed manually or from unknown source'); } ``` -------------------------------- ### Install Executable Target Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/example/windows/CMakeLists.txt Installs the main executable target to the runtime destination. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Install Application Executable Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/example/linux/CMakeLists.txt Installs the application executable to the runtime destination within the bundle. ```cmake 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) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/example/linux/CMakeLists.txt Initializes the CMake project, sets the minimum version, and defines the project name and languages. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) ``` -------------------------------- ### Install Flutter Library Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/example/windows/CMakeLists.txt Installs the Flutter library file to the bundle library directory. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Get Installer Store Information Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/package_info_plus/package_info_plus/README.md Obtain the name of the app store that installed the application. This property returns `null` on macOS, Linux, Windows, and Web. ```dart PackageInfo packageInfo = await PackageInfo.fromPlatform(); String? installerStore = packageInfo.installerStore; ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/example/windows/CMakeLists.txt Initializes CMake, sets the project name, and specifies the C++ standard. Ensures compatibility with modern C++ features. ```cmake cmake_minimum_required(VERSION 3.15) project(example LANGUAGES CXX) ``` -------------------------------- ### Configure Installation for In-Place Execution Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/example/windows/CMakeLists.txt Sets up installation rules to copy files next to the executable for in-place execution, particularly for Visual Studio builds. This ensures the application can run correctly without needing a separate bundle. ```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) ``` -------------------------------- ### Installing Application Artifacts Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/example/linux/CMakeLists.txt Installs the main executable, Flutter ICU data, and the Flutter library to the bundle. ```cmake 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) ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/example/linux/CMakeLists.txt Installs any bundled plugin libraries to the bundle's library directory if they exist. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Executable and Libraries Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/share_plus/share_plus/example/linux/CMakeLists.txt Installs the application executable, ICU data, Flutter library, and bundled plugin libraries to the specified bundle directories. ```cmake 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) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Installation Configuration for Executable Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/connectivity_plus/connectivity_plus/example/windows/CMakeLists.txt Configures installation paths for the executable and its support files, ensuring they are placed next to the executable for in-place running. Sets Visual Studio specific install-to-default-build. ```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}") ``` -------------------------------- ### Configure Installation Bundle Directory Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/package_info_plus/package_info_plus/example/linux/CMakeLists.txt Sets the directory for the build bundle and forces the CMAKE_INSTALL_PREFIX if it's not initialized. ```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 Native Assets Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/example/windows/CMakeLists.txt Installs native assets provided by build.dart from all packages to the bundle library directory. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installing AOT Library Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library on non-Debug 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() ``` -------------------------------- ### Share from iPad with sharePositionOrigin Source: https://context7.com/fluttercommunity/plus_plugins/llms.txt On iPad, `sharePositionOrigin` must be provided to prevent crashes. This example shows how to get the render box and share from its position. ```dart // iPad requires sharePositionOrigin to prevent crashes Builder( builder: (BuildContext context) { return ElevatedButton( onPressed: () async { final box = context.findRenderObject() as RenderBox; await SharePlus.instance.share( ShareParams( text: 'Shared from iPad', sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size, ), ); }, child: Text('Share'), ); }, ); ``` -------------------------------- ### Get Battery Level and State Changes Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/README.md Import the package and instantiate `Battery`. Access the current battery level using `batteryLevel` and listen for state changes via `onBatteryStateChanged`. This example demonstrates basic usage for retrieving battery information. ```dart // Import package import 'package:battery_plus/battery_plus.dart'; // Instantiate it var battery = Battery(); // Access current battery level print(await battery.batteryLevel); // Be informed when the state (full, charging, discharging) changes battery.onBatteryStateChanged.listen((BatteryState state) { // Do something with new state }); // Check if device in battery save mode // Currently available on Android, iOS, macOS and Windows platforms only print(await battery.isInBatterySaveMode); ``` -------------------------------- ### Install ICU Data File Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/example/windows/CMakeLists.txt Installs the ICU data file to the bundle data directory. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Setting Binary Name and Install RPATH Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/network_info_plus/network_info_plus/example/windows/CMakeLists.txt Defines the executable binary name and configures the installation runtime path for libraries. ```cmake set(BINARY_NAME "example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Clean Build Bundle Directory on Install Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/package_info_plus/package_info_plus/example/linux/CMakeLists.txt Installs a custom command to remove the build bundle directory before installation, ensuring a clean state. ```cmake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/example/linux/CMakeLists.txt Installs the Flutter assets directory to the bundle, ensuring it's re-copied on each build to avoid stale files. ```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) ``` -------------------------------- ### Start ChromeDriver for Web Tests Source: https://github.com/fluttercommunity/plus_plugins/blob/main/CONTRIBUTING.md Before running web integration tests, start ChromeDriver on the specified port. ```bash chromedriver --port=4444 ``` -------------------------------- ### Check and Launch Activity with Android Intent Source: https://context7.com/fluttercommunity/plus_plugins/llms.txt This example demonstrates how to check if any application on the device can handle a given intent before attempting to launch it. It also retrieves details about the activity that will handle the intent. ```dart // Check if an activity can handle the intent final intent = AndroidIntent( action: 'action_view', data: Uri.encodeFull('http://example.com'), ); bool canHandle = await intent.canResolveActivity(); if (canHandle) { final details = await intent.getResolvedActivity(); print('Will be handled by: ${details.packageName}'); await intent.launch(); } else { print('No app can handle this intent'); } ``` -------------------------------- ### Install AOT Library (Non-Debug Builds) Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compilation library to the bundle data directory, but only for Profile and Release configurations. ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Set Installation Prefix for Visual Studio Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/example/windows/CMakeLists.txt Configures the installation prefix for Visual Studio builds to be adjacent to the executable, allowing in-place running. ```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 AOT Library Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/connectivity_plus/connectivity_plus/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library for Profile and Release builds. This optimizes runtime performance for non-debug configurations. ```cmake # Install the AOT library on non-Debug builds only. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Run Flutter Driver End-to-End Tests Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/android_alarm_manager_plus/README.md Execute Flutter Driver end-to-end tests from the example directory. This command runs the specified test file for comprehensive testing. ```bash flutter driver test_driver/android_alarm_manager_plus_e2e.dart ``` -------------------------------- ### Query if an Activity can Handle an Intent Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/android_intent_plus/README.md This example shows how to check if any activity on the device can handle a given intent before attempting to launch it. It requires importing the `android_intent_plus` package. Note that for Android 11 and above, you may need to declare package visibility queries in your `AndroidManifest.xml`. ```dart import 'package:android_intent_plus/android_intent.dart'; final intent = AndroidIntent( action: 'action_view', data: Uri.encodeFull('http://'), ); // can this intent be handled by an activity final canHandleIntent = await intent.canResolveActivity(); // get the details of the activity that will handle this intent final details = await intent.getResolvedActivity(); print(details.packageName); // prints com.google.chrome ``` -------------------------------- ### Install AOT Library (Non-Debug) Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the bundle's library directory, but only for non-Debug build types. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Bootstrap Project Dependencies with Melos Source: https://github.com/fluttercommunity/plus_plugins/blob/main/CONTRIBUTING.md Bootstrap the project dependencies using Melos. This command locally links all project dependencies, enabling plugins, examples, and tests to build from the local clone without manual dependency overrides. ```bash melos bootstrap ``` -------------------------------- ### Configure Install RPATH Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/package_info_plus/package_info_plus/example/linux/CMakeLists.txt Sets the RPATH for installed executables to include the library directory relative to the executable. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Install Assets and AOT Library Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/connectivity_plus/connectivity_plus/example/linux/CMakeLists.txt Installs the Flutter assets directory and the AOT (Ahead-Of-Time) compiled library for non-Debug builds. The assets directory is re-copied on each build to ensure freshness. ```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 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() ``` -------------------------------- ### Install Flutter ICU Data and Library Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/example/linux/CMakeLists.txt Installs the Flutter ICU data file and the main Flutter library to the bundle's data and library directories. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Set Flutter Library and Headers Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/example/windows/flutter/CMakeLists.txt Defines the Flutter library and its header files, publishing them to the parent scope for the install step. ```cmake 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) ``` -------------------------------- ### Get Platform-Specific Device Info Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/README.md Import the package, instantiate DeviceInfoPlugin, and use getters for Android, iOS, or Web to retrieve specific device details. This is useful for tailoring app behavior or displaying device information. ```dart import 'package:device_info_plus/device_info_plus.dart'; DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; print('Running on ${androidInfo.model}'); // e.g. "Moto G (4)" IosDeviceInfo iosInfo = await deviceInfo.iosInfo; print('Running on ${iosInfo.utsname.machine}'); // e.g. "iPod7,1" WebBrowserInfo webBrowserInfo = await deviceInfo.webBrowserInfo; print('Running on ${webBrowserInfo.userAgent}'); // e.g. "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0" ``` -------------------------------- ### Get App Package Information Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/package_info_plus/package_info_plus/README.md Retrieve essential application package details like app name, package name, version, and build number. Ensure `WidgetsFlutterBinding.ensureInitialized()` is called before `PackageInfo.fromPlatform()` if it's invoked before `runApp()`. ```dart import 'package:package_info_plus/package_info_plus.dart'; ... // Be sure to add this line if `PackageInfo.fromPlatform()` is called before runApp() WidgetsFlutterBinding.ensureInitialized(); ... PackageInfo packageInfo = await PackageInfo.fromPlatform(); String appName = packageInfo.appName; String packageName = packageInfo.packageName; String version = packageInfo.version; String buildNumber = packageInfo.buildNumber; ``` -------------------------------- ### Open App in Play Store with Android Intent Source: https://context7.com/fluttercommunity/plus_plugins/llms.txt This code snippet demonstrates how to open a specific application in the Google Play Store using its package name. This is useful for directing users to an app's page for reviews or installation. ```dart // Open app in Play Store if (Platform.isAndroid) { final intent = AndroidIntent( action: 'action_view', data: 'https://play.google.com/store/apps/details?id=com.example.app', ); await intent.launch(); } ``` -------------------------------- ### Configure Flutter GTK Dependencies (CMake) Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/example/linux/flutter/CMakeLists.txt This section finds and checks for required system-level dependencies using PkgConfig, such as GTK, GLib, GIO, and BLKID. These are essential for the Flutter engine to interact with the Linux desktop environment. Ensure these packages are installed on your system. ```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) pkg_check_modules(BLKID REQUIRED IMPORTED_TARGET blkid) ``` -------------------------------- ### Flutter Tool Backend Custom Command Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/network_info_plus/network_info_plus/example/windows/flutter/CMakeLists.txt Configures a custom command to run the Flutter tool backend. This command is designed to run every time due to the use of a phony output file, as there's no direct way to get a full input/output list from the Flutter tool. ```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" windows-x64 $ VERBATIM ) ``` -------------------------------- ### System Dependencies and Application Build Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/example/linux/CMakeLists.txt Finds PkgConfig and GTK, defines the application ID, and adds the main executable with its source files. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) apply_standard_settings(${BINARY_NAME}) target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Check Current Connectivity Types Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/connectivity_plus/connectivity_plus/README.md Use this method to get a list of currently available network connectivity types. Note that system behavior may vary, for example, on Android, Wi-Fi is returned if both Wi-Fi and mobile are active. VPN connectivity is reported as 'other' on iOS and macOS. ```dart import 'package:connectivity_plus/connectivity_plus.dart'; final List connectivityResult = await (Connectivity().checkConnectivity()); // This condition is for demo purposes only to explain every connection type. // Use conditions which work for your requirements. if (connectivityResult.contains(ConnectivityResult.mobile)) { // Mobile network available. } else if (connectivityResult.contains(ConnectivityResult.wifi)) { // Wi-fi is available. // Note for Android: // When both mobile and Wi-Fi are turned on system will return Wi-Fi only as active network type } else if (connectivityResult.contains(ConnectivityResult.ethernet)) { // Ethernet connection available. } else if (connectivityResult.contains(ConnectivityResult.vpn)) { // Vpn connection active. // Note for iOS and macOS: // There is no separate network interface type for [vpn]. // It returns [other] on any device (also simulator) } else if (connectivityResult.contains(ConnectivityResult.bluetooth)) { // Bluetooth connection available. } else if (connectivityResult.contains(ConnectivityResult.satellite)) { // Carrier-provided satellite network available } else if (connectivityResult.contains(ConnectivityResult.other)) { // Connected to a network which is not in the above mentioned networks. } else if (connectivityResult.contains(ConnectivityResult.none)) { // No available network types } ``` -------------------------------- ### System Dependencies and Application Build Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/connectivity_plus/connectivity_plus/example/linux/CMakeLists.txt Finds PkgConfig and GTK, defines the application ID, and builds the main executable with specified source files and linked libraries. It also sets runtime output directory. ```cmake # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") # Application build add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) apply_standard_settings(${BINARY_NAME}) target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) add_dependencies(${BINARY_NAME} flutter_assemble) # 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" ) ``` -------------------------------- ### Set up Flutter Library Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/share_plus/share_plus/example/windows/flutter/CMakeLists.txt Configures the Flutter library and its headers for the build. Ensure FLUTTER_LIBRARY and FLUTTER_ICU_DATA_FILE are correctly set. ```cmake cmake_minimum_required(VERSION 3.15) 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" ) 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) ``` -------------------------------- ### Run Package Info Plus Web Tests Source: https://github.com/fluttercommunity/plus_plugins/blob/main/CONTRIBUTING.md Execute integration tests for the package_info_plus plugin on the Chrome web environment using flutter drive. ```bash cd packages/package_info_plus/package_info_plus/example flutter drive \ --driver ./integration_test/driver.dart \ --target ./integration_test/package_info_plus_web_test.dart \ -d chrome ``` -------------------------------- ### Configure Build Options Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/connectivity_plus/connectivity_plus/example/windows/CMakeLists.txt Sets up build configurations (Debug, Profile, Release) based on whether the generator is multi-config. This ensures the correct build types are available. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Configure build options. 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() ``` -------------------------------- ### Find and Check System Libraries Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/connectivity_plus/connectivity_plus/example/linux/flutter/CMakeLists.txt Uses PkgConfig to find and check for required system libraries: gtk+-3.0, glib-2.0, gio-2.0, and blkid. These are essential for the GTK backend. ```cmake # === Flutter Library === # System-level dependencies. 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) pkg_check_modules(BLKID REQUIRED IMPORTED_TARGET blkid) ``` -------------------------------- ### Conventional Commit Message Example Source: https://github.com/fluttercommunity/plus_plugins/blob/main/CONTRIBUTING.md Example of a pull request title following the Conventional Commits specification, including the package name. ```text fix(sensor_plus): fixed a bug! ``` -------------------------------- ### Launch Application Details Settings Intent Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/android_intent_plus/README.md This snippet demonstrates launching the Android activity for application details settings. Replace 'com.example.app' with the actual application ID. This is useful for directing users to an app's settings page. ```dart if (platform.isAndroid) { final AndroidIntent intent = AndroidIntent( action: 'action_application_details_settings', data: 'package:com.example.app', // replace com.example.app with your applicationId ); await intent.launch(); } ``` -------------------------------- ### Application Executable Build Configuration Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/example/linux/CMakeLists.txt Defines the main executable target, applies standard settings, and links necessary libraries. ```cmake # Application build add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) apply_standard_settings(${BINARY_NAME}) target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Configure Connectivity Plus Plugin Build Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/connectivity_plus/connectivity_plus/windows/CMakeLists.txt Defines the project name, sets up the shared library for the plugin, and specifies compilation settings and include directories. This configuration is essential for building the native part of the connectivity_plus plugin. ```cmake cmake_minimum_required(VERSION 3.15) set(PROJECT_NAME "connectivity_plus") project(${PROJECT_NAME} LANGUAGES CXX) # This value is used when generating builds using this plugin, so it must # not be changed set(PLUGIN_NAME "connectivity_plus_plugin") add_library(${PLUGIN_NAME} SHARED "connectivity_plus_plugin.cpp" "network_manager.cpp" ) apply_standard_settings(${PLUGIN_NAME}) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin iphlpapi ) # List of absolute paths to libraries that should be bundled with the plugin set(connectivity_plus_bundled_libraries "" PARENT_SCOPE ) ``` -------------------------------- ### Application Build Configuration Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/share_plus/share_plus/example/linux/CMakeLists.txt Defines the main executable target, applies standard settings, links Flutter and GTK libraries, and adds a dependency on flutter_assemble. ```cmake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) apply_standard_settings(${BINARY_NAME}) target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Define Application Executable Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/package_info_plus/package_info_plus/example/windows/runner/CMakeLists.txt Adds the main executable target and lists all source files. New source files should be added here. The BINARY_NAME should be managed in the top-level CMakeLists.txt. ```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" ) ``` -------------------------------- ### Define Flutter Library and Headers Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/connectivity_plus/connectivity_plus/example/windows/flutter/CMakeLists.txt Configures the Flutter library and its associated header files. Ensures the library and ICU data are available in the parent scope for installation. ```cmake cmake_minimum_required(VERSION 3.15) 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") # === 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) ``` -------------------------------- ### Configure Build Options for Flutter Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/example/windows/CMakeLists.txt Sets up build configurations (Debug, Profile, Release) and handles multi-configuration generators. This ensures the project can be built for various Flutter build modes. ```cmake set(BINARY_NAME "example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Configure build options. 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}") ``` -------------------------------- ### Get WiFi Network Information with network_info_plus Source: https://context7.com/fluttercommunity/plus_plugins/llms.txt Retrieve SSID, BSSID, IP addresses, subnet mask, broadcast address, and gateway. Requires location permissions on Android/iOS for SSID. ```dart import 'package:network_info_plus/network_info_plus.dart'; final info = NetworkInfo(); // Get WiFi network name (SSID) // Note: Requires location permission on Android/iOS final wifiName = await info.getWifiName(); print('WiFi Name: $wifiName'); // e.g., "FooNetwork" // Get WiFi BSSID (router MAC address) final wifiBSSID = await info.getWifiBSSID(); print('WiFi BSSID: $wifiBSSID'); // e.g., "11:22:33:44:55:66" // Get device IP addresses final wifiIP = await info.getWifiIP(); print('IPv4 Address: $wifiIP'); // e.g., "192.168.1.43" final wifiIPv6 = await info.getWifiIPv6(); print('IPv6 Address: $wifiIPv6'); // e.g., "2001:0db8:85a3:0000:0000:8a2e:0370:7334" // Get network configuration details final wifiSubmask = await info.getWifiSubmask(); print('Subnet Mask: $wifiSubmask'); // e.g., "255.255.255.0" final wifiBroadcast = await info.getWifiBroadcast(); print('Broadcast: $wifiBroadcast'); // e.g., "192.168.1.255" final wifiGateway = await info.getWifiGatewayIP(); print('Gateway: $wifiGateway'); // e.g., "192.168.1.1" ``` -------------------------------- ### Get Generic Device Info Data Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/README.md Use the deviceInfo.data method to retrieve a generic map of device information, suitable for crash reporting. Note that this data is not guaranteed to be serializable (JSON compatible). ```dart import 'package:device_info_plus/device_info_plus.dart'; final deviceInfoPlugin = DeviceInfoPlugin(); final deviceInfo = await deviceInfoPlugin.deviceInfo; final allInfo = deviceInfo.data; ``` -------------------------------- ### Run Sensors Plus End-to-End Tests Source: https://github.com/fluttercommunity/plus_plugins/blob/main/CONTRIBUTING.md Execute end-to-end (e2e) tests for the sensors_plus plugin from its example directory. E2e tests communicate directly with Flutter and require the path to the integration test file. ```bash cd packages/sensors_plus/sensors_plus/example flutter test integration_test/sensors_plus_test.dart ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/package_info_plus/package_info_plus/example/windows/runner/CMakeLists.txt Applies a standard set of build settings to the application target. This can be customized for specific build requirements. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Access Battery Information with battery_plus Source: https://context7.com/fluttercommunity/plus_plugins/llms.txt Use this plugin to get the current battery level, charging status, and battery save mode. It also provides a stream to listen for real-time battery state changes. ```dart import 'package:battery_plus/battery_plus.dart'; // Instantiate the battery plugin var battery = Battery(); // Get current battery level (0-100) int level = await battery.batteryLevel; print('Battery level: $level%'); // Listen to battery state changes (charging, discharging, full, unknown) battery.onBatteryStateChanged.listen((BatteryState state) { switch (state) { case BatteryState.charging: print('Battery is charging'); break; case BatteryState.discharging: print('Battery is discharging'); break; case BatteryState.full: print('Battery is full'); break; case BatteryState.unknown: print('Battery state unknown'); break; } }); // Check if device is in battery save mode (Android, iOS, macOS, Windows only) bool saveMode = await battery.isInBatterySaveMode; print('Battery save mode: $saveMode'); ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/share_plus/share_plus/windows/CMakeLists.txt Applies common build settings defined at the application level. This simplifies configuration for plugins that don't require custom build flags. ```cmake apply_standard_settings(${PLUGIN_NAME}) ``` -------------------------------- ### Flutter and System Dependency Integration Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/device_info_plus/device_info_plus/example/linux/CMakeLists.txt Includes Flutter build rules and finds system-level GTK+ 3.0 libraries using PkgConfig. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") # Flutter library and tool build rules. add_subdirectory(${FLUTTER_MANAGED_DIR}) # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Configure Flutter Library Source: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/example/windows/flutter/CMakeLists.txt Sets up the Flutter library target, including include directories and linking against the Flutter Windows DLL. This is essential for integrating Flutter into a native Windows application. ```cmake cmake_minimum_required(VERSION 3.15) 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") # === 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" ) 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) ``` -------------------------------- ### Publish Packages to pub.dev Source: https://github.com/fluttercommunity/plus_plugins/blob/main/CONTRIBUTING.md After a successful dry run and review, use this command to publish the packages to pub.dev. The `--no-dry-run` flag ensures the actual publishing occurs, and `--git-tag-version` automatically creates and tags a Git commit for the release. ```bash melos publish --no-dry-run --git-tag-version ```