### Install Target Executable Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/CMakeLists.txt Installs the main application executable (`${BINARY_NAME}`) to the specified installation prefix, marking it as part of the Runtime component. ```CMake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Define Installation Paths Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/CMakeLists.txt Sets variables for the installation directories, including the build bundle directory relative to the target executable, the default installation prefix (set to the bundle directory), and subdirectories for data and libraries within the installation 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}") ``` -------------------------------- ### Installation Setup and Prefix Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Configures the installation process to create a relocatable bundle in the build directory and sets the default installation prefix. ```CMake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Install AOT Library (Profile/Release) Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library, which is typically generated for optimized builds, specifically for the Profile and Release configurations into the data directory. ```CMake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/CMakeLists.txt Defines the name for the assets directory and uses custom CMake code to first remove any existing assets in the installation directory before copying the latest assets from the build directory, ensuring the installed assets are always up-to-date. ```CMake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Required Files Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/CMakeLists.txt Installs essential files required by the Flutter application, including the ICU data file and the main Flutter library, placing them in the designated data and library directories within the installation prefix. ```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) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Application Executable Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Installs the application executable to the installation prefix. ```CMake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Set Installation RPATH Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/CMakeLists.txt Configures the runtime search path (RPATH) for the installed executable to look for shared libraries in a 'lib' subdirectory relative to the executable's location. ```CMake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Initialize CMake Project and Set Binary Name Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/CMakeLists.txt Sets the minimum required CMake version, defines the project name and language, and specifies the name for the output binary executable. ```CMake cmake_minimum_required(VERSION 3.15) project(example LANGUAGES CXX) set(BINARY_NAME "example") cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Initializing Flutter ScreenUtil (Dart) Source: https://github.com/openflutter/flutter_screenutil/blob/master/README_PT.md Shows the standard way to initialize the `flutter_screenutil` library in a Flutter application. It uses a `LayoutBuilder` to get the device constraints and calls `ScreenUtil.init()` with the constraints and the specified `designSize` based on the design prototype (e.g., iPhone 6). This setup is crucial for the library to calculate responsive dimensions correctly. ```Dart ...import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return LayoutBuilder( builder: (context, constraints) { //Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334) ScreenUtil.init(constraints, designSize: Size(750, 1334)); return MaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter_ScreenUtil', theme: ThemeData( primarySwatch: Colors.blue, ), home: HomePage(title: 'FlutterScreenUtil Demo'), ); }, ); } } ``` -------------------------------- ### Install Plugin Bundled Libraries Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Installs any libraries bundled by plugins to the library directory within the bundle, if they exist. ```CMake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Set Installation Destination Variables Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Defines variables for the data and library subdirectories within the installation prefix. ```CMake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Include Generated Plugins Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/CMakeLists.txt Includes a CMake file generated by the Flutter build process that contains build rules for any plugins used by the application, ensuring they are built and linked correctly. ```CMake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Initializing ScreenUtil within Widget Build (Second Method Variation) Source: https://github.com/openflutter/flutter_screenutil/blob/master/README.md Provides another example of the second initialization method, demonstrating how ScreenUtil.init can be called within the build method of a widget, using its context and specifying the design size. ```Dart class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter_ScreenUtil', theme: ThemeData( primarySwatch: Colors.blue, ), home: HomePage(title: 'FlutterScreenUtil Demo'), ); } } class HomePage extends StatefulWidget { const HomePage({Key key, this.title}) : super(key: key); final String title; @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State { @override Widget build(BuildContext context) { //Set the fit size (fill in the screen size of the device in the design) //If the design is based on the size of the 360*690(dp) ScreenUtil.init(context, designSize: const Size(360, 690)); ... } } ``` -------------------------------- ### Add Global Unicode Definitions Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/CMakeLists.txt Adds preprocessor definitions for UNICODE and _UNICODE to all targets, ensuring that the project is built with Unicode support enabled. ```CMake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Set Profile Build Flags Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/CMakeLists.txt Copies the linker and compiler flags from the Release configuration to the Profile configuration, ensuring consistency in optimization and settings between the two release-like modes. ```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_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Project Setup and Naming Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Sets the minimum required CMake version, defines the project name and language, and sets variables for the binary name and application ID. ```CMake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "example") set(APPLICATION_ID "li.zhuoyuan.example") ``` -------------------------------- ### Include Flutter and Runner Subdirectories Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/CMakeLists.txt Sets a variable pointing to the Flutter managed directory and includes the build rules from the Flutter and application runner subdirectories, incorporating their targets and configurations into the main project. ```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") ``` -------------------------------- ### Using ScreenUtil for Responsive Layout (Dart) Source: https://github.com/openflutter/flutter_screenutil/blob/master/README_PT.md Illustrates how to apply responsive sizing using `flutter_screenutil` within a widget's build method. It shows examples of setting width, height, and font size using both the convenient extension methods (like `.w`, `.h`, `.sw`, `.sp`) and the older method calls (like `setWidth`, `setHeight`, `setSp`). It also displays various device and design-related properties obtained from `ScreenUtil`. ```Dart class HomePage extends StatefulWidget { const HomePage({Key key, this.title}) : super(key: key); final String title; @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State { @override Widget build(BuildContext context) { //Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the iPhone6 ​​(iPhone6 ​​750*1334) printScreenInformation(); return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Row( children: [ // Using Extensions Container( padding: EdgeInsets.all(10.w), width: 0.5.sw, height: 200.h, color: Colors.red, child: Text( 'My width:${0.5.sw}dp \n' 'My height:${200.h}dp', style: TextStyle( color: Colors.white, fontSize: 24.sp, ), ), ), // Without using Extensions Container( padding: EdgeInsets.all(ScreenUtil().setWidth(10)), width: ScreenUtil().screenWidth * 0.5, height: ScreenUtil().setHeight(200), color: Colors.blue, child: Text( 'My width:${ScreenUtil().screenWidth * 0.5}dp \n' 'My height:${ScreenUtil().setHeight(200)}dp', style: TextStyle( color: Colors.white, fontSize: ScreenUtil().setSp(24), ), ), ), ], ), Text('Device width:${ScreenUtil().screenWidthPx}px'), Text('Device height:${ScreenUtil().screenHeightPx}px'), Text('Device width:${ScreenUtil().screenWidth}dp'), Text('Device height:${ScreenUtil().screenHeight}dp'), Text('Device pixel density:${ScreenUtil().pixelRatio}'), Text('Bottom safe zone distance:${ScreenUtil().bottomBarHeight}dp'), Text('Status bar height:${ScreenUtil().statusBarHeight}dp'), Text( 'Ratio of actual width dp to design draft px:${ScreenUtil().scaleWidth}', textAlign: TextAlign.center, ), Text( 'Ratio of actual height dp to design draft px:${ScreenUtil().scaleHeight}', textAlign: TextAlign.center, ), SizedBox( height: 5.h, ), Text('System font scaling factor:${ScreenUtil().textScaleFactor}'), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'My font size is 24px on the design draft and will not change with the system.', style: TextStyle( color: Colors.black, fontSize: 24.sp, ), ), Text( 'My font size is 24px on the design draft and will change with the system.', style: TextStyle( ``` -------------------------------- ### Example of Adapted Font Size in Text Widget Source: https://github.com/openflutter/flutter_screenutil/blob/master/README.md Provides a practical example of applying adapted font sizes (.sp) to Text widgets within a Column. Demonstrates how textScaleFactor can influence whether the font size changes with system settings. ```Dart Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( '16sp, will not change with the system.', style: TextStyle( color: Colors.black, fontSize: 16.sp, ), textScaleFactor: 1.0, ), Text( '16sp,if data is not set in MediaQuery,my font size will change with the system.', style: TextStyle( color: Colors.black, fontSize: 16.sp, ), ), ], ) ``` -------------------------------- ### Install Flutter Data and Libraries Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Installs the Flutter ICU data file and the main Flutter library to the appropriate subdirectories within the bundle. ```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) ``` -------------------------------- ### Initial CMake Setup and Configuration Include Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/flutter/CMakeLists.txt Sets the minimum required CMake version and includes a generated configuration file, typically produced by the Flutter tool, which provides build-specific variables and settings. ```CMake cmake_minimum_required(VERSION 3.10) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### Install AOT Library (Non-Debug) Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the bundle's library directory, but only for non-Debug builds (Profile and Release). ```CMake # Install the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Define Standard Settings Function Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/CMakeLists.txt Defines a CMake function `APPLY_STANDARD_SETTINGS` that applies common compilation settings to a given target, including C++17 standard, specific compiler options (like warning levels and exception handling), and configuration-dependent 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() ``` -------------------------------- ### Initializing ScreenUtil Instance - Flutter/Dart Source: https://github.com/openflutter/flutter_screenutil/blob/master/CHANGELOG.md Shows the updated recommended way to get a ScreenUtil instance using the constructor 'ScreenUtil()' instead of the deprecated 'ScreenUtil.getInstance()'. ```Dart ScreenUtil() ``` ```Dart ScreenUtil.getInstance() ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Removes existing assets and then copies the Flutter assets directory into the bundle's 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) ``` -------------------------------- ### Using Proportional Width/Height Extensions - Flutter/Dart Source: https://github.com/openflutter/flutter_screenutil/blob/master/CHANGELOG.md Demonstrates the usage of the new '.wp' and '.hp' extension methods to get a proportional width or height of the screen. For example, '0.5.wp' represents half the screen width. ```Dart 0.5.wp ``` ```Dart 0.5.hp ``` -------------------------------- ### Clean Build Bundle Directory Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Adds an installation step to remove the contents of the build bundle directory before installing new files, ensuring a clean bundle. ```CMake # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Defining Square and Rectangle Dimensions Source: https://github.com/openflutter/flutter_screenutil/blob/master/README.md Illustrates different strategies for defining the dimensions of widgets to create rectangles or squares that adapt to screen size. Shows examples using .w (based on width), .h (based on height), and .r (based on the minimum of width/height). ```Dart //for example: //If you want to display a rectangle: Container( width: 375.w, height: 375.h, ), //If you want to display a square based on width: Container( width: 300.w, height: 300.w, ), //If you want to display a square based on height: Container( width: 300.h, height: 300.h, ), //If you want to display a square based on minimum(height, width): Container( width: 300.r, height: 300.r, ), ``` -------------------------------- ### Incorrect TextTheme Configuration (Second Method Limitation) Source: https://github.com/openflutter/flutter_screenutil/blob/master/README.md Illustrates a TextTheme configuration within MaterialApp that is not supported when using the second initialization method (ScreenUtil.init(ctx)). It highlights a limitation requiring the first method (ScreenUtilInit) for this specific theme setup. ```Dart MaterialApp( ... //To support the following, you need to use the first initialization method theme: ThemeData( textTheme: TextTheme( button: TextStyle(fontSize: 45.sp) ), ), ) ``` -------------------------------- ### Set CMake Policy and RPATH Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Configures a specific CMake policy for target properties and sets the runtime path for installed binaries to find libraries. ```CMake cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Create Square using ScreenUtil radius extension (Dart) Source: https://github.com/openflutter/flutter_screenutil/blob/master/README_PT.md Example of creating a square where both width and height are scaled using the `.r` extension. While primarily for radius, using `.r` for both dimensions ensures equal scaling to maintain a square shape. ```Dart ////Se quiser exibir um quadrado: Container( width: 300.r, height: 300.r, ), ``` -------------------------------- ### Create Rectangle using ScreenUtil width extension (Dart) Source: https://github.com/openflutter/flutter_screenutil/blob/master/README_PT.md Example of creating a rectangle where both width and height are scaled based on the screen width using the `.w` extension. This approach can help maintain aspect ratio relative to the design width. ```Dart //Exemplo: //Retângulo Container( width: 375.w, height: 200.w, ... ), ``` -------------------------------- ### Configure Build Types Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/CMakeLists.txt Determines if the generator supports multiple configurations (like Visual Studio) and sets the available build types (Debug, Profile, Release). If not a multi-config generator, it sets the default build type to Debug if none is specified. ```CMake get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) elif(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() ``` -------------------------------- ### Printing Device Screen Information using flutter_screenutil (Dart) Source: https://github.com/openflutter/flutter_screenutil/blob/master/README_PT.md This function demonstrates how to retrieve and print various screen-related metrics using the `ScreenUtil` instance and extension properties like `.sw` and `.sh`. It shows how to get device dimensions, pixel ratio, safe area height, status bar height, scaling factors, and scaled dimensions. ```Dart void printScreenInformation() { print('Device width dp:${1.sw}'); //Device width print('Device height dp:${1.sh}'); //Device height print('Device pixel density:${ScreenUtil().pixelRatio}'); //Device pixel density print( 'Bottom safe zone distance dp:${ScreenUtil().bottomBarHeight}'); //Bottom safe zone distance,suitable for buttons with full screen print( 'Status bar height px:${ScreenUtil().statusBarHeight}dp'); //Status bar height , Notch will be higher Unit px print('Ratio of actual width dp to UI Design:${ScreenUtil().scaleWidth}'); print('Ratio of actual height dp to UI Design:${ScreenUtil().scaleHeight}'); print('System font scaling:${ScreenUtil().textScaleFactor}'); print('0.5 times the screen width:${0.5.sw}'); print('0.5 times the screen height:${0.5.sh}'); } ``` -------------------------------- ### Initializing ScreenUtil with ScreenUtilInit (First Method) Source: https://github.com/openflutter/flutter_screenutil/blob/master/README.md Demonstrates the primary method for initializing flutter_screenutil by wrapping the root MaterialApp with ScreenUtilInit. It shows setting the design size, enabling text adaptation, and using the builder pattern for context access. ```Dart void main() => runApp(MyApp()); class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { //Set the fit size (Find your UI design, look at the dimensions of the device screen and fill it in,unit in dp) return ScreenUtilInit( designSize: const Size(360, 690), minTextAdapt: true, splitScreenMode: true, // Use builder only if you need to use library outside ScreenUtilInit context builder: (_ , child) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'First Method', // You can use the library anywhere in the app even in theme theme: ThemeData( primarySwatch: Colors.blue, textTheme: Typography.englishLike2018.apply(fontSizeFactor: 1.sp), ), home: child, ); }, child: const HomePage(title: 'First Method'), ); } } ``` -------------------------------- ### Initializing ScreenUtil with ScreenUtil.init (Second Method) Source: https://github.com/openflutter/flutter_screenutil/blob/master/README.md Shows an alternative initialization method suitable for hybrid development. It involves calling ScreenUtil.ensureScreenSize() before runApp and ScreenUtil.init(ctx) within the MaterialApp builder to initialize the library using the current context. ```Dart void main() async { // Add this line await ScreenUtil.ensureScreenSize(); runApp(MyApp()); } ... MaterialApp( ... builder: (ctx, child) { ScreenUtil.init(ctx); return Theme( data: ThemeData( primarySwatch: Colors.blue, textTheme: TextTheme(bodyText2: TextStyle(fontSize: 30.sp)), ), child: HomePage(title: 'FlutterScreenUtil Demo'), ); }, ) ``` -------------------------------- ### Using Flutter ScreenUtil Methods and Extensions Source: https://github.com/openflutter/flutter_screenutil/blob/master/README.md Demonstrates various methods and extension properties provided by flutter_screenutil for adapting dimensions, fonts, spacing, and accessing screen metrics. Shows both the older method calls and the newer extension syntax (for Dart SDK >= 2.6). ```Dart ScreenUtil().setWidth(540) (dart sdk>=2.6 : 540.w) //Adapted to screen width ScreenUtil().setHeight(200) (dart sdk>=2.6 : 200.h) //Adapted to screen height , under normal circumstances, the height still uses x.w ScreenUtil().radius(200) (dart sdk>=2.6 : 200.r) //Adapt according to the smaller of width or height ScreenUtil().setSp(24) (dart sdk>=2.6 : 24.sp) //Adapter font 12.sm //return min(12,12.sp) ScreenUtil().pixelRatio //Device pixel density ScreenUtil().screenWidth (dart sdk>=2.6 : 1.sw) //Device width ScreenUtil().screenHeight (dart sdk>=2.6 : 1.sh) //Device height ScreenUtil().bottomBarHeight //Bottom safe zone distance, suitable for buttons with full screen ScreenUtil().statusBarHeight //Status bar height , Notch will be higher ScreenUtil().textScaleFactor //System font scaling factor ScreenUtil().scaleWidth //The ratio of actual width to UI design ScreenUtil().scaleHeight //The ratio of actual height to UI design ScreenUtil().orientation //Screen orientation 0.2.sw //0.2 times the screen width 0.5.sh //50% of screen height 20.setVerticalSpacing // SizedBox(height: 20 * scaleHeight) 20.horizontalSpace // SizedBox(height: 20 * scaleWidth) const RPadding.all(8) // Padding.all(8.r) - take advantage of const key word EdgeInsets.all(10).w //EdgeInsets.all(10.w) REdgeInsets.all(8) // EdgeInsets.all(8.r) EdgeInsets.only(left:8,right:8).r // EdgeInsets.only(left:8.r,right:8.r). BoxConstraints(maxWidth: 100, minHeight: 100).w //BoxConstraints(maxWidth: 100.w, minHeight: 100.w) Radius.circular(16).w //Radius.circular(16.w) BorderRadius.all(Radius.circular(16)).w ``` -------------------------------- ### Define Flutter Wrapper Plugin Static Library Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/flutter/CMakeLists.txt Creates a STATIC library target named `flutter_wrapper_plugin` using the core and plugin C++ wrapper source files. It applies standard settings, sets target properties for position-independent code and symbol visibility, links against the `flutter` interface library, specifies include directories for the wrapper headers, and adds a dependency on `flutter_assemble`. ```CMake 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) ``` -------------------------------- ### Define Flutter Wrapper App Static Library Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/flutter/CMakeLists.txt Creates a STATIC library target named `flutter_wrapper_app` using the core and application-specific C++ wrapper source files. It applies standard settings, links against the `flutter` interface library, specifies include directories for the wrapper headers, and adds a dependency on `flutter_assemble`. ```CMake 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) ``` -------------------------------- ### Defining Custom Command for Flutter Tool Backend Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/flutter/CMakeLists.txt Sets up a custom command that executes the Flutter tool's backend script. This script is responsible for assembling the Flutter engine and application artifacts. The command's outputs include the Flutter library and headers, and a phony file to ensure it runs 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 ) ``` -------------------------------- ### Add Application Executable Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Defines the main application executable target, adds source files, applies standard settings, links necessary libraries (flutter, GTK), and sets dependencies. ```CMake # Application build add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) apply_standard_settings(${BINARY_NAME}) target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Initializing Without Context - Flutter/Dart Source: https://github.com/openflutter/flutter_screenutil/blob/master/CHANGELOG.md Illustrates the change to use 'MediaQueryData.fromWindow(window)' for initialization, removing the requirement for a BuildContext parameter. ```Dart MediaQueryData.fromWindow(window) ``` ```Dart MediaQuery.of(context) ``` -------------------------------- ### Define C++ Wrapper Source File Lists Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/flutter/CMakeLists.txt Defines separate list variables for core, plugin, and application-specific C++ wrapper source files. It then transforms each list by prepending the `WRAPPER_ROOT` path to the file names, creating full paths to the source files. ```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}/") ``` -------------------------------- ### Adapting Widget Dimensions with ScreenUtil Source: https://github.com/openflutter/flutter_screenutil/blob/master/README.md Shows how to set the width and height of a widget (like Container) using flutter_screenutil. Presents the older method call syntax (ScreenUtil().setWidth/setHeight) and the more concise extension syntax (.w, .h) available in newer Dart SDK versions. ```Dart Container( width: ScreenUtil().setWidth(50), height:ScreenUtil().setHeight(200), ) ``` ```Dart Container( width: 50.w, height:200.h ) ``` -------------------------------- ### Testing Flutter Widgets with pumpAndSettle (Dart) Source: https://github.com/openflutter/flutter_screenutil/blob/master/README.md Demonstrates a widget test using `flutter_screenutil` in version 5.9.0 or later. It shows the required inclusion of `await tester.pumpAndSettle()` after pumping the widget tree to ensure animations and state changes complete before assertions, preventing potential test failures. ```Dart testWidgets('Should ensure widgets settle correctly', (WidgetTester tester) async { await tester.pumpWidget( const MaterialApp( home: ScreenUtilInit( child: MyApp(), ), ), ); // Insertion of recommended method to prevent failures await tester.pumpAndSettle(); // Continue with your assertions and tests }); ``` -------------------------------- ### Find System Dependencies (GTK) Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Uses PkgConfig to find and import the GTK 3.0 library as a required system dependency. ```CMake # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Configuring Windows Runner Executable with CMake Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/runner/CMakeLists.txt This CMake snippet defines the project, adds the main executable for the Windows runner, lists the required source files and resources, applies standard build settings, adds a private compile definition, links necessary Flutter libraries, includes source directories, and 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) ``` -------------------------------- ### Using Dimension Extension Methods (.w, .h, .sp, .ssp) - Flutter/Dart Source: https://github.com/openflutter/flutter_screenutil/blob/master/CHANGELOG.md Demonstrates the use of extension methods like '.w', '.h', '.sp', and '.ssp' as a concise alternative to the older 'setWidth', 'setHeight', and 'setSp' methods. ```Dart width: 50.w ``` ```Dart width: ScreenUtil().setWidth(50) ``` ```Dart 50.h ``` ```Dart ScreenUtil().setHeight(50) ``` ```Dart 24.sp ``` ```Dart ScreenUtil().setSp(24) ``` ```Dart 24.ssp ``` ```Dart ScreenUtil().setSp(24, allowFontScalingSelf: true) ``` -------------------------------- ### Finding System Dependencies (GTK, GLIB, GIO) Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/flutter/CMakeLists.txt Uses `find_package` and `pkg_check_modules` with `PkgConfig` to locate required system libraries like GTK 3, GLIB 2, and GIO 2, importing them as CMake targets. ```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) ``` -------------------------------- ### Adapting Font Size with ScreenUtil Source: https://github.com/openflutter/flutter_screenutil/blob/master/README.md Explains how to adapt font sizes using flutter_screenutil. Shows the method call ScreenUtil().setSp() and the extension property .sp for scaling font size based on the screen dimensions. ```Dart //Incoming font size(The unit is the same as the unit at initialization) ScreenUtil().setSp(28) 28.sp ``` -------------------------------- ### Adding flutter_screenutil Dependency (YAML) Source: https://github.com/openflutter/flutter_screenutil/blob/master/README_PT.md To use the flutter_screenutil package, add it as a dependency in your project's pubspec.yaml file. Ensure you use the latest version available. ```YAML dependencies: flutter: sdk: flutter # add flutter_screenutil flutter_screenutil: ^{latest version} ``` -------------------------------- ### Set C++ Wrapper Root Directory Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/flutter/CMakeLists.txt Defines a variable `WRAPPER_ROOT` pointing to the directory containing the C++ client wrapper source files, located within the ephemeral directory. ```CMake set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") ``` -------------------------------- ### Include Generated Plugin Rules Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Includes the CMake file generated by Flutter that contains build rules for any plugins used by the application. ```CMake # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Define Flutter Interface Library Target Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/flutter/CMakeLists.txt Creates an INTERFACE library target named `flutter`. This target represents the Flutter engine dependency. It specifies the include directories required to use the Flutter headers and links against the Flutter library import file (`.lib`). It also adds a dependency on the `flutter_assemble` target to ensure the necessary files are generated before this target is configured. ```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) ``` -------------------------------- ### Set Widget Size using ScreenUtil extensions (Dart) Source: https://github.com/openflutter/flutter_screenutil/blob/master/README_PT.md Shows how to use the `.w` and `.h` extension methods (available for Dart SDK >= 2.6) to set widget width and height concisely based on design prototype pixel values. ```Dart Container( width: 50.w, height:200.h ) ``` -------------------------------- ### Accessing ScreenUtil Properties (Dart) Source: https://github.com/openflutter/flutter_screenutil/blob/master/README_PT.md Demonstrates how to access various static and instance properties provided by the `flutter_screenutil` library to retrieve device screen dimensions, pixel density, safe area heights, text scale factor, and scaling ratios relative to the design prototype. ```Dart ScreenUtil.pixelRatio //Densidade de pixels do dispositivo ScreenUtil.screenWidth //Largura da tela do dispositivo ScreenUtil.screenHeight //Altura da tela do dispositivo ScreenUtil.bottomBarHeight //Distância segura do rodapé, adequada para botões em tela cheia ScreenUtil.statusBarHeight //Altura da status bar em pixels, Notch será maior ScreenUtil.textScaleFactor //Fator de escala da fonte do sistema ScreenUtil().scaleWidth //Razão entre a largura atual e a largura do protótipo de design em pixels ScreenUtil().scaleHeight //Razão entre a altura atual e a altura do protótipo de design em pixels ``` -------------------------------- ### Define Flutter Assemble Custom Command and Target Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/flutter/CMakeLists.txt Defines a custom command that executes the Flutter tool backend script to assemble necessary build artifacts (Flutter library, headers, wrapper sources). A phony output file (`_phony_`) is used to force the command to run on every build. A custom target `flutter_assemble` is created with dependencies on the outputs of the custom command, ensuring the assembly process completes before any targets that rely on these files. ```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} ) ``` -------------------------------- ### Adding Dependency for flutter_screenutil in YAML Source: https://github.com/openflutter/flutter_screenutil/blob/master/README.md This YAML snippet shows how to add the `flutter_screenutil` package as a dependency in your Flutter project's `pubspec.yaml` file. Replace `{latest version}` with the current version of the package. This is required to use the library in your project. ```YAML dependencies: flutter: sdk: flutter # add flutter_screenutil flutter_screenutil: ^{latest version} ``` -------------------------------- ### Define Flutter Library Headers List Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/flutter/CMakeLists.txt Creates a list variable `FLUTTER_LIBRARY_HEADERS` containing the names of essential Flutter library header files. It then transforms the list by prepending the ephemeral directory path to each header file 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}/") ``` -------------------------------- ### Defining Flutter Interface Library Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/flutter/CMakeLists.txt Creates an `INTERFACE` library target named `flutter`. It specifies include directories and links the previously defined Flutter engine library and system dependencies (GTK, GLIB, GIO) to this interface. ```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 ) ``` -------------------------------- ### Set Widget Size using ScreenUtil methods (Dart) Source: https://github.com/openflutter/flutter_screenutil/blob/master/README_PT.md Demonstrates setting the width and height of a Container widget using the `ScreenUtil().setWidth()` and `ScreenUtil().setHeight()` methods based on design prototype pixel values. ```Dart Container( width: ScreenUtil().setWidth(50), height:ScreenUtil().setHeight(200), ) ``` -------------------------------- ### Importing flutter_screenutil Package in Dart Source: https://github.com/openflutter/flutter_screenutil/blob/master/README.md This Dart snippet demonstrates the necessary import statement to use the classes and functions provided by the `flutter_screenutil` package within your Dart code. Place this line at the top of any `.dart` file where you intend to use the library. ```Dart import 'package:flutter_screenutil/flutter_screenutil.dart'; ``` -------------------------------- ### Include Flutter Build Rules Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Includes the CMake build rules managed by Flutter, typically found in the 'flutter' subdirectory. ```CMake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") # Flutter library and tool build rules. add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Set Minimum CMake Version and Ephemeral Directory Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/flutter/CMakeLists.txt Specifies the minimum required version of CMake for the project and defines a variable pointing to the ephemeral build directory used by the Flutter tool. ```CMake cmake_minimum_required(VERSION 3.15) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") ``` -------------------------------- ### Include Generated Configuration File Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/windows/flutter/CMakeLists.txt Includes a CMake configuration file (`generated_config.cmake`) located within the ephemeral directory. This file is generated by the Flutter tool and contains build-specific settings. ```CMake include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### Configure Cross-Building Sysroot Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Sets the CMake system root and find paths if a target platform sysroot is specified, typically used for cross-compilation scenarios. ```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 Standard Compilation Settings Function Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Defines a CMake function to apply standard compilation settings, including C++ standard, warning flags, optimization, and debug definitions. ```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() ``` -------------------------------- ### Define Application ID Macro Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Adds a preprocessor definition for the application ID, making it available in the C++ source code. ```CMake add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Using setSp Method with Font Scaling - Flutter/Dart Source: https://github.com/openflutter/flutter_screenutil/blob/master/CHANGELOG.md Provides the method signature and logic for the 'setSp' method, showing how the 'allowFontScaling' parameter affects the calculated font size. ```Dart setSp(int fontSize, [allowFontScaling = false]) => allowFontScaling ? setWidth(fontSize) * _textScaleFactor : setWidth(fontSize); ``` -------------------------------- ### Managing Flutter Library Headers List Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/flutter/CMakeLists.txt Appends a list of standard Flutter Linux header files to the `FLUTTER_LIBRARY_HEADERS` variable and then uses the custom `list_prepend` function to add the ephemeral directory path to each header file name. ```CMake list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") ``` -------------------------------- ### Configure Executable Output Directory Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/CMakeLists.txt Sets the output directory for the executable to a subdirectory to prevent users from running the unbundled executable directly. ```CMake # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of # the default top-level location. set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Custom CMake Function list_prepend Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/flutter/CMakeLists.txt Defines a helper function `list_prepend` that prepends a given prefix to each element in a list. This is used to modify lists in a way similar to `list(TRANSFORM ... PREPEND ...)` but compatible with older CMake versions. ```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() ``` -------------------------------- ### Defining Custom Target for Flutter Assemble Source: https://github.com/openflutter/flutter_screenutil/blob/master/example/linux/flutter/CMakeLists.txt Creates a custom target named `flutter_assemble` which depends on the outputs of the `add_custom_command` that runs the Flutter tool backend. This target represents the step of assembling the Flutter engine and application. ```CMake add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ```