### Flutter Library Setup Source: https://github.com/sachinganesh/screenshot/blob/master/example/windows/flutter/CMakeLists.txt Configures the Flutter library, including its DLL, header files, and ICU data. It sets up include directories and links the necessary libraries for the Flutter interface. ```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) ``` -------------------------------- ### Installation Rules for Application Bundle Source: https://github.com/sachinganesh/screenshot/blob/master/example/windows/CMakeLists.txt Configures installation rules for the application, including setting the install prefix to the bundle directory, installing the executable, Flutter ICU data, libraries, and bundled plugin libraries. It also handles the assets directory and AOT library installation. ```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) ``` -------------------------------- ### CMake Build Configuration Source: https://github.com/sachinganesh/screenshot/blob/master/example/windows/CMakeLists.txt Configures the CMake build process, including minimum version, project name, binary name, and installation paths. It also sets up build type configurations for multi-config generators and standard build types. ```cmake cmake_minimum_required(VERSION 3.15) project(example LANGUAGES CXX) 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}") # Use Unicode for all projects. add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### CMake Build Configuration Source: https://github.com/sachinganesh/screenshot/blob/master/example/windows/runner/CMakeLists.txt Configures the CMake build system for the project. It sets the minimum required CMake version, defines the project name and language, and specifies how to build the executable, including source files, compiler definitions, linked libraries, and include directories. It also adds a dependency on the 'flutter_assemble' target. ```cmake cmake_minimum_required(VERSION 3.15) project(runner LANGUAGES CXX) add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "run_loop.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) apply_standard_settings(${BINARY_NAME}) target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Flutter Tool Backend Integration Source: https://github.com/sachinganesh/screenshot/blob/master/example/windows/flutter/CMakeLists.txt Configures a custom command to execute the Flutter tool backend for Windows x64 builds. This command generates necessary files like the Flutter library and wrapper sources. ```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 ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### C++ Client Wrapper for Plugins Source: https://github.com/sachinganesh/screenshot/blob/master/example/windows/flutter/CMakeLists.txt Builds a static library for the C++ client wrapper used by Flutter plugins. It includes core implementations and plugin-specific sources, linking against the Flutter library. ```cmake # === Wrapper === list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") # Wrapper sources needed for a plugin. add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Capture a Widget Source: https://github.com/sachinganesh/screenshot/blob/master/README.md Demonstrates how to capture a visible widget by wrapping it with the Screenshot widget and using a ScreenshotController. ```dart class _MyHomePageState extends State { ScreenshotController screenshotController = ScreenshotController(); // ... } Screenshot( controller: screenshotController, child: Text("This text will be captured as image"), ), // To capture: screenshotController.capture().then((Uint8List image) { // Handle captured image }).catchError((onError) { print(onError); }); ``` -------------------------------- ### C++ Client Wrapper for Runner Source: https://github.com/sachinganesh/screenshot/blob/master/example/windows/flutter/CMakeLists.txt Builds a static library for the C++ client wrapper used by the Flutter runner application. It includes core and application-specific sources, linking against the Flutter library. ```cmake # Wrapper sources needed for the runner. add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/sachinganesh/screenshot/blob/master/example/windows/CMakeLists.txt Defines a CMake function to apply standard compilation features and options to a target, including C++17 standard, warning levels, exception handling, and debug definitions. ```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() ``` -------------------------------- ### Customize Launch Screen Assets via Xcode Source: https://github.com/sachinganesh/screenshot/blob/master/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md Instructions for customizing launch screen assets using Xcode. This involves opening the Flutter project's workspace in Xcode, selecting the Assets.xcassets catalog, and replacing the default images. ```bash open ios/Runner.xcworkspace ``` ```text In Xcode: 1. Select "Runner/Assets.xcassets" in the Project Navigator. 2. Drag and drop your desired images into the catalog. ``` -------------------------------- ### Flutter Project Structure and Plugin Integration Source: https://github.com/sachinganesh/screenshot/blob/master/example/windows/CMakeLists.txt Includes subdirectories for Flutter managed files and the runner application. It also integrates generated plugin build rules, which are essential for managing and building project plugins. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") # Flutter library and tool build rules. add_subdirectory(${FLUTTER_MANAGED_DIR}) # Application build add_subdirectory("runner") # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Capture and Share Image Source: https://github.com/sachinganesh/screenshot/blob/master/README.md Captures a screenshot, saves it as a PNG file in the application's documents directory, and then shares the file using the Share plugin. ```dart await _screenshotController.capture(delay: const Duration(milliseconds: 10)).then((Uint8List image) async { if (image != null) { final directory = await getApplicationDocumentsDirectory(); final imagePath = await File('${directory.path}/image.png').create(); await imagePath.writeAsBytes(image); /// Share Plugin await Share.shareFiles([imagePath.path]); } }); ``` -------------------------------- ### Capture an Invisible Widget Source: https://github.com/sachinganesh/screenshot/blob/master/README.md Shows how to capture a widget that is not currently rendered on the screen by passing the widget directly to the captureFromWidget method. ```dart screenshotController .captureFromWidget(Container( padding: const EdgeInsets.all(30.0), decoration: BoxDecoration( border: Border.all(color: Colors.blueAccent, width: 5.0), color: Colors.redAccent, ), child: Text("This is an invisible widget"))) .then((capturedImage) { // Handle captured image }); ``` -------------------------------- ### Adjusting Pixel Ratio for Screenshot Quality Source: https://github.com/sachinganesh/screenshot/blob/master/README.md Demonstrates how to set the pixelRatio to improve the quality of captured images and prevent pixelation. The pixelRatio controls the scale between logical pixels and the output image size. ```dart double pixelRatio = MediaQuery.of(context).devicePixelRatio; screenshotController.capture( pixelRatio: pixelRatio //1.5 ) ``` -------------------------------- ### Adding Delay for Frame Rasterization Source: https://github.com/sachinganesh/screenshot/blob/master/README.md Provides a solution to capture frames correctly when dealing with asynchronous rasterization by adding a small delay before capturing the screenshot. This addresses issues where the screenshot might be taken before the GPU thread finishes rendering. ```dart screenshotController.capture(delay: Duration(milliseconds: 10)) ``` -------------------------------- ### Flutter Service Worker Registration Source: https://github.com/sachinganesh/screenshot/blob/master/example/web/index.html This JavaScript code snippet checks for service worker support in the browser and registers a Flutter service worker upon the 'flutter-first-frame' event. This is typically used for optimizing PWA performance in Flutter web applications. ```javascript if ('serviceWorker' in navigator) { window.addEventListener('flutter-first-frame', function () { navigator.serviceWorker.register('flutter_service_worker.js'); }); } ``` -------------------------------- ### Save Screenshot to Specific Location Source: https://github.com/sachinganesh/screenshot/blob/master/README.md Demonstrates how to save a captured screenshot to a specific directory using the captureAndSave method. The 'path' parameter specifies the save location. This method is not supported on the web. ```dart import 'package:path_provider/path_provider.dart'; // ... final directory = (await getApplicationDocumentsDirectory()).path; String fileName = DateTime.now().microsecondsSinceEpoch.toString(); String path = directory; screenshotController.captureAndSave( path, fileName: fileName ); ``` -------------------------------- ### Capture a Long Invisible Widget Source: https://github.com/sachinganesh/screenshot/blob/master/README.md Illustrates capturing a long widget, such as a list with many items, that is not rendered on screen using captureFromLongWidget. It's important not to use scrolling widgets within the captured widget. ```dart var randomItemCount = Random().nextInt(100); var myLongWidget = Builder(builder: (context) { return Container( padding: const EdgeInsets.all(30.0), decoration: BoxDecoration( border: Border.all(color: Colors.blueAccent, width: 5.0), color: Colors.redAccent, ), child: Column( mainAxisSize: MainAxisSize.min, children: [ for (int i = 0; i < randomItemCount; i++) Text("Tile Index $i"), ], )); }); screenshotController .captureFromLongWidget( InheritedTheme.captureAll( context, Material( child: myLongWidget, ), ), delay: Duration(milliseconds: 100), context: context ) .then((capturedImage) { // Handle captured image }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.