### Installation Bundle Setup Source: https://github.com/flutter/packages/blob/main/packages/path_provider/path_provider/example/linux/CMakeLists.txt Configures the installation process, setting the build bundle directory and initial 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_BUNDLLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Installation Configuration Source: https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector_linux/example/linux/CMakeLists.txt Sets up the installation directory and installs the application executable, data files, and libraries. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() 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) if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/flutter/packages/blob/main/packages/url_launcher/url_launcher_linux/example/linux/CMakeLists.txt Initializes the CMake project, sets the minimum version, project name, and binary name. Configures build policies and installation paths. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Full Screen Camera Preview Example Source: https://github.com/flutter/packages/blob/main/packages/camera/camera/README.md This example demonstrates how to initialize and display a full-screen camera preview using the camera package. It includes setup for available cameras and handling initialization errors. ```dart import 'package:camera/camera.dart'; import 'package:flutter/material.dart'; late List _cameras; Future main() async { WidgetsFlutterBinding.ensureInitialized(); _cameras = await availableCameras(); runApp(const CameraApp()); } /// CameraApp is the Main Application. class CameraApp extends StatefulWidget { /// Default Constructor const CameraApp({super.key}); @override State createState() => _CameraAppState(); } class _CameraAppState extends State { late CameraController controller; @override void initState() { super.initState(); controller = CameraController(_cameras[0], ResolutionPreset.max); controller .initialize() .then((_) { if (!mounted) { return; } setState(() {}); }) .catchError((Object e) { if (e is CameraException) { switch (e.code) { case 'CameraAccessDenied': // Handle access errors here. break; default: // Handle other errors here. break; } } }); } @override void dispose() { controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { if (!controller.value.isInitialized) { return Container(); } return MaterialApp(home: CameraPreview(controller)); } } ``` -------------------------------- ### Get Started with GoRouter Source: https://github.com/flutter/packages/blob/main/packages/go_router/example/README.md Demonstrates a simple two-page app using GoRouter. Run with `flutter run lib/main.dart`. ```dart flutter run lib/main.dart ``` -------------------------------- ### Configure Installation Bundle Source: https://github.com/flutter/packages/blob/main/packages/shared_preferences/shared_preferences/example/linux/CMakeLists.txt Sets up the installation process to create a relocatable bundle. It cleans the build directory and defines installation paths for data, libraries, and assets. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Run Example Project Source: https://github.com/flutter/packages/blob/main/packages/animations/README.md Navigate to the example directory and run the Flutter project with the --release flag to see animations in action. ```bash cd example/ flutter run --release ``` -------------------------------- ### Install Application Bundle Source: https://github.com/flutter/packages/blob/main/packages/rfw/example/local/linux/CMakeLists.txt Configures the installation process to create a relocatable bundle in the build directory. It includes rules for cleaning the bundle, installing the executable, data files, libraries, and assets. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() 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 Application Bundle Source: https://github.com/flutter/packages/blob/main/packages/pigeon/platform_tests/test_plugin/example/linux/CMakeLists.txt Configures the installation process to create a relocatable application bundle. This includes clearing the build directory, installing the executable, data files, and bundled libraries. ```cmake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 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) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Application Bundle Components Source: https://github.com/flutter/packages/blob/main/packages/two_dimensional_scrollables/example/linux/CMakeLists.txt Defines installation rules for creating a relocatable application bundle. This includes installing the executable, data files, libraries, and assets. ```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) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) 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) ``` -------------------------------- ### Configure Installation Directory Source: https://github.com/flutter/packages/blob/main/packages/shared_preferences/shared_preferences/example/windows/CMakeLists.txt Sets up installation directories for the application bundle, ensuring files are placed correctly next to the executable. ```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 - Build Bundle Directory Source: https://github.com/flutter/packages/blob/main/packages/image_picker/image_picker/example/linux/CMakeLists.txt Configures the installation prefix to be the build bundle directory and ensures it's clean before installation. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Install Application Executable and Support Files Source: https://github.com/flutter/packages/blob/main/packages/path_provider/path_provider/example/windows/CMakeLists.txt Installs the main application executable, ICU data, Flutter library, and any bundled plugin libraries to their respective destinations within the installation prefix. This prepares the application bundle for deployment. ```cmake 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() ``` -------------------------------- ### Run Material UI Example Source: https://github.com/flutter/packages/blob/main/packages/material_ui/example/README.md Demonstrates how to run a specific Material UI example from the command line. This command targets a Chrome browser for execution. ```sh % flutter run -d chrome lib/about/about_list_tile.0.dart ``` -------------------------------- ### Define Installation Directories Source: https://github.com/flutter/packages/blob/main/packages/google_fonts/example/linux/CMakeLists.txt Sets the destination directories for data and libraries within the installation bundle. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Drive Example on Android Source: https://github.com/flutter/packages/blob/main/script/tool/README.md Runs integration tests for a package's examples on Android. Replace `--android` with other platform flags as needed. ```sh fpt drive-examples --android --packages package_name ``` -------------------------------- ### Configure Installation Paths for Runtime Components Source: https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector/example/windows/CMakeLists.txt Sets up installation directories for the application executable, data files, and libraries. This ensures that all necessary components are placed correctly for runtime execution. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Basic RemoteWidget Example Source: https://github.com/flutter/packages/blob/main/packages/rfw/README.md Renders a remote widget with hardcoded library and data. This example shows the fundamental setup for displaying remote UI elements. ```dart class Example extends StatefulWidget { const Example({super.key}); @override State createState() => _ExampleState(); } class _ExampleState extends State { final Runtime _runtime = Runtime(); final DynamicContent _data = DynamicContent(); // Normally this would be obtained dynamically, but for this example // we hard-code the "remote" widgets into the app. // // Also, normally we would decode this with [decodeLibraryBlob] rather than // parsing the text version using [parseLibraryFile]. However, to make it // easier to demo, this uses the slower text format. static final RemoteWidgetLibrary _remoteWidgets = parseLibraryFile(''' // The "import" keyword is used to specify dependencies, in this case, // the built-in widgets that are added by initState below. import core.widgets; // The "widget" keyword is used to define a new widget constructor. // The "root" widget is specified as the one to render in the build // method below. widget root = Container( color: 0xFF002211, child: Center( child: Text(text: ["Hello, ", data.greet.name, "!"], textDirection: "ltr"), ), ); '''); static const LibraryName coreName = LibraryName(['core', 'widgets']); static const LibraryName mainName = LibraryName(['main']); @override void initState() { super.initState(); // Local widget library: _runtime.update(coreName, createCoreWidgets()); // Remote widget library: _runtime.update(mainName, _remoteWidgets); // Configuration data: _data.update('greet', {'name': 'World'}); } @override Widget build(BuildContext context) { return RemoteWidget( runtime: _runtime, data: _data, widget: const FullyQualifiedWidgetName(mainName, 'root'), onEvent: (String name, DynamicMap arguments) { // The example above does not have any way to trigger events, but if it // did, they would result in this callback being invoked. debugPrint('user triggered event "$name" with data: $arguments'); }, ); } } ``` -------------------------------- ### Run Button Tester Example Source: https://github.com/flutter/packages/blob/main/packages/google_sign_in/google_sign_in_web/example/README.md Command to run the button tester example app on Chrome. Ensure you are in the package directory. ```bash flutter run -d chrome --target=lib/button_tester.dart ``` -------------------------------- ### Configure Installation Paths Source: https://github.com/flutter/packages/blob/main/packages/local_auth/local_auth/example/windows/CMakeLists.txt Sets up installation directories for the application bundle, ensuring files are placed correctly relative to the executable. This is particularly important for running the application in place. ```cmake 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}") ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/flutter/packages/blob/main/packages/path_provider/path_provider_linux/example/linux/CMakeLists.txt Initializes the CMake project, sets the minimum version, project name, and binary name. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "example") set(APPLICATION_ID "dev.flutter.plugins.path_provider_linux_example") ``` -------------------------------- ### Dartdoc Example Link Source: https://github.com/flutter/packages/blob/main/packages/material_ui/example/README.md This snippet shows how to link a code example within Dartdoc documentation using the `{@example}` tag. The path specifies the location of the example file. ```dart /// {@example /example/lib/about/about_list_tile.0.dart} /// Write a description of the example here. This description will appear in the /// API web documentation to introduce the example. /// {@end-example} ``` -------------------------------- ### Configure Installation Directory Source: https://github.com/flutter/packages/blob/main/packages/image_picker/image_picker_windows/example/windows/CMakeLists.txt Sets up installation paths for the application and its data files. It ensures that runtime files are placed correctly next to the executable for in-place execution. ```cmake # 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}") ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector_linux/example/linux/CMakeLists.txt Initializes the CMake project, sets the minimum version, and defines the project name and languages. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) ``` -------------------------------- ### Install Application Executable Source: https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector/example/windows/CMakeLists.txt Installs the main application executable to the specified runtime destination. This is a core step in making the application runnable. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Install application runtime components Source: https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector/example/linux/CMakeLists.txt Defines the installation rules for the application bundle. It ensures a clean bundle directory, installs the executable, ICU data, Flutter library, and any bundled plugin libraries to their respective destinations. ```cmake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 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) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Dartdoc Example Tag Source: https://github.com/flutter/packages/blob/main/packages/cupertino_ui/example/README.md Use the `{@example}` tag in Dartdoc comments to link to external code examples. The path specifies the location of the example file. ```dart /// {@example /example/lib/activity_indicator/cupertino_activity_indicator.0.dart} /// Write a description of the example here. This description will appear in the /// API web documentation to introduce the example. /// {@end-example} ``` -------------------------------- ### Build Example APK Source: https://github.com/flutter/packages/blob/main/script/tool/README.md Builds an APK for the examples of a specified package. This is part of the integration testing process for Flutter plugins. ```sh fpt build-examples --apk --packages package_name ``` -------------------------------- ### Installing Flutter Library and Bundled Libraries Source: https://github.com/flutter/packages/blob/main/packages/image_picker/image_picker_linux/example/linux/CMakeLists.txt Installs the main Flutter library and any bundled plugin libraries to the library directory within the installation bundle. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Install Application Executable and Support Files Source: https://github.com/flutter/packages/blob/main/packages/image_picker/image_picker/example/windows/CMakeLists.txt Installs the main application executable, ICU data, Flutter library, and any bundled plugin libraries to their designated runtime destinations. This prepares the application for execution. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Application and Assets Source: https://github.com/flutter/packages/blob/main/packages/shared_preferences/shared_preferences/example/linux/CMakeLists.txt Installs the application executable, Flutter ICU data, Flutter library, and bundled plugin libraries into the specified installation directories. It also ensures assets are copied correctly. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() 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) ``` -------------------------------- ### Installation Rules for Windows Executable Source: https://github.com/flutter/packages/blob/main/packages/camera/camera_windows/example/windows/CMakeLists.txt Configures the installation process for the Windows executable and its associated files, ensuring runtime dependencies are placed correctly. ```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) ``` -------------------------------- ### Install Application Runtime Files Source: https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector_windows/example/windows/CMakeLists.txt Configures the installation of the main executable, ICU data, libraries, and bundled plugin libraries. It ensures files are placed next to the executable for in-place execution. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Application Target and Data Files Source: https://github.com/flutter/packages/blob/main/packages/rfw/example/hello/windows/CMakeLists.txt Installs the main application executable, ICU data file, and Flutter library to their designated locations. This makes the application ready for deployment. ```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) ``` -------------------------------- ### Install Flutter Library Source: https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector/example/windows/CMakeLists.txt Installs the main Flutter library file. This is a required component for the Flutter runtime. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installing Application Executable and Data Source: https://github.com/flutter/packages/blob/main/packages/image_picker/image_picker_linux/example/linux/CMakeLists.txt Installs the application executable to the prefix, and ICU data to the data directory 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 Bundled Libraries Source: https://github.com/flutter/packages/blob/main/packages/google_fonts/example/linux/CMakeLists.txt Installs all bundled libraries required by plugins to the lib directory within the bundle. ```cmake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Installation Prefix Configuration Source: https://github.com/flutter/packages/blob/main/packages/google_fonts/example/linux/CMakeLists.txt Configures the installation prefix, defaulting to a 'bundle' directory within the build directory for relocatable applications. ```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() ``` -------------------------------- ### Books App Example with GoRouter Source: https://github.com/flutter/packages/blob/main/packages/go_router/example/README.md A fully-fledged example showcasing various GoRouter APIs in a books application. Run with `flutter run lib/books/main.dart`. ```dart flutter run lib/books/main.dart ``` -------------------------------- ### Run Cupertino Activity Indicator Example Source: https://github.com/flutter/packages/blob/main/packages/cupertino_ui/example/README.md Demonstrates how to run a specific example from the cupertino_ui package, such as the CupertinoActivityIndicator, using the Flutter CLI. ```sh % flutter run -d chrome lib/activity_indicator/cupertino_activity_indicator.0.dart ``` -------------------------------- ### Example Local Widget Library with Hot Reload Source: https://github.com/flutter/packages/blob/main/packages/rfw/README.md This example demonstrates how to create a local widget library and integrate it with RFW's `Runtime` for real-time updates during development using the `reassemble` method. It defines custom widgets 'GreenBox' and 'Hello' and uses them in a remote widget definition. ```dart class Example extends StatefulWidget { const Example({super.key}); @override State createState() => _ExampleState(); } class _ExampleState extends State { final Runtime _runtime = Runtime(); final DynamicContent _data = DynamicContent(); @override void initState() { super.initState(); _update(); } @override void reassemble() { // This function causes the Runtime to be updated any time the app is // hot reloaded, so that changes to _createLocalWidgets can be seen // during development. This function has no effect in production. super.reassemble(); _update(); } static WidgetLibrary _createLocalWidgets() { return LocalWidgetLibrary({ 'GreenBox': (BuildContext context, DataSource source) { return ColoredBox(color: const Color(0xFF002211), child: source.child(['child'])); }, 'Hello': (BuildContext context, DataSource source) { return Center( child: Text( 'Hello, ${source.v(["name"])}!', textDirection: TextDirection.ltr, ), ); }, }); } static const LibraryName localName = LibraryName(['local']); static const LibraryName remoteName = LibraryName(['remote']); void _update() { _runtime.update(localName, _createLocalWidgets()); // Normally we would obtain the remote widget library in binary form from a // server, and decode it with [decodeLibraryBlob] rather than parsing the // text version using [parseLibraryFile]. However, to make it easier to // play with this sample, this uses the slower text format. _runtime.update( remoteName, parseLibraryFile(''' import local; widget root = GreenBox( child: Hello(name: "World"), ); '''), ); } @override Widget build(BuildContext context) { return RemoteWidget( runtime: _runtime, data: _data, widget: const FullyQualifiedWidgetName(remoteName, 'root'), onEvent: (String name, DynamicMap arguments) { debugPrint('user triggered event "$name" with data: $arguments'); }, ); } } ``` -------------------------------- ### Initialize Build Bundle Directory Source: https://github.com/flutter/packages/blob/main/packages/two_dimensional_scrollables/example/linux/CMakeLists.txt Sets the installation prefix to the build bundle directory and ensures it's cleaned on each build. This is part of the installation process for creating a relocatable 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(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Build Configuration Variables Source: https://github.com/flutter/packages/blob/main/packages/path_provider/path_provider/example/linux/CMakeLists.txt Sets variables for the binary name, application ID, and installation path. ```cmake set(BINARY_NAME "example") set(APPLICATION_ID "dev.flutter.plugins.path_provider_example") set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Install Application Bundle Components Source: https://github.com/flutter/packages/blob/main/packages/path_provider/path_provider_linux/example/linux/CMakeLists.txt Installs the application executable, ICU data, Flutter library, bundled plugins, and assets into a relocatable bundle structure. ```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) ``` ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Configure Installation Prefix for Bundle Source: https://github.com/flutter/packages/blob/main/packages/path_provider/path_provider/example/windows/CMakeLists.txt Sets the installation prefix to the directory of the executable for in-place running. This ensures that support files are located correctly next to the executable, facilitating development within Visual Studio. ```cmake # 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() ``` -------------------------------- ### Basic GoRouter Configuration Source: https://github.com/flutter/packages/blob/main/packages/go_router/doc/configuration.md Create a GoRouter instance with a list of GoRoute objects for basic navigation setup. ```dart GoRouter( routes: [ GoRoute( path: '/', builder: (context, state) => const Page1Screen(), ), GoRoute( path: '/page2', builder: (context, state) => const Page2Screen(), ), ], ); ``` -------------------------------- ### Library Installation Path Source: https://github.com/flutter/packages/blob/main/packages/google_fonts/example/linux/CMakeLists.txt Configures the runtime path for bundled libraries to be relative to the binary's location. ```cmake # Load bundled libraries from the lib/ directory relative to the binary. set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Build iOS Simulator App Source: https://github.com/flutter/packages/blob/main/packages/interactive_media_ads/CONTRIBUTING.md Run this command in the `example/` directory to build the iOS app for the simulator. This is a prerequisite for updating SDK wrappers. ```bash flutter build ios --simulator ``` -------------------------------- ### Web Integration Test Options Source: https://github.com/flutter/packages/blob/main/packages/pointer_interceptor/pointer_interceptor_web/example/README.md These options are used to build and drive integration examples on the web. Ensure you have the correct packages and chromedriver setup. ```bash --web ``` ```bash --packages pointer_interceptor_web ``` ```bash --run-chromedriver ``` -------------------------------- ### Set Up Flutter Environment Source: https://github.com/flutter/packages/blob/main/AGENTS.md Installs the Flutter SDK and configures the environment path. Ensures Flutter analytics are disabled and precaches necessary resources. Includes a verbose doctor check for configuration verification. ```bash curl -L https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_3.32.8-stable.tar.xz | tar -xJ -C $HOME export FLUTTER_HOME=$HOME/flutter export PATH=$FLUTTER_HOME/bin:$PATH flutter --disable-analytics flutter precache --force # Sanity check the configuration. flutter doctor --verbose ``` -------------------------------- ### Installing AOT Library Source: https://github.com/flutter/packages/blob/main/packages/path_provider/path_provider/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library on non-Debug builds. ```cmake # Install the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Flutter Assets and AOT Library Source: https://github.com/flutter/packages/blob/main/packages/url_launcher/url_launcher/example/linux/CMakeLists.txt Installs the Flutter assets directory and the AOT (Ahead-Of-Time) compiled library. The assets directory is re-copied on each build to prevent stale files. The AOT library is installed only on non-Debug builds. ```cmake # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) # Install the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Basic Video Player Integration Source: https://github.com/flutter/packages/blob/main/packages/video_player/video_player/README.md This example demonstrates how to initialize, display, and control a video player using network URLs. It includes play/pause functionality and handles the player's initialization state. ```dart import 'package:flutter/material.dart'; import 'package:video_player/video_player.dart'; void main() => runApp(const VideoApp()); /// Stateful widget to fetch and then display video content. class VideoApp extends StatefulWidget { const VideoApp({super.key}); @override _VideoAppState createState() => _VideoAppState(); } class _VideoAppState extends State { late VideoPlayerController _controller; @override void initState() { super.initState(); _controller = VideoPlayerController.networkUrl( Uri.parse('https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4'), ) ..initialize().then((_) { // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed. setState(() {}); }); } @override Widget build(BuildContext context) { return MaterialApp( title: 'Video Demo', home: Scaffold( body: Center( child: _controller.value.isInitialized ? AspectRatio( aspectRatio: _controller.value.aspectRatio, child: VideoPlayer(_controller), ) : Container(), ), floatingActionButton: FloatingActionButton( onPressed: () { setState(() { _controller.value.isPlaying ? _controller.pause() : _controller.play(); }); }, child: Icon(_controller.value.isPlaying ? Icons.pause : Icons.play_arrow), ), ), ); } @override void dispose() { _controller.dispose(); super.dispose(); } } ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/flutter/packages/blob/main/packages/google_fonts/example/linux/CMakeLists.txt Removes and re-copies the Flutter assets directory to ensure it's up-to-date during installation. ```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) ``` -------------------------------- ### Test Executable Configuration Source: https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector_windows/windows/CMakeLists.txt Sets up the test executable, including fetching Google Test, linking libraries, and discovering tests. ```cmake if (${include_${PROJECT_NAME}_tests}) set(TEST_RUNNER "${PROJECT_NAME}_test") enable_testing() # TODO(stuartmorgan): Consider using a single shared, pre-checked-in googletest # instance rather than downloading for each plugin. This approach makes sense # for a template, but not for a monorepo with many plugins. include(FetchContent) FetchContent_Declare( googletest URL https://github.com/google/googletest/archive/v1.15.2.zip ) # Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Disable install commands for gtest so it doesn't end up in the bundle. set(INSTALL_GTEST OFF CACHE BOOL "Disable installation of googletest" FORCE) FetchContent_MakeAvailable(googletest) # The plugin's C API is not very useful for unit testing, so build the sources # directly into the test binary rather than using the DLL. add_executable(${TEST_RUNNER} test/file_selector_plugin_test.cpp test/test_main.cpp test/test_file_dialog_controller.cpp test/test_file_dialog_controller.h test/test_utils.cpp test/test_utils.h ${PLUGIN_SOURCES} ) apply_standard_settings(${TEST_RUNNER}) target_include_directories(${TEST_RUNNER} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(${TEST_RUNNER} PRIVATE flutter_wrapper_plugin) target_link_libraries(${TEST_RUNNER} PRIVATE gtest gmock) # Override apply_standard_settings for exceptions due to # https://developercommunity.visualstudio.com/t/stdany-doesnt-link-when-exceptions-are-disabled/376072 target_compile_definitions(${TEST_RUNNER} PRIVATE "_HAS_EXCEPTIONS=1") # flutter_wrapper_plugin has link dependencies on the Flutter DLL. add_custom_command(TARGET ${TEST_RUNNER} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${FLUTTER_LIBRARY}" $ ) include(GoogleTest) gtest_discover_tests(${TEST_RUNNER}) endif() ``` -------------------------------- ### Build Android Debug APK Source: https://github.com/flutter/packages/blob/main/packages/interactive_media_ads/CONTRIBUTING.md Run this command in the `example/` directory to build a debug APK for Android. This is a prerequisite for updating SDK wrappers. ```bash flutter build apk --debug ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector/example/windows/CMakeLists.txt Installs any bundled libraries associated with plugins. This ensures that plugin dependencies are available at runtime. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install ICU Data File Source: https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector/example/windows/CMakeLists.txt Installs the ICU data file, which is necessary for internationalization and localization. This component is marked as 'Runtime'. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Get Local Package Tool Source: https://github.com/flutter/packages/blob/main/script/tool/README.md Use this command to get the local package for the tool when developing within the flutter/packages repository. ```sh dart pub get -C "/path/to/flutter/packages/"script/tool ``` -------------------------------- ### Initialize Repository Tooling Source: https://github.com/flutter/packages/blob/main/AGENTS.md Sets the REPO_ROOT environment variable to the current directory and fetches dependencies for the repository's tooling scripts. ```bash # Define an environment variable for the repository root. export REPO_ROOT=$(pwd) # Verify that the environment variable is working correctly. echo "Repository root directory: $REPO_ROOT" dart pub get -C $REPO_ROOT/script/tool ``` -------------------------------- ### Open Android Project in Android Studio Source: https://github.com/flutter/packages/blob/main/packages/interactive_media_ads/CONTRIBUTING.md Open the `example/android/` directory in Android Studio to update native code after modifying pigeon files. ```bash example/android/ ``` -------------------------------- ### Instantiate and Read XFile Source: https://github.com/flutter/packages/blob/main/packages/cross_file/README.md Instantiate an XFile using a file path and read its content. This example demonstrates accessing file metadata like path, name, and MIME type, and reading the file as a string. ```dart final file = XFile('assets/hello.txt'); print('File information:'); print('- Path: ${file.path}'); print('- Name: ${file.name}'); print('- MIME type: ${file.mimeType}'); final String fileContent = await file.readAsString(); print('Content of the file: $fileContent'); ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/flutter/packages/blob/main/packages/url_launcher/url_launcher/example/linux/CMakeLists.txt Initializes a CMake project, sets the binary name, and configures build policies. Ensure CMAKE_BUILD_TYPE is set for Flutter build modes. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Configure build options. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### Get Price of One-Time Purchase (Before Migration) Source: https://github.com/flutter/packages/blob/main/packages/in_app_purchase/in_app_purchase_android/migration_guide.md This snippet shows how to get the price of a one-time purchase using the old SkuDetailsWrapper before migration. ```dart SkuDetailsWrapper sku; if (sku.type == SkuType.inapp) { String price = sku.price; } ``` -------------------------------- ### Configure url_launcher_windows Plugin Tests Source: https://github.com/flutter/packages/blob/main/packages/url_launcher/url_launcher_windows/windows/CMakeLists.txt Sets up the test runner executable for the url_launcher_windows plugin, fetching Google Test, linking necessary libraries, and discovering tests. ```cmake if (${include_${PROJECT_NAME}_tests}) set(TEST_RUNNER "${PROJECT_NAME}_test") enable_testing() # TODO(stuartmorgan): Consider using a single shared, pre-checked-in googletest # instance rather than downloading for each plugin. This approach makes sense # for a template, but not for a monorepo with many plugins. include(FetchContent) FetchContent_Declare( googletest URL https://github.com/google/googletest/archive/v1.15.2.zip ) # Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Disable install commands for gtest so it doesn't end up in the bundle. set(INSTALL_GTEST OFF CACHE BOOL "Disable installation of googletest" FORCE) FetchContent_MakeAvailable(googletest) # The plugin's C API is not very useful for unit testing, so build the sources # directly into the test binary rather than using the DLL. add_executable(${TEST_RUNNER} test/url_launcher_windows_test.cpp ${PLUGIN_SOURCES} ) apply_standard_settings(${TEST_RUNNER}) target_include_directories(${TEST_RUNNER} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(${TEST_RUNNER} PRIVATE flutter_wrapper_plugin shlwapi.lib) target_link_libraries(${TEST_RUNNER} PRIVATE gtest_main gmock) # flutter_wrapper_plugin has link dependencies on the Flutter DLL. add_custom_command(TARGET ${TEST_RUNNER} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${FLUTTER_LIBRARY}" $ ) include(GoogleTest) gtest_discover_tests(${TEST_RUNNER}) endif() ``` -------------------------------- ### Run the Sample App Source: https://github.com/flutter/packages/blob/main/packages/pointer_interceptor/pointer_interceptor_web/example/README.md Use this command to run the sample application on Chrome. Be cautious when modifying code in lib/main.dart as it may affect integration tests. ```bash flutter run -d chrome ``` -------------------------------- ### Configure Include Directories and Libraries Source: https://github.com/flutter/packages/blob/main/packages/pigeon/platform_tests/test_plugin/linux/CMakeLists.txt Sets interface include directories for the plugin and links necessary libraries like 'flutter' and 'PkgConfig::GTK'. Add plugin-specific dependencies here. ```cmake target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter) target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK) ```