### Define Installation Directories Source: https://github.com/5alafawyyy/flutter_svga/blob/master/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") ``` -------------------------------- ### Install Application Executable Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Installs the application executable to the root of the installation prefix. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Library Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Installs the main Flutter library file to the library directory within the bundle. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Dependencies via Flutter Pub Get Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md After adding flutter_svga to pubspec.yaml, execute this command in your terminal to fetch the package. ```sh flutter pub get ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Installs all bundled libraries provided by plugins to the library 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) ``` -------------------------------- ### API Usage Compatibility Example Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md Demonstrates the similar controller patterns and loading mechanisms between svgaplayer_flutter and flutter_svga for migration. ```dart // Both packages use similar controller patterns SVGAAnimationController controller = SVGAAnimationController(vsync: this); // Loading remains the same final videoItem = await SVGAParser.shared.decodeFromAssets("assets/animation.svga"); controller.videoItem = videoItem; controller.repeat(); ``` -------------------------------- ### Install flutter_svga Package Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md Add the flutter_svga package to your pubspec.yaml file and run 'flutter pub get' to install dependencies. ```yaml dependencies: flutter_svga: ^0.0.13 ``` -------------------------------- ### Install Native Assets Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Installs native assets provided by build.dart from all packages to the library directory within the bundle. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Flutter SVGA Package API Usage Example Source: https://context7.com/5alafawyyy/flutter_svga/llms.txt Demonstrates basic usage of the flutter_svga package, including controller instantiation, parsing SVGA files from assets, and controlling playback. The API is designed to be similar to the previous svgaplayer_flutter package. ```dart // Before // import 'package:svgaplayer_flutter/svgaplayer_flutter.dart'; // After import 'package:flutter_svga/flutter_svga.dart'; // API is identical — no other changes required: final controller = SVGAAnimationController(vsync: this); final videoItem = await SVGAParser.shared.decodeFromAssets('assets/animation.svga'); controller.videoItem = videoItem; controller.repeat(); // Bonus: automatic caching, audio, and all-platform support at no extra cost ``` -------------------------------- ### Install ICU Data File Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Installs the ICU data file to the data directory within the bundle. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Clean Build Bundle Directory on Install Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Removes the build bundle directory before installation to ensure a clean state. ```cmake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Set Installation Prefix for Bundle Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Configures the installation prefix to a 'bundle' directory within the build directory for relocatable bundles. ```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() ``` -------------------------------- ### Controlled SVGA Player with AnimationController Source: https://context7.com/5alafawyyy/flutter_svga/llms.txt This example demonstrates how to use SVGAAnimationController to load and control an SVGA animation. It includes playback buttons and a slider for scrubbing through frames. Ensure 'assets/animation.svga' exists in your project's assets folder. ```dart import 'package:flutter/material.dart'; import 'package:flutter_svga/flutter_svga.dart'; class ControlledPlayerScreen extends StatefulWidget { const ControlledPlayerScreen({super.key}); @override State createState() => _ControlledPlayerScreenState(); } class _ControlledPlayerScreenState extends State with SingleTickerProviderStateMixin { late final SVGAAnimationController _controller; bool _isLoading = true; @override void initState() { super.initState(); _controller = SVGAAnimationController(vsync: this); _loadAnimation(); } Future _loadAnimation() async { final videoItem = await SVGAParser.shared.decodeFromAssets('assets/animation.svga'); if (!mounted) { videoItem.dispose(); return; } setState(() { _controller.videoItem = videoItem; // sets duration automatically _controller.repeat(); // loop forever _isLoading = false; }); } @override void dispose() { _controller.dispose(); // also disposes the videoItem and audio layers super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Controlled SVGA')), body: Column( children: [ if (_isLoading) const LinearProgressIndicator(), Expanded( child: SVGAImage( _controller, fit: BoxFit.contain, clearsAfterStop: false, allowDrawingOverflow: false, filterQuality: FilterQuality.high, preferredSize: const Size(300, 300), ), ), // Playback control buttons Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ ElevatedButton( onPressed: () => _controller.forward(from: 0), // play once child: const Text('Play Once'), ), ElevatedButton( onPressed: _controller.repeat, // loop child: const Text('Loop'), ), ElevatedButton( onPressed: () => _controller.stop(), // pause child: const Text('Stop'), ), ElevatedButton( onPressed: () { _controller.value = 0; // seek to first frame }, child: const Text('Reset'), ), ], ), // Scrub to a specific frame AnimatedBuilder( animation: _controller, builder: (_, __) => Slider( min: 0, max: _controller.frames.toDouble(), value: _controller.currentFrame.toDouble(), label: 'Frame ${_controller.currentFrame}', onChanged: (v) { _controller.stop(); _controller.value = v / _controller.frames; }, ), ), ], ), ); } } ``` -------------------------------- ### Install AOT Library Conditionally Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the library directory, but only for non-Debug build types. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Get SVGA Cache Statistics Source: https://github.com/5alafawyyy/flutter_svga/blob/master/CACHE.md Retrieves statistics about the current cache, including its size, file count, and enabled status. ```dart final stats = await SVGACache.shared.getStats(); print('Cache size: ${stats['size']}'); print('File count: ${stats['fileCount']}'); print('Enabled: ${stats['enabled']}'); ``` -------------------------------- ### Clear SVGA Cache in Debug Builds Source: https://github.com/5alafawyyy/flutter_svga/blob/master/CACHE.md In debug builds, clear the SVGA cache when the application starts. Ensure `WidgetsFlutterBinding.ensureInitialized()` is called before this. ```dart void main() { WidgetsFlutterBinding.ensureInitialized(); if (kDebugMode) { SVGACache.shared.clear(); // Clear during development } runApp(MyApp()); } ``` -------------------------------- ### Configure Cache Settings at App Startup Source: https://github.com/5alafawyyy/flutter_svga/blob/master/CACHE.md Set cache size and age limits during application startup to ensure optimal performance from the beginning. ```dart void main() { // Configure cache before first use SVGACache.shared.setMaxCacheSize(200 * 1024 * 1024); // 200MB SVGACache.shared.setMaxAge(const Duration(days: 14)); // 2 weeks runApp(MyApp()); } ``` -------------------------------- ### Configure Cross-Building with Sysroot Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Sets up the sysroot and find root path for cross-building based on the Flutter target platform. ```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() ``` -------------------------------- ### Add Dependency Libraries and Include Directories Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/windows/runner/CMakeLists.txt Links necessary libraries (flutter, flutter_wrapper_app, dwmapi.lib) and adds the source directory to include paths. Add any application-specific dependencies here. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) ``` ```cmake target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") ``` ```cmake target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Clone the Repository Source: https://github.com/5alafawyyy/flutter_svga/blob/master/CONTRIBUTING.md Clone your forked repository to your local machine to begin making changes. ```sh git clone https://github.com/5alafawyyy/flutter_svga.git cd flutter_svga ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/windows/runner/CMakeLists.txt Applies a standard set of build settings to the executable target. This can be customized for applications requiring different build configurations. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Set Runtime Search Path for Libraries Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Configures the runtime search path for libraries, loading them from the 'lib/' directory relative to the binary. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Registering Assets in pubspec.yaml Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md Ensure your SVGA files are correctly placed in the 'assets/' directory and registered in your 'pubspec.yaml' file to avoid black screen issues. ```yaml flutter: assets: - assets/sample.svga ``` -------------------------------- ### Find and check GTK, GLIB, and GIO modules Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/flutter/CMakeLists.txt Uses PkgConfig to find and check for the required GTK, GLIB, and GIO system libraries. These are essential for the Flutter Linux embedder. ```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) ``` -------------------------------- ### Find and Check PkgConfig Modules Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Finds and checks for the PkgConfig modules, specifically requiring 'gtk+-3.0'. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Include Generated Plugin Build Rules Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Includes the CMake file that manages the build rules for generated plugins. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Configure SVGA Cache Settings Source: https://github.com/5alafawyyy/flutter_svga/blob/master/CACHE.md Customize cache behavior by enabling/disabling caching, setting the maximum cache size, and defining the maximum age for cached files. ```dart import 'package:flutter_svga/flutter_svga.dart'; void configureSVGACache() { // Enable/disable caching (default: true) SVGACache.shared.setEnabled(true); // Set maximum cache size (default: 100MB) SVGACache.shared.setMaxCacheSize(50 * 1024 * 1024); // 50MB // Set maximum age for cached files (default: 7 days) SVGACache.shared.setMaxAge(const Duration(days: 3)); // 3 days } ``` -------------------------------- ### Enable Modern CMake Behaviors Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Explicitly opts into modern CMake behaviors to avoid warnings with recent CMake versions. ```cmake cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Clean and Copy Assets Directory Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Removes the existing assets directory and copies the new assets from the build directory to the data directory within the bundle. ```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) ``` -------------------------------- ### Basic Usage: Play SVGA from Assets Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md Use SVGAEasyPlayer to easily play an SVGA animation directly from your project's assets folder. Specify the assetsName and desired BoxFit. ```dart import 'package:flutter/material.dart'; import 'package:flutter_svga/flutter_svga.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: Text("Flutter SVGA Example")), body: Center( child: SVGAEasyPlayer( assetsName: "assets/sample_with_audio.svga", fit: BoxFit.contain, ), ), ), ); } } ``` -------------------------------- ### Custom command to assemble Flutter library and headers Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/flutter/CMakeLists.txt A custom build command that invokes the Flutter tool backend script to generate the Flutter library and its associated header files. It uses a phony target to ensure execution on every build. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Manage Persistent Disk Cache with SVGACache Source: https://context7.com/5alafawyyy/flutter_svga/llms.txt Configure and manage the persistent disk cache for SVGA animations. The cache automatically evicts expired entries and enforces a maximum size. All cache-related errors fail silently. Configure cache settings once at app startup. ```dart import 'package:flutter/foundation.dart'; import 'package:flutter_svga/flutter_svga.dart'; void main() { // Configure cache once at app startup (before first decode call) SVGACache.shared.setEnabled(true); SVGACache.shared.setMaxCacheSize(100 * 1024 * 1024); // 100 MB SVGACache.shared.setMaxAge(const Duration(days: 7)); if (kDebugMode) { // Clear stale cache during development SVGACache.shared.clear(); } runApp(const MyApp()); } ``` ```dart // Inspect cache health Future printCacheStats() async { final stats = await SVGACache.shared.getStats(); // stats keys: enabled, size (bytes), maxSize (bytes), fileCount, maxAge (days) debugPrint('Cache: ${stats['fileCount']} files, '${(stats['size'] as int) ~/ 1024} KB / '${(stats['maxSize'] as int) ~/ (1024 * 1024)} MB, enabled=${stats['enabled']}'); } ``` ```dart // Remove one entry (e.g., after the server updates an animation) Future invalidateAnimation(String url) async { await SVGACache.shared.remove(url); } ``` ```dart // Measure cache speedup Future benchmarkCache(SVGAAnimationController controller) async { const url = 'https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/EmptyState.svga'; final sw = Stopwatch()..start(); await SVGAParser.shared.decodeFromURL(url); // cold load (downloads + caches) debugPrint('Cold load: ${sw.elapsedMilliseconds} ms'); sw.reset(); await SVGAParser.shared.decodeFromURL(url); // warm load (reads from disk) debugPrint('Warm load: ${sw.elapsedMilliseconds} ms'); // dramatically faster } ``` -------------------------------- ### Compare Network Animation Load Times Source: https://github.com/5alafawyyy/flutter_svga/blob/master/CACHE.md Load an animation twice to compare the first load time with the cached load time, verifying cache effectiveness. ```dart // Load an animation twice and compare timing final stopwatch = Stopwatch()..start(); await SVGAParser.shared.decodeFromURL('https://example.com/animation.svga'); print('First load: ${stopwatch.elapsedMilliseconds}ms'); stopwatch.reset(); await SVGAParser.shared.decodeFromURL('https://example.com/animation.svga'); print('Cached load: ${stopwatch.elapsedMilliseconds}ms'); // Should be much faster ``` -------------------------------- ### CMakeLists.txt Configuration for Linux Runner Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/runner/CMakeLists.txt This snippet defines the core build configuration for the Linux runner application. It sets the minimum CMake version, project name, and adds executable targets with source files. It also applies standard build settings, defines application ID, and links essential libraries like flutter and GTK. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) # Define the application target. To change its name, change BINARY_NAME in the # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer # work. # # Any new source files that you add to the application should be added here. add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) # Add preprocessor definitions for the application ID. add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") # Add dependency libraries. Add any application-specific dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Basic Usage: Play SVGA from Network URL Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md Load and play an SVGA animation from a remote URL using SVGAEasyPlayer by providing the resUrl and BoxFit. ```dart SVGAEasyPlayer( resUrl: "https://example.com/sample.svga", fit: BoxFit.cover, ); ``` -------------------------------- ### Add Runner Subdirectory Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Includes the 'runner' subdirectory for application-specific build configurations. ```cmake add_subdirectory("runner") ``` -------------------------------- ### Define list_prepend function for CMake < 3.10 Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/flutter/CMakeLists.txt This function prepends a prefix to each element in a list. It's a workaround for older CMake versions that lack the list(TRANSFORM ... PREPEND ...) command. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Rebuilding Widget After Loading SVGA Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md If an animation freezes or doesn't play, use `setState` after loading the SVGA to ensure the widget rebuilds with the new video item. ```dart setState(() { _controller.videoItem = video; }); ``` -------------------------------- ### SVGAImage Source: https://context7.com/5alafawyyy/flutter_svga/llms.txt A StatefulWidget that renders SVGA animations using a CustomPaint. It provides options for controlling how the animation fits its container, image quality, and clipping. ```APIDOC ## SVGAImage — Low-level render widget `SVGAImage` is a `StatefulWidget` wrapping a `CustomPaint` powered by `_SVGAPainter`. It repaints automatically as the controller animates. Use it when you need fine-grained rendering options: `fit` controls how the viewbox maps to the widget size; `filterQuality` controls bitmap interpolation; `allowDrawingOverflow` clips to canvas bounds; `preferredSize` constrains the canvas. ### Properties - **controller** (SVGAAnimationController): The controller managing the animation. - **fit** (BoxFit): How the animation should be inscribed into the widget's bounds. - **filterQuality** (FilterQuality): The quality of bitmap interpolation. - **allowDrawingOverflow** (bool): Whether to clip drawing to the canvas bounds. - **clearsAfterStop** (bool): Whether to clear the canvas when the animation stops. - **preferredSize** (Size): An explicit hint for the canvas size. ### Example Usage ```dart import 'package:flutter/material.dart'; import 'package:flutter_svga/flutter_svga.dart'; // Inside a build method — controller already has a videoItem assigned: Widget buildSVGAWidget(SVGAAnimationController controller) { return SVGAImage( controller, fit: BoxFit.cover, // fill the widget area filterQuality: FilterQuality.medium, // balance quality vs speed allowDrawingOverflow: false, // clip to canvas bounds (saves memory) clearsAfterStop: true, // clear canvas when animation finishes preferredSize: const Size(480, 480), // explicit canvas size hint ); } ``` ``` -------------------------------- ### Define Executable Target Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/windows/runner/CMakeLists.txt Defines the main executable target for the Windows application. Ensure BINARY_NAME is consistent with the top-level CMakeLists.txt for `flutter run` compatibility. Add any new source files here. ```cmake add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) ``` -------------------------------- ### Set Minimum CMake Version and Project Name Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Specifies the minimum required CMake version and defines the project name and languages. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) ``` -------------------------------- ### Set Runtime Output Directory for Executable Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Configures the runtime output directory for the application's executable to a specific subdirectory to prevent accidental execution of unbundled copies. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run") ``` -------------------------------- ### Advanced Usage: Control Animation Playback Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md Utilize SVGAAnimationController for fine-grained control over SVGA animations. Initialize the controller, decode the animation, assign it to the controller, and then use SVGAImage to display it. Remember to dispose of the controller when done. ```dart class MySVGAWidget extends StatefulWidget { @override _MySVGAWidgetState createState() => _MySVGAWidgetState(); } class _MySVGAWidgetState extends State with SingleTickerProviderStateMixin { late SVGAAnimationController _controller; @override void initState() { super.initState(); _controller = SVGAAnimationController(vsync: this); SVGAParser.shared.decodeFromAssets("assets/sample.svga").then((video) { _controller.videoItem = video; _controller.repeat(); }); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return SVGAImage(_controller); } } ``` -------------------------------- ### Monitor Cache Growth Over Time Source: https://github.com/5alafawyyy/flutter_svga/blob/master/CACHE.md Periodically check and log cache statistics to monitor its growth and manage storage effectively. ```dart // Periodically check cache statistics Timer.periodic(Duration(minutes: 5), (timer) async { final stats = await SVGACache.shared.getStats(); print('Cache: ${stats['fileCount']} files, ${stats['size'] ~/ 1024}KB'); }); ``` -------------------------------- ### Define Executable and Application ID Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Sets the name of the application's executable and its unique GTK application identifier. ```cmake set(BINARY_NAME "example") set(APPLICATION_ID "com.example.example") ``` -------------------------------- ### Add Flutter Version Preprocessor Definitions Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/windows/runner/CMakeLists.txt Adds preprocessor definitions for Flutter version components, allowing the application to access version information at compile time. ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") ``` -------------------------------- ### Migrate from svgaplayer_flutter to flutter_svga Source: https://context7.com/5alafawyyy/flutter_svga/llms.txt Update your project dependencies and imports to migrate from the svgaplayer_flutter package to flutter_svga. The API for controller and parser remains largely identical, with added benefits like automatic caching and audio support. ```yaml # pubspec.yaml — before dependencies: svgaplayer_flutter: ^2.2.0 # pubspec.yaml — after dependencies: flutter_svga: ^0.0.13 ``` -------------------------------- ### Check if Caching is Enabled and View Stats Source: https://github.com/5alafawyyy/flutter_svga/blob/master/CACHE.md Troubleshoot cache issues by verifying if caching is enabled and inspecting the current cache statistics. ```dart // Check if caching is enabled print('Cache enabled: ${SVGACache.shared.isEnabled}'); // Check cache statistics final stats = await SVGACache.shared.getStats(); print('Cache stats: $stats'); ``` -------------------------------- ### Include Flutter Managed Directory Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Adds the Flutter managed directory as a subdirectory for build rules. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Defines a function to apply common compilation features and options to targets, including C++14 standard, Wall/Werror, optimization levels, and NDEBUG definition. ```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() ``` -------------------------------- ### Update Dependencies for Migration Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md When migrating from svgaplayer_flutter, update your pubspec.yaml to include flutter_svga and remove the old package. ```yaml dependencies: # svgaplayer_flutter: ^2.2.0 # Remove old package flutter_svga: ^0.0.13 # Add new package ``` -------------------------------- ### Decode SVGA Animation from URL with Cache Source: https://github.com/5alafawyyy/flutter_svga/blob/master/CACHE.md This automatically uses the cache if available, otherwise it downloads the animation. No code changes are needed for existing usage. ```dart final animation = await SVGAParser.shared.decodeFromURL( 'https://example.com/animation.svga' ); ``` -------------------------------- ### Decode SVGA Animation from Assets with Cache Source: https://github.com/5alafawyyy/flutter_svga/blob/master/CACHE.md Assets are also cached for faster subsequent loads, improving performance on repeated app launches. ```dart final assetAnimation = await SVGAParser.shared.decodeFromAssets( 'assets/my_animation.svga' ); ``` -------------------------------- ### SVGAParser Source: https://context7.com/5alafawyyy/flutter_svga/llms.txt Handles decoding of SVGA animations from various sources. It supports decoding from URLs, assets, and raw bytes, with transparent caching for network and asset sources. ```APIDOC ## SVGAParser — Decode SVGA from any source `SVGAParser` is a stateless singleton (`SVGAParser.shared`) that handles all decoding. It decompresses the zlib-encoded protobuf payload, processes shape items, and decodes embedded bitmap images concurrently. After decoding, it calls `releaseMemory()` on the `MovieEntity` to free protobuf internal structures. Caching is applied transparently for both `decodeFromURL` and `decodeFromAssets`. ### Methods - **decodeFromURL(String url)**: Decodes SVGA from a remote URL. Caches results. - **decodeFromAssets(String assetPath)**: Decodes SVGA from bundled assets. Caches results. - **decodeFromBuffer(Uint8List bytes)**: Decodes SVGA from raw bytes. No caching. ### Example Usage ```dart import 'dart:typed_data'; import 'package:flutter_svga/flutter_svga.dart'; // Decode from a remote URL Future loadFromNetwork(SVGAAnimationController controller) async { try { final videoItem = await SVGAParser.shared.decodeFromURL( 'https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/Rocket.svga', ); controller.videoItem = videoItem; controller.repeat(); } catch (e) { debugPrint('Network load failed: $e'); } } // Decode from a bundled asset Future loadFromAssets(SVGAAnimationController controller) async { final videoItem = await SVGAParser.shared.decodeFromAssets('assets/animation.svga'); controller.videoItem = videoItem; controller.forward(); // play once } // Decode from raw bytes Future loadFromBytes(SVGAAnimationController controller, Uint8List bytes) async { final videoItem = await SVGAParser.shared.decodeFromBuffer(bytes); controller.videoItem = videoItem; controller.repeat(); } // Determine source type at runtime and dispatch Future loadVideoItem(String source) { if (source.startsWith(RegExp(r'https?://'))) { return SVGAParser.shared.decodeFromURL(source); } return SVGAParser.shared.decodeFromAssets(source); } ``` ``` -------------------------------- ### Use SVGAEasyPlayer for Local Assets and Network URLs Source: https://context7.com/5alafawyyy/flutter_svga/llms.txt The SVGAEasyPlayer widget simplifies displaying SVGA animations. Provide either 'assetsName' for local files or 'resUrl' for network URLs. It automatically handles decoding and looping. ```dart import 'package:flutter/material.dart'; import 'package:flutter_svga/flutter_svga.dart'; class SimplePlayerScreen extends StatelessWidget { const SimplePlayerScreen({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('SVGA Easy Player')), body: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ // From local asset (loops automatically) const SVGAEasyPlayer( assetsName: 'assets/animation.svga', fit: BoxFit.contain, ), const SizedBox(height: 24), // From network URL (loops automatically) SVGAEasyPlayer( resUrl: 'https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/rose.svga', fit: BoxFit.cover, ), ], ), ); } } ``` -------------------------------- ### Render SVGA Animations with SVGAImage Widget Source: https://context7.com/5alafawyyy/flutter_svga/llms.txt SVGAImage is a StatefulWidget that wraps CustomPaint for rendering SVGA animations. It allows fine-grained control over rendering options like fit, filter quality, and clipping. ```dart import 'package:flutter/material.dart'; import 'package:flutter_svga/flutter_svga.dart'; // Inside a build method — controller already has a videoItem assigned: Widget buildSVGAWidget(SVGAAnimationController controller) { return SVGAImage( controller, fit: BoxFit.cover, // fill the widget area filterQuality: FilterQuality.medium, // balance quality vs speed allowDrawingOverflow: false, // clip to canvas bounds (saves memory) clearsAfterStop: true, // clear canvas when animation finishes preferredSize: const Size(480, 480), // explicit canvas size hint ); } ``` -------------------------------- ### Add Flutter Tool Build Dependency Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/windows/runner/CMakeLists.txt Ensures that the Flutter tool's assembly process is completed before the application target is built. This is a required step for Flutter projects. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Update Imports for Migration Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md Adjust your Dart imports to use the new flutter_svga package instead of svgaplayer_flutter. ```dart // Old // import 'package:svgaplayer_flutter/svgaplayer_flutter.dart'; // New import 'package:flutter_svga/flutter_svga.dart'; ``` -------------------------------- ### Define Flutter library interface target Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/flutter/CMakeLists.txt Creates an INTERFACE library target for Flutter, specifying include directories and linking against system libraries and the Flutter engine library. ```cmake add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Configure Audio Volume and Mute for SVGA Animations Source: https://context7.com/5alafawyyy/flutter_svga/llms.txt Control the audio playback volume and mute state of SVGA animations. Setting muted to true silences playback without altering the stored volume, allowing it to be restored later. Setting volume to 0.0 provides a complete silence. ```dart import 'package:flutter_svga/flutter_svga.dart'; void configureAudio(SVGAAnimationController controller) { // Set volume to 60% controller.volume = 0.6; // Mute (preserves volume setting internally) controller.muted = true; // Unmute — restores to 0.6 controller.muted = false; // Silence completely (does not preserve via mute) controller.volume = 0.0; } ``` -------------------------------- ### SVGADynamicEntity Source: https://context7.com/5alafawyyy/flutter_svga/llms.txt Allows runtime customization of individual SVGA sprite layers. You can replace images, overlay text, perform custom drawing, or hide layers. ```APIDOC ## SVGADynamicEntity — Runtime layer customization `SVGADynamicEntity` (accessed via `videoItem.dynamicItem`) lets you override individual SVGA sprite layers at runtime before or during playback. The layer key strings correspond to image/sprite identifiers embedded in the SVGA file. Supported operations: replace with a `ui.Image`, replace with a remote image URL, overlay text via `TextPainter`, custom `Canvas` drawing per frame, and hidden-layer toggling. ### Methods - **setImageWithUrl(String url, String key)**: Replaces a layer's image with one from a URL. - **setText(TextPainter painter, String key)**: Overlays styled text on a layer. - **setDynamicDrawer(Function(Canvas canvas, int frameIndex) drawer, String key)**: Provides a custom drawing function for a layer per frame. - **setHidden(bool hidden, String key)**: Toggles the visibility of a layer. - **reset()**: Resets all dynamic overrides for the video item. ### Example Usage ```dart import 'package:flutter/material.dart'; import 'package:flutter_svga/flutter_svga.dart'; Future applyDynamicElements(MovieEntity videoItem) async { final dynamic = videoItem.dynamicItem; // 1. Overlay styled text on the "banner" layer dynamic.setText( TextPainter( text: const TextSpan( text: 'Hello, World!', style: TextStyle( fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold, ), ), textDirection: TextDirection.ltr, ), 'banner', // SVGA layer key ); // 2. Replace the avatar image layer with a remote image await dynamic.setImageWithUrl( 'https://example.com/user_avatar.png', '99', // SVGA layer key ); // 3. Custom per-frame drawing on the "canvas_layer" layer dynamic.setDynamicDrawer((Canvas canvas, int frameIndex) { final paint = Paint() ..color = Colors.red.withValues(alpha: 0.5) ..style = PaintingStyle.fill; canvas.drawCircle(Offset(44, 44), 44.0 * (frameIndex % 10) / 10.0, paint); }, 'canvas_layer'); // 4. Hide a specific layer entirely dynamic.setHidden(true, 'watermark_layer'); // 5. Reset all dynamic overrides dynamic.reset(); } ``` ``` -------------------------------- ### Decode SVGA from URL, Assets, or Bytes with SVGAParser Source: https://context7.com/5alafawyyy/flutter_svga/llms.txt Use SVGAParser.shared to decode SVGA animations. It supports decoding from network URLs, local assets, and raw byte buffers. Caching is automatically handled for URL and asset decoding. ```dart import 'dart:typed_data'; import 'package:flutter_svga/flutter_svga.dart'; // 1. Decode from a remote URL (cache checked first) Future loadFromNetwork(SVGAAnimationController controller) async { try { final videoItem = await SVGAParser.shared.decodeFromURL( 'https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/Rocket.svga', ); controller.videoItem = videoItem; controller.repeat(); } catch (e) { debugPrint('Network load failed: $e'); } } // 2. Decode from a bundled asset (cache checked first) Future loadFromAssets(SVGAAnimationController controller) async { final videoItem = await SVGAParser.shared.decodeFromAssets('assets/animation.svga'); controller.videoItem = videoItem; controller.forward(); // play once } // 3. Decode from raw bytes (no caching — caller manages bytes) Future loadFromBytes(SVGAAnimationController controller, Uint8List bytes) async { final videoItem = await SVGAParser.shared.decodeFromBuffer(bytes); controller.videoItem = videoItem; controller.repeat(); } // 4. Determine source type at runtime and dispatch Future loadVideoItem(String source) { if (source.startsWith(RegExp(r'https?://'))) { return SVGAParser.shared.decodeFromURL(source); } return SVGAParser.shared.decodeFromAssets(source); } ``` -------------------------------- ### SVGA Playback Controls Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md Control the playback of SVGA animations using the provided controller methods. These include playing once, looping, stopping, and resetting to the first frame. ```dart controller.forward(); // Play once controller.repeat(); // Loop playback controller.stop(); // Stop animation controller.value = 0; // Reset to first frame ``` -------------------------------- ### Set Default Build Type Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/linux/CMakeLists.txt Sets the default build type to 'Debug' if not already defined, ensuring a consistent build configuration. ```cmake if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### Add flutter_svga to pubspec.yaml Source: https://context7.com/5alafawyyy/flutter_svga/llms.txt Declare the flutter_svga dependency and any bundled SVGA asset files in your pubspec.yaml file. ```yaml # pubspec.yaml dependencies: flutter_svga: ^0.0.13 flutter: assets: - assets/animation.svga - assets/audio_biling.svga ``` -------------------------------- ### SVGA Caching Configuration and Management Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md SVGA caching is automatic for performance optimization. You can optionally configure cache size and age, or manually clear the cache and retrieve statistics. ```dart // Caching works automatically - no code changes needed! final animation = await SVGAParser.shared.decodeFromURL( "https://example.com/animation.svga" ); // Optional: Configure cache settings SVGACache.shared.setMaxCacheSize(50 * 1024 * 1024); // 50MB SVGACache.shared.setMaxAge(const Duration(days: 3)); // 3 days // Optional: Manage cache await SVGACache.shared.clear(); // Clear all cache final stats = await SVGACache.shared.getStats(); // Get cache info ``` -------------------------------- ### SVGA Audio Volume Control Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md Manage the audio volume for SVGA animations. You can set a specific volume level, mute the audio, or unmute it while preserving the last volume setting. ```dart // Set volume (0.0 to 1.0) controller.volume = 0.5; // Mute audio (preserves volume setting) controller.muted = true; // Unmute audio controller.muted = false; ``` -------------------------------- ### Disable and Re-enable SVGA Caching Source: https://github.com/5alafawyyy/flutter_svga/blob/master/CACHE.md Temporarily disable SVGA caching for testing or troubleshooting, and then re-enable it when finished. This is useful for observing behavior without cached assets. ```dart SVGACache.shared.setEnabled(false); ``` ```dart SVGACache.shared.setEnabled(true); ``` -------------------------------- ### Customize SVGA Layers at Runtime with SVGADynamicEntity Source: https://context7.com/5alafawyyy/flutter_svga/llms.txt Use SVGADynamicEntity to modify individual SVGA sprite layers during playback. This includes overlaying text, replacing images, custom drawing, and hiding layers. ```dart import 'package:flutter/material.dart'; import 'package:flutter_svga/flutter_svga.dart'; Future applyDynamicElements(MovieEntity videoItem) async { final dynamic = videoItem.dynamicItem; // 1. Overlay styled text on the "banner" layer dynamic.setText( TextPainter( text: const TextSpan( text: 'Hello, World!', style: TextStyle( fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold, ), ), textDirection: TextDirection.ltr, ), 'banner', // SVGA layer key ); // 2. Replace the avatar image layer with a remote image await dynamic.setImageWithUrl( 'https://example.com/user_avatar.png', '99', // SVGA layer key ); // 3. Custom per-frame drawing on the "canvas_layer" layer dynamic.setDynamicDrawer((Canvas canvas, int frameIndex) { final paint = Paint() ..color = Colors.red.withValues(alpha: 0.5) ..style = PaintingStyle.fill; canvas.drawCircle(Offset(44, 44), 44.0 * (frameIndex % 10) / 10.0, paint); }, 'canvas_layer'); // 4. Hide a specific layer entirely dynamic.setHidden(true, 'watermark_layer'); // 5. Reset all dynamic overrides dynamic.reset(); } ``` -------------------------------- ### Replace Image Dynamically in SVGA Animation Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md Replace an existing image in an SVGA animation with a new image from a URL. The 'image_layer' identifier must be present in the SVGA asset. ```dart controller.videoItem!.dynamicItem.setImageWithUrl( "https://example.com/new_image.png", "image_layer", ); ``` -------------------------------- ### Clear Entire SVGA Cache Source: https://github.com/5alafawyyy/flutter_svga/blob/master/CACHE.md Clears all cached SVGA files from the storage. ```dart // Clear entire cache await SVGACache.shared.clear(); ``` -------------------------------- ### Add Dynamic Text to SVGA Animation Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md Use this to dynamically set text within an SVGA animation. Ensure the 'text_layer' identifier exists in your SVGA asset. ```dart controller.videoItem!.dynamicItem.setText( TextPainter( text: TextSpan( text: "Hello SVGA!", style: TextStyle(color: Colors.red, fontSize: 18), ), textDirection: TextDirection.ltr, ), "text_layer", ); ``` -------------------------------- ### Disable Conflicting Windows Macros Source: https://github.com/5alafawyyy/flutter_svga/blob/master/example/windows/runner/CMakeLists.txt Disables the NOMINMAX Windows macro to prevent collisions with C++ standard library functions. ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") ``` -------------------------------- ### Remove Specific Animation from Cache Source: https://github.com/5alafawyyy/flutter_svga/blob/master/CACHE.md Manually remove a specific animation from the cache using its URL as the key. ```dart // Remove specific animation from cache await SVGACache.shared.remove('https://example.com/animation.svga'); ``` -------------------------------- ### Hide Layer in SVGA Animation Source: https://github.com/5alafawyyy/flutter_svga/blob/master/README.md Dynamically hide a specific layer within an SVGA animation by its identifier. Set the hidden state to true to conceal the layer. ```dart controller.videoItem!.dynamicItem.setHidden(true, "layer_to_hide"); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.