### Setting up Installation Paths and Installing Executable - CMake Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/CMakeLists.txt Defines variables for installation directories, setting the install prefix to the executable's build directory to facilitate running directly from the build output. It also configures Visual Studio to include the install step by default and installs the main application executable to the specified prefix. ```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) ``` -------------------------------- ### Configure Installation Prefix for Bundling Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Sets the default installation prefix to a 'bundle' directory within the build directory, configuring CMake's install command to create 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() ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Iterates through a list of bundled plugin libraries and installs each one into the bundle's library directory. ```CMake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Example Usage of AnyLinkPreview Widget (Dart) Source: https://github.com/sur950/any_link_preview/blob/master/README.md Demonstrates how to create and configure an AnyLinkPreview widget instance with various properties set, such as link, direction, styling, error handling, caching, and tap behavior. ```Dart AnyLinkPreview( link: "https://vardaan.app/", displayDirection: UIDirection.uiDirectionHorizontal, showMultimedia: false, bodyMaxLines: 5, bodyTextOverflow: TextOverflow.ellipsis, titleStyle: TextStyle( color: Colors.black, fontWeight: FontWeight.bold, fontSize: 15, ), bodyStyle: TextStyle(color: Colors.grey, fontSize: 12), errorBody: 'Show my custom error body', errorTitle: 'Show my custom error title', errorWidget: Container( color: Colors.grey[300], child: Text('Oops!'), ), errorImage: "https://google.com/", cache: Duration(days: 7), backgroundColor: Colors.grey[300], borderRadius: 12, removeElevation: false, userAgent: 'WhatsApp/2.21.12.21 A', boxShadow: [BoxShadow(blurRadius: 3, color: Colors.grey)], onTap: () {}, // This disables tap event ) ``` -------------------------------- ### Installing Plugin Libraries and Native Assets - CMake Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/CMakeLists.txt Installs libraries provided by plugins if the `PLUGIN_BUNDLED_LIBRARIES` variable is set. It also defines the path to native assets generated by the Flutter build process and installs the entire directory containing these assets into the installation's library directory. Both are part of the "Runtime" component. ```CMake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() # Copy the native assets provided by the build.dart from all packages. set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Executable and Core Libraries Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Installs the main application executable, the Flutter ICU data file, and the main Flutter library into their respective locations within the 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) ``` -------------------------------- ### Define Bundle Installation Directories Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Sets variables for the standard data and library directories within the application bundle's installation prefix. ```CMake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Installing AOT Library for Release/Profile Builds - CMake Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library, which is typically used for optimized builds. This installation step is conditional and only runs for "Profile" and "Release" configurations, placing the library in the data directory within the install prefix as part of the "Runtime" component. ```CMake # Install the AOT library on non-Debug builds only. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Installing and Refreshing Flutter Assets - CMake Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/CMakeLists.txt Defines the name for the Flutter assets directory. It then uses an `install(CODE)` block to remove any previously installed assets directory before installing the current build's assets directory. This ensures that the installed assets are always up-to-date. Both steps are part of the "Runtime" component and target the data directory. ```CMake # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Clean Bundle Directory During Install Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Adds a custom installation step that removes the contents of the build bundle directory before installing new files, ensuring a clean bundle on each install. ```CMake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Assets Directory - CMake Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Configures the installation of the built Flutter asset directory from the project's build output location to the designated installation bundle data directory as part of the Runtime component. ```CMake install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Initialize Project and Set Minimum CMake Version Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Sets the minimum required CMake version and defines the project name and enabled languages. This is the standard starting point for any CMake project. ```CMake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) ``` -------------------------------- ### Installing Flutter ICU Data and Library - CMake Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/CMakeLists.txt Installs core Flutter runtime files required by the application. This includes the ICU data file, which is placed in the data directory within the install prefix, and the main Flutter library, which is placed directly in the install prefix. Both are marked as part of the "Runtime" component. ```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) ``` -------------------------------- ### Install Native Assets Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Defines the directory containing native assets generated by the build and installs its contents into the bundle's library directory. ```CMake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Conditionally Install AOT Library - CMake Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Installs the Ahead-of-Time (AOT) compiled library file to the installation bundle's library directory only when the build type is not 'Debug', typically for Release or Profile builds. ```CMake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Remove Existing Flutter Assets Before Install - CMake Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Executes a CMake script during the installation process to recursively remove any existing Flutter assets at the target destination, ensuring a clean installation or update. ```CMake install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) ``` -------------------------------- ### Setup Phony Output for Custom Command Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/flutter/CMakeLists.txt Defines a variable for a phony output file and sets its SYMBOLIC property to TRUE. This is used to force the custom command to run every time, as it doesn't produce a real output file that CMake can track for dependencies. ```CMake # _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) ``` -------------------------------- ### Set CMake Version and Project for Flutter Runner Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/runner/CMakeLists.txt Sets the minimum required CMake version to 3.14 and defines the project name as "runner" with CXX language support. This is the initial setup for the CMake build process. ```CMake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) ``` -------------------------------- ### Getting Link Metadata with AnyLinkPreview (Dart) Source: https://github.com/sur950/any_link_preview/blob/master/CHANGELOG.md Demonstrates how to retrieve only the metadata for a given URL using the static `getMetadata` method of the `AnyLinkPreview` class. This method returns a `Metadata` object and is useful for building custom UI based on link data. ```Dart AnyLinkPreview.getMetadata(link: "https://google.com/") ``` -------------------------------- ### Set Flutter Asset Directory Name - CMake Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Defines a CMake variable to hold the standard directory name for Flutter assets, promoting consistency and easier modification of installation paths. ```CMake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") ``` -------------------------------- ### Apply Standard Settings and Link Libraries Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Applies the previously defined standard compilation settings to the executable target and links the necessary libraries, including the Flutter library and the found GTK library. ```CMake apply_standard_settings(${BINARY_NAME}) target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Setting up CMake Project and Binary Name - CMake Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/CMakeLists.txt Configures the minimum required CMake version, defines the project name and enabled languages (C++), and sets the name for the output executable binary. This is typically the first section in a CMakeLists.txt file. ```CMake cmake_minimum_required(VERSION 3.14) project(example 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 "example") ``` -------------------------------- ### Properties of AnyLinkPreview Widget (Dart) Source: https://github.com/sur950/any_link_preview/blob/master/README.md Describes the various configuration options available for the AnyLinkPreview widget, including display direction, URL launching, link URL, styling, error handling, caching, and tap behavior. ```Dart /// Display direction. Either [UIDirection.uiDirectionVertical] or /// [UIDirection.uiDirectionHorizontal]. Defaults to vertical direction. final UIDirection displayDirection; /// Represents the mechanism used to open URLs via [launchUrl]. Defaults to /// [LaunchMode.platformDefault] final LaunchMode urlLaunchMode; /// URL represented in string. For IOS & Web, only HTTP and HTTPS are /// supported. For Android, all URLs are supported. final String link; /// Customize background color. Defaults to `Color.fromRGBO(235, 235, 235, 1)` final Color? backgroundColor; /// Placeholder widget that is shown while the metadata request is pending. /// If not present, the default loading widget will be shown. final Widget? placeholderWidget; /// Error widget that will be shown in case of an error. Defaults to a plain /// [Container] with a given [backgroundColor]. If the issue is known, i.e. /// either a title or a description of the error is present, [errorTitle] and /// [errorBody] are used instead, with fallback to their default values. final Widget? errorWidget; /// Error title message that will be shown in case of an error. Defaults to /// "Something went wrong!". final String? errorTitle; /// Error body message that will be shown in case of an error. Defaults to /// "Oops! Unable to parse the url. We have sent feedback to our developers & /// we will try to fix this in our next release. Thanks!" final String? errorBody; /// Image that will be shown in case of an error when [showMultimedia] is set /// to `true` and no metadata could be parsed. Defaults to /// "A semi-soccer ball image that looks like crying". final String? errorImage; /// Sets the overflow type for body text (description) of the link. /// Deaults to [TextOverflow.ellipsis]. final TextOverflow bodyTextOverflow; /// Sets the limit to body text (description) of the link. Defaults to `3`. final int bodyMaxLines; /// TTL of metadata cache. Defaults to 1 day. Pass `null` to disable caching /// and always make a request for latest metadata. final Duration cache; /// Customize body [TextStyle]. final TextStyle? titleStyle; /// Customize body [TextStyle]. final TextStyle? bodyStyle; /// Whether to show metadata image if it's present. Defaults to `true`. final bool showMultimedia; /// [BorderRadius] for the card. Deafults to `12`. final double? borderRadius; /// If set to true, removes card widget's elevation. Defaults to `false`. final bool removeElevation; /// Box shadow for the card. Deafults to /// `[BoxShadow(blurRadius: 3, color: Colors.grey)]`. final List? boxShadow; /// Proxy URL that is used to resolve CORS issues on web. /// For example, `https://cors-anywhere.herokuapp.com/` . final String? proxyUrl; /// Headers to be added in the HTTP request to the link final Map? headers; /// Function that is called on card tap. If not provided, then [launchUrl] /// will be used with the provided link. To disable calling [launchUrl] and /// instead do nothing on tap, pass an empty function: `() {}`. final VoidCallback? onTap; /// Height of the preview card. Defaults to /// `(MediaQuery.sizeOf(context).height) * 0.15` for the horizontal preview /// and `(MediaQuery.sizeOf(context).height) * 0.25` for the vertical preview. final double? previewHeight; /// Builder function that is used only in [AnyLinkPreview.builder] and /// allows building a custom [Widget] from the [Metadata], with either of /// the optional [ImageProvider] or [SvgPicture] fetched. final Widget Function(BuildContext, Metadata, ImageProvider?, SvgPicture?)? itemBuilder; /// User-Agent to be used in the HTTP request to the link /// Default: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' final String? userAgent; ``` -------------------------------- ### Fetching Link Metadata with AnyLinkPreview (Dart) Source: https://github.com/sur950/any_link_preview/blob/master/README.md Demonstrates how to use the `AnyLinkPreview.getMetadata` method to retrieve metadata for a given URL. It shows how to specify the link, caching duration, a proxy URL (needed for web), and a custom user agent. The retrieved title is then printed. ```Dart Metadata? _metadata = await AnyLinkPreview.getMetadata( link: "https://google.com/", cache: const Duration(days: 7), proxyUrl: "https://corsproxy.org/", // Need for web userAgent: 'WhatsApp/2.21.12.21 A', // Change when results are wrong ); print(_metadata?.title); ``` -------------------------------- ### Include Flutter Build Rules and Find GTK Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Includes the CMake rules managed by the Flutter tool and finds the required GTK 3.0 library using PkgConfig, making it available as an imported target. ```CMake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/runner/CMakeLists.txt Specifies the libraries to link against and the include directories for the executable target (`${BINARY_NAME}`). It links the Flutter core libraries (`flutter`, `flutter_wrapper_app`), a specific Windows library (`dwmapi.lib`), and adds the source directory (`${CMAKE_SOURCE_DIR}`) to the include paths for finding header files. ```CMake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Link PkgConfig Dependencies to Flutter Library Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Links the imported targets for GTK, GLIB, and GIO (found via PkgConfig) to the `flutter` interface library, ensuring that targets linking against `flutter` also link against these system libraries. ```CMake target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) ``` -------------------------------- ### Define Application Executable Target Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Defines the main executable target for the application, specifying its name (using BINARY_NAME) and listing the source files to be compiled. ```CMake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) ``` -------------------------------- ### Apply Standard Build Settings to Target Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/runner/CMakeLists.txt Applies a predefined set of standard build settings to the specified executable target (`${BINARY_NAME}`). This command likely includes common compiler flags, optimization levels, and other settings recommended for the project. ```CMake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Include Generated Plugin Rules Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Includes the CMake file generated by the Flutter tool that contains build rules for any plugins used by the application. ```CMake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Set CMake Policy and RPATH Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Explicitly opts into modern CMake behaviors to avoid warnings and sets the runtime path (RPATH) to load bundled libraries from a 'lib' directory relative to the executable. ```CMake cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Add Flutter Assemble Dependency and Set Output Directory Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Ensures that the Flutter tool's assemble step runs before building the executable and sets a custom output directory for the unbundled executable to discourage running it directly. ```CMake add_dependencies(${BINARY_NAME} flutter_assemble) set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Define Flutter Windows Executable Target Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/runner/CMakeLists.txt Defines the main executable target for the Windows runner application using `add_executable`. It specifies the target name (`${BINARY_NAME}`), the build type (`WIN32`), and lists all the source files required to build the executable, including C++ files, resource files, and generated plugin registration code. ```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" ) ``` -------------------------------- ### Including Flutter and Plugin Subdirectories - CMake Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/CMakeLists.txt Sets a variable for the Flutter managed directory and includes it as a subdirectory, incorporating Flutter's build rules. It also includes the "runner" subdirectory, which contains the application's main build logic, and includes a generated CMake file for handling plugin builds. ```CMake # Flutter library and tool build rules. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) # Application build; see runner/CMakeLists.txt. add_subdirectory("runner") # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Define Flutter Wrapper App Static Library Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/flutter/CMakeLists.txt Defines a STATIC library named 'flutter_wrapper_app' using the core and app wrapper sources. It applies standard settings, links against the 'flutter' interface library, includes wrapper headers, and adds a dependency on 'flutter_assemble'. ```CMake # Wrapper sources needed for the runner. add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Find and Check PkgConfig Modules Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Uses `find_package` to locate PkgConfig and then `pkg_check_modules` to find and import targets for system libraries like GTK, GLIB, and GIO, which are required dependencies for the Flutter Linux GTK 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) ``` -------------------------------- ### Opening Xcode Workspace for Launch Screen Assets (Shell) Source: https://github.com/sur950/any_link_preview/blob/master/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md This command opens the Xcode workspace for the iOS runner project, allowing direct access to the Assets.xcassets catalog where launch screen images can be managed and replaced. ```Shell open ios/Runner.xcworkspace ``` -------------------------------- ### Define Standard Compilation Settings Function Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Defines a CMake function `APPLY_STANDARD_SETTINGS` that applies common compilation features (C++14) and options (-Wall, -Werror, optimization for non-Debug builds, NDEBUG definition) to a specified target. ```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() ``` -------------------------------- ### Configure Cross-Building Sysroot Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Configures CMake's sysroot and find root paths when cross-building is enabled (e.g., via FLUTTER_TARGET_PLATFORM_SYSROOT), ensuring dependencies are found within the target 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() ``` -------------------------------- ### Define C++ Wrapper Source Lists Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/flutter/CMakeLists.txt Defines lists for the core, plugin, and application C++ wrapper source files. It then transforms each list by prepending the wrapper root directory path to the file names. ```CMake list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Define Flutter Wrapper Plugin Static Library Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/flutter/CMakeLists.txt Defines a STATIC library named 'flutter_wrapper_plugin' using the core and plugin wrapper sources. It applies standard settings, sets position-independent code and visibility properties, links against the 'flutter' interface library, includes wrapper headers, and adds a dependency on 'flutter_assemble'. ```CMake # Wrapper sources needed for a plugin. add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Validating URL with AnyLinkPreview (Dart) Source: https://github.com/sur950/any_link_preview/blob/master/README.md Shows how to use the `AnyLinkPreview.isValidLink` method to check if a URL is valid based on specified protocols, a whitelist of allowed hosts, and a blacklist of disallowed hosts. The validation result is printed to the console. ```Dart final bool _isUrlValid = AnyLinkPreview.isValidLink( "https://google.com/", protocols: ['http', 'https'], hostWhitelist: ['https://youtube.com/'], hostBlacklist: ['https://facebook.com/'], ); print('_isUrlValid => $_isUrlValid'); ``` -------------------------------- ### Defining Standard Compilation Settings Function - CMake Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/CMakeLists.txt Defines a CMake function `APPLY_STANDARD_SETTINGS` that takes a target name as input. This function applies common compilation settings to the specified target, including C++17 standard, specific compiler options (like warning levels and exception handling), and preprocessor definitions based on the build configuration (e.g., `_DEBUG` for Debug builds). ```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_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() ``` -------------------------------- ### Add Compile Definitions for Version and Macros Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/runner/CMakeLists.txt Adds preprocessor definitions to the executable target (`${BINARY_NAME}`). This includes defining various parts of the Flutter version string and disabling Windows macros like `min` and `max` that can conflict with C++ standard library functions by defining `NOMINMAX`. ```CMake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") # Disable Windows macros that collide with C++ standard library functions. target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") ``` -------------------------------- ### Define Application Binary Name and ID Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Sets variables for the executable file name and the unique GTK application identifier. These variables are used throughout the CMake configuration. ```CMake set(BINARY_NAME "example") set(APPLICATION_ID "com.example.example") ``` -------------------------------- ### Define list_prepend Function Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Defines a custom CMake function `list_prepend` that prepends a given prefix to each element in a list. This function serves as a workaround for the `list(TRANSFORM ... PREPEND ...)` command not available in CMake 3.10. ```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() ``` -------------------------------- ### Set Ephemeral and Wrapper Directories Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/flutter/CMakeLists.txt Defines variables for the ephemeral directory, which contains generated build files, and the C++ client wrapper root directory. These paths are used throughout the script to locate necessary files. ```CMake set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") ``` -------------------------------- ### Validate URL Format using AnyLinkPreview in Dart Source: https://github.com/sur950/any_link_preview/blob/master/README.md Demonstrates how to use the static `isValidLink` method provided by the `AnyLinkPreview` package to check if a given string conforms to a valid URL format before processing it for preview generation. ```Dart bool isValid = AnyLinkPreview.isValidLink(myUrlString); ``` -------------------------------- ### Define Flutter Assemble Custom Command and Target Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/flutter/CMakeLists.txt Defines a custom command that invokes the Flutter tool backend script to assemble necessary build artifacts (Flutter library, headers, wrapper sources). It lists the expected outputs and uses VERBATIM for command execution. It then defines a custom target 'flutter_assemble' that depends on the outputs of this custom command, ensuring the command runs when 'flutter_assemble' is built. ```CMake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Define Default Build Type Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/CMakeLists.txt Sets the default build type to 'Debug' if not already specified, and defines the available build types ('Debug', 'Profile', 'Release') for the project. ```CMake if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### Set Include Directories for Flutter Library Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Specifies the include directories required when compiling code that uses the `flutter` interface library. This includes the ephemeral directory where generated headers are located. ```CMake target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) ``` -------------------------------- ### Prepend Path to Header List Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Uses the custom `list_prepend` function to add the ephemeral directory path to each header filename in the `FLUTTER_LIBRARY_HEADERS` list. ```CMake list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") ``` -------------------------------- ### Link Flutter Library to Interface Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Links the actual Flutter shared library (`libflutter_linux_gtk.so`) to the `flutter` interface library, making it a usage requirement for targets linking against `flutter`. ```CMake target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") ``` -------------------------------- ### Add Dependency on Flutter Assemble Step Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/runner/CMakeLists.txt Adds a build dependency for the executable target (`${BINARY_NAME}`) on the `flutter_assemble` target. This ensures that the necessary Flutter assets, generated code, and other build artifacts are prepared by the Flutter tool before the native executable is compiled and linked. ```CMake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Include Generated Configuration File Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Includes a CMake configuration file generated by the Flutter tool. This file typically contains build-specific variables and settings. ```CMake include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### Include Generated Configuration Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/flutter/CMakeLists.txt Includes a CMake configuration file generated by the Flutter tool. This file typically contains build-specific settings and variables. ```CMake include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### Define Flutter Interface Library Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Defines an INTERFACE library named `flutter`. Interface libraries are used to propagate usage requirements (like include directories and link libraries) to targets that link against them. ```CMake add_library(flutter INTERFACE) ``` -------------------------------- ### Configuring Build Types and Profile Flags - CMake Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/CMakeLists.txt Sets the CMake policy version range for modern behavior. It then configures build types (Debug, Profile, Release) based on whether the generator supports multiple configurations, defaulting to Debug for single-config generators. Finally, it sets compilation and linker flags for the Profile build mode to match the Release mode. ```CMake # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. cmake_policy(VERSION 3.14...3.25) # Define build configuration option. get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() # Define settings for the Profile build mode. set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Define flutter_assemble Custom Command Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Defines a custom command named `flutter_assemble` that executes the Flutter tool backend script. This command generates the necessary build artifacts like the Flutter library and headers. A phony output is used to force the command to run every time. ```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 ) ``` -------------------------------- ### Define Flutter Interface Library Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/flutter/CMakeLists.txt Defines an INTERFACE library named 'flutter'. It specifies include directories and links against the Flutter library's import library. 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}.lib") add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Append Headers to List Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Appends a list of Flutter library header filenames to the `FLUTTER_LIBRARY_HEADERS` variable. ```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" ) ``` -------------------------------- ### Add Build Dependency on flutter_assemble Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Adds a dependency to the `flutter` interface library on the `flutter_assemble` target. This ensures that the `flutter_assemble` target runs before any target that depends on `flutter`. ```CMake add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Define Flutter Library Headers List Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/flutter/CMakeLists.txt Appends the necessary header file names for the Flutter library to a list variable. It then transforms the list by prepending the ephemeral directory path to each header name. ```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}/") ``` -------------------------------- ### Set Minimum Required CMake Version Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Specifies the minimum version of CMake required to build the project. This ensures compatibility with the commands and features used in the script. ```CMake cmake_minimum_required(VERSION 3.10) ``` -------------------------------- ### Define flutter_assemble Custom Target Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Defines a custom target named `flutter_assemble` that depends on the outputs of the corresponding custom command. This target represents the step of assembling the Flutter engine and application artifacts. ```CMake add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Set and Export Variables to Parent Scope Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Sets variables like `FLUTTER_LIBRARY`, `FLUTTER_ICU_DATA_FILE`, `PROJECT_BUILD_DIR`, and `AOT_LIBRARY`, and exports them to the parent scope so they can be accessed by other CMakeLists.txt files or build steps. ```CMake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 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) ``` -------------------------------- ### Set Ephemeral Directory Path Source: https://github.com/sur950/any_link_preview/blob/master/example/linux/flutter/CMakeLists.txt Defines a variable `EPHEMERAL_DIR` pointing to a directory used for generated files and build artifacts specific to the Flutter tool's output. ```CMake set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") ``` -------------------------------- ### Set Minimum CMake Version Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/flutter/CMakeLists.txt Specifies the minimum required version of CMake to build the project. This ensures compatibility with the commands and features used in the script. ```CMake cmake_minimum_required(VERSION 3.14) ``` -------------------------------- ### Set Fallback Target Platform Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/flutter/CMakeLists.txt Checks if the FLUTTER_TARGET_PLATFORM variable is defined and sets a default value ('windows-x64') if it is not. This provides compatibility with older versions of the Flutter tool. ```CMake if (NOT DEFINED FLUTTER_TARGET_PLATFORM) set(FLUTTER_TARGET_PLATFORM "windows-x64") endif() ``` -------------------------------- ### Set Flutter Library and Data Paths Source: https://github.com/sur950/any_link_preview/blob/master/example/windows/flutter/CMakeLists.txt Defines variables for the main Flutter library DLL, the ICU data file, the project build directory, and the AOT library path. These variables are set with PARENT_SCOPE to make them available in the parent CMakeLists.txt scope. ```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) ``` -------------------------------- ### Checking Link Validity with AnyLinkPreview (Dart) Source: https://github.com/sur950/any_link_preview/blob/master/CHANGELOG.md Shows how to check if a URL string is valid using the static `isValidLink` method of the `AnyLinkPreview` class. This method takes a URL string as input and returns a boolean value (`true` if valid, `false` if invalid). ```Dart AnyLinkPreview.isValidLink("https://google.com/") ``` -------------------------------- ### Disabling onTap Action in AnyLinkPreview (Dart) Source: https://github.com/sur950/any_link_preview/blob/master/CHANGELOG.md Shows how to disable the tap action on the link preview card by assigning an empty anonymous function to the `onTap` parameter of the AnyLinkPreview widget. ```Dart onTap: (){} ``` -------------------------------- ### Defining UIDirection Enum (Dart) Source: https://github.com/sur950/any_link_preview/blob/master/README.md Defines a Dart enum `UIDirection` with two possible values, `uiDirectionVertical` and `uiDirectionHorizontal`, used to specify the display direction for UI elements. ```Dart enum UIDirection { uiDirectionVertical, uiDirectionHorizontal } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.