### Install Application Binary Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Installs the main application binary to the root of the installation prefix. This makes the executable available in the bundle. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Installation Configuration Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/windows/CMakeLists.txt Configures installation paths and components for the application executable, data files, libraries, and native assets. ```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) ``` ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` ```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) ``` ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Library Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Installs the main Flutter library file to the 'lib' subdirectory of the installation bundle. This makes the core Flutter runtime available. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Iterates through a list of bundled plugin libraries and installs each one to the 'lib' subdirectory of the installation bundle. This ensures all necessary plugin code is included. ```cmake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Clean Build Bundle on Install Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Installs a code block that removes the build bundle directory before installation. This ensures a clean installation by removing any previous build artifacts. ```cmake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Installation Bundle Directory Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Configures the installation prefix to be a 'bundle' directory within the project's binary directory. This is the default behavior for creating a relocatable application 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() ``` -------------------------------- ### Project and CMake Version Setup Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/windows/CMakeLists.txt Sets the minimum required CMake version and the project name. It also explicitly opts into modern CMake behaviors. ```cmake cmake_minimum_required(VERSION 3.14) project(internet_connection_checker_plus_example LANGUAGES CXX) ``` ```cmake set(BINARY_NAME "internetcheck-win32") ``` ```cmake cmake_policy(VERSION 3.14...3.25) ``` -------------------------------- ### Install Native Assets Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Installs native assets provided by the build.dart script into the 'lib' subdirectory of the installation bundle. This ensures that any platform-specific assets are correctly deployed. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Runtime Library Path Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Configures the installation runtime path to include a 'lib' directory relative to the binary. This is crucial for loading bundled libraries correctly. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Install ICU Data Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Installs the ICU data file to the 'data' subdirectory of the installation bundle. This is necessary for internationalization and localization. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install AOT Library (Non-Debug) Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the 'lib' subdirectory, but only for non-Debug builds. This optimizes release and profile builds by including pre-compiled code. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Re-copy Flutter Assets Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Installs code to remove and then copy the Flutter assets directory on each build. This prevents stale assets from being included in the installation. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Initialize InternetConnection (v2) Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/MIGRATION_V3.md This is how InternetConnection was initialized in v2, before the dependency on connectivity_plus was removed. ```dart import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart'; final connection = InternetConnection(); ``` -------------------------------- ### System Dependencies (GTK) Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Finds and checks for the GTK+ 3.0 library using PkgConfig. This ensures that GTK+ is available and configured for the build. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Initialize InternetConnection with Trigger Stream (v3) Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/MIGRATION_V3.md In v3, explicitly pass the connectivity_plus trigger stream to InternetConnection.createInstance to maintain automatic checking behavior. ```dart import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart'; import 'package:connectivity_plus/connectivity_plus.dart'; final connection = InternetConnection.createInstance( triggerStream: Connectivity().onConnectivityChanged, ); ``` -------------------------------- ### Find and check GTK, GLIB, and GIO modules Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/flutter/CMakeLists.txt Uses PkgConfig to find and check for the GTK, GLIB, and GIO libraries, which are essential system-level dependencies for Flutter on Linux. This ensures the necessary components are available before proceeding with the build. ```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) ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/runner/CMakeLists.txt Applies a standard set of build settings to the specified target. This can be removed if custom build settings are required. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Project and Binary Naming Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Sets the minimum CMake version, project name, and the executable's on-disk name. Adjust BINARY_NAME to change the application's filename. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) set(BINARY_NAME "internetcheck-linux-x64") set(APPLICATION_ID "rocks.outdatedguy.internet_connection_checker_plus_example") ``` -------------------------------- ### Create Isolated Internet Connection Checker Instance Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/README.md Third-party package developers should use `createInstance()` to create a dedicated `InternetConnection` checker. This isolates the checker from the host application and prevents unintended side effects. Ensure to manage the lifecycle of this isolated instance within your package. ```dart class MyCustomPackageService { final InternetConnection _connectionChecker; // Use createInstance() to isolate your connection checker from the host app MyCustomPackageService() : _connectionChecker = InternetConnection.createInstance(); // Safely clean up only your isolated instance Future shutdown() async { await _connectionChecker.dispose(); } } ``` -------------------------------- ### Configure Static Wrapper Library for Plugins Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/windows/flutter/CMakeLists.txt Builds a static C++ wrapper library for Flutter plugins, including core and plugin-specific sources. It sets visibility, links against the Flutter library, and specifies include directories. ```cmake list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Profile Build Mode Settings Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/windows/CMakeLists.txt Configures linker and compiler flags for the 'Profile' build mode, typically by inheriting settings from the 'Release' mode. ```cmake set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Unicode Support Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/windows/CMakeLists.txt Enables Unicode support by defining preprocessor macros. ```cmake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Runtime Output Directory Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Sets the runtime output directory for the main binary to a specific subdirectory within the build directory. This is done to prevent users from running the unbundled copy of the executable. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Configure Static Wrapper Library for Runner Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/windows/flutter/CMakeLists.txt Builds a static C++ wrapper library for the Flutter runner application, including core and application-specific sources. It links against the Flutter library and specifies include directories. ```cmake list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Cross-Building Sysroot Configuration Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Sets up the sysroot and find root path for cross-building when FLUTTER_TARGET_PLATFORM_SYSROOT is defined. This directs CMake to use the specified sysroot for finding libraries and headers. ```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() ``` -------------------------------- ### Set Include Directories Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/runner/CMakeLists.txt Specifies include directories for the target, making source files accessible during compilation. ```cmake target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Build Configuration for Multi-Config Generators Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/windows/CMakeLists.txt Defines the available build configurations (Debug, Profile, Release) when using a multi-configuration generator like Visual Studio. ```cmake 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() ``` -------------------------------- ### Listen to Real-Time Connectivity Status Changes (Dart) Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/README.md Subscribe to connectivity status updates using `onStatusChange`. Remember to cancel the subscription when no longer needed to prevent memory leaks. ```dart final subscription = InternetConnection().onStatusChange.listen( (InternetStatus status) { if (status == InternetStatus.connected) { // Connection established } else { // Connection lost } }, ); // Cancel the subscription when it is no longer needed to prevent memory leaks subscription.cancel(); ``` -------------------------------- ### Add Preprocessor Definitions Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/runner/CMakeLists.txt Adds preprocessor definitions for the application ID, making it available during compilation. ```cmake add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Generated Plugin Inclusion Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/windows/CMakeLists.txt Includes CMake rules for building and integrating generated plugins. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Add connectivity_plus Dependency Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/MIGRATION_V3.md Ensure you add the connectivity_plus package to your pubspec.yaml file as it's no longer bundled. ```yaml dependencies: internet_connection_checker_plus: ^3.0.0 connectivity_plus: ^7.0.0 # or latest ``` -------------------------------- ### Link Dependencies Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/runner/CMakeLists.txt Links necessary libraries to the application target. Includes the Flutter engine library and GTK via PkgConfig. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Custom command to assemble Flutter library and headers Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/flutter/CMakeLists.txt Defines a custom command that runs the Flutter tool backend script to generate the Flutter library and its headers. This command is triggered by the `flutter_assemble` custom target. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Check Internet Connectivity on Demand (Dart) Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/README.md Use this snippet to perform a one-time check for internet access. Ensure the `InternetConnection` class is imported. ```dart final bool isConnected = await InternetConnection().hasInternetAccess; ``` -------------------------------- ### Standard Compilation Settings Function Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/windows/CMakeLists.txt A reusable function to apply common compilation settings like C++ standard, warning levels, and exception handling to a target. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() ``` -------------------------------- ### Modern CMake Policies Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Explicitly opts into modern CMake behaviors to avoid warnings with recent CMake versions. This ensures compatibility and adherence to current best practices. ```cmake cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Define list_prepend function for CMake < 3.10 Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/flutter/CMakeLists.txt This function prepends a prefix to each element in a list. It is a workaround for versions of CMake older than 3.10, which do not support 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() ``` -------------------------------- ### Custom Command for Flutter Tool Backend Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/windows/flutter/CMakeLists.txt Defines a custom command to execute the Flutter tool backend script. This command generates necessary build artifacts like the Flutter library and headers. A phony output file is used to ensure the command runs on every build. ```cmake set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) ``` -------------------------------- ### Subdirectory Inclusion Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/windows/CMakeLists.txt Includes the Flutter managed directory and the application runner subdirectory. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` ```cmake add_subdirectory("runner") ``` -------------------------------- ### Define Executable Target Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/runner/CMakeLists.txt Defines the main executable for the runner application. Source files and 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" ) ``` -------------------------------- ### Build Type Configuration Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Sets the default build type to 'Debug' if not already defined. This ensures a consistent build mode for development unless explicitly overridden. ```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() ``` -------------------------------- ### Configure Flutter Library Interface Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/windows/flutter/CMakeLists.txt Defines the Flutter library target, including its include directories and linked libraries. It also adds a dependency on the flutter_assemble target. ```cmake 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 Flutter library interface Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/flutter/CMakeLists.txt Defines an INTERFACE library for Flutter, setting include directories and linking against the Flutter library and its system dependencies (GTK, GLIB, GIO). This makes the Flutter library available for other targets. ```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) ``` -------------------------------- ### Dispose Custom InternetConnection Instances Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/README.md Manually dispose of custom InternetConnection instances created with createInstance() to prevent memory leaks. Never call dispose() on the global singleton. ```dart final customConnection = InternetConnection.createInstance(); // When done with the instance: await customConnection.dispose(); ``` -------------------------------- ### Standard Compilation Settings Function Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Defines a function to apply standard compilation settings like C++ standard, warning options, optimization levels, and debug definitions to a target. Use this to ensure consistent compiler flags across targets. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Custom HTTP Client with Dio Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/README.md Integrate existing HTTP clients like Dio for network requests. This allows for consistent configuration across your application. The custom check function should return an InternetCheckResult. ```dart final connection = InternetConnection.createInstance( customConnectivityCheck: (option) async { try { final dio = Dio(); final response = await dio.head( option.uri.toString(), options: Options( headers: option.headers, receiveTimeout: option.timeout, validateStatus: (_) => true, ), ); return InternetCheckResult( option: option, isSuccess: response.statusCode == 42, ); } catch (_) { return InternetCheckResult(option: option, isSuccess: false); } }, ); ``` -------------------------------- ### Flutter Managed Directory Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Sets the path to the Flutter managed directory, which is typically located in a 'flutter' subdirectory. This path is used for including Flutter-specific build rules. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Runner Subdirectory Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Includes the 'runner' subdirectory, which contains the specific build rules for the application's runner executable. This is a common pattern for organizing larger CMake projects. ```cmake add_subdirectory("runner") ``` -------------------------------- ### Set Flutter Target Platform Fallback Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/windows/flutter/CMakeLists.txt Sets a default FLUTTER_TARGET_PLATFORM if it's not already defined, ensuring compatibility with older Flutter tool versions. ```cmake if (NOT DEFINED FLUTTER_TARGET_PLATFORM) set(FLUTTER_TARGET_PLATFORM "windows-x64") endif() ``` -------------------------------- ### Custom Target for Flutter Assembly Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/windows/flutter/CMakeLists.txt Creates a custom target 'flutter_assemble' that depends on the output of the Flutter tool backend command. This target ensures that all necessary Flutter assets and libraries are generated before other build steps that depend on them. ```cmake add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Flutter Assemble Dependency Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/example/linux/CMakeLists.txt Adds a dependency on 'flutter_assemble'. This ensures that the Flutter assets and code are assembled before the main binary is built. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Strict Mode Validation with Custom Endpoints Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/README.md Enable strict mode to require all provided endpoints to succeed for a positive connectivity result. Use this only with custom-defined URIs, not default ones. ```dart final connection = InternetConnection.createInstance( enableStrictCheck: true, useDefaultOptions: false, customCheckOptions: [ InternetCheckOption(uri: Uri.parse('https://example.com')), InternetCheckOption(uri: Uri.parse('https://example2.com')), ], ); ``` -------------------------------- ### Pause and Resume Network Requests on App Lifecycle Changes (Flutter) Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/README.md Use AppLifecycleListener to pause network requests when the app enters the background and resume them on foreground. Cancel and recreate the subscription to avoid stale events. ```dart class _MyWidgetState extends State { late StreamSubscription _subscription; late final AppLifecycleListener _listener; @override void initState() { super.initState(); _startListening(); _listener = AppLifecycleListener( onResume: _startListening, onPause: () => _subscription.cancel(), ); } void _startListening() { _subscription = InternetConnection().onStatusChange.listen((status) { // Handle internet status changes }); } @override void dispose() { _subscription.cancel(); _listener.dispose(); super.dispose(); } } ``` -------------------------------- ### Custom Validation Endpoints Source: https://github.com/outdatedguy/internet_connection_checker_plus/blob/main/README.md Override default validation endpoints and specify custom response status functions. Ensure custom endpoints are not cached and CORS-compatible for web use. ```dart final connection = InternetConnection.createInstance( customCheckOptions: [ InternetCheckOption( uri: Uri.parse('https://cloudflare.com/cdn-cgi/trace'), responseStatusFn: (response) => response.statusCode == 69, ), ], ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.