### Import Main Example Source: https://github.com/xvrh/lottie-flutter/blob/master/README.template.md Import the main example file for Lottie animations. ```dart import 'example/lib/main.dart'; ``` -------------------------------- ### Import Custom Draw Example Source: https://github.com/xvrh/lottie-flutter/blob/master/README.template.md Import the example file for custom drawing of Lottie compositions on a Canvas. ```dart import 'example/lib/examples/custom_draw.dart#example'; ``` -------------------------------- ### Complete Configuration Example Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/configuration.md A comprehensive example demonstrating various configuration options for loading and displaying Lottie animations, including network settings, delegates, options, and callbacks. ```dart Lottie.network( 'https://example.com/animation.json', headers: {'Authorization': 'Bearer token'}, controller: _controller, frameRate: FrameRate(30), width: 200, height: 200, fit: BoxFit.contain, alignment: Alignment.center, delegates: LottieDelegates( text: (text) => 'Updated: $text', values: [ ValueDelegate.color(['Shape', 'Fill'], value: Colors.blue), ], ), options: LottieOptions( enableMergePaths: true, enableApplyingOpacityToLayers: false, ), filterQuality: FilterQuality.high, addRepaintBoundary: true, renderCache: RenderCache.drawingCommands, backgroundLoading: true, onLoaded: (composition) { print('Loaded: ${composition.duration}'); }, ) ``` -------------------------------- ### Import Dynamic Properties Example Source: https://github.com/xvrh/lottie-flutter/blob/master/README.template.md Import the example file demonstrating modification of animation properties at runtime. ```dart import 'example/lib/examples/simple_dynamic_properties.dart#example'; ``` -------------------------------- ### Import Animation Controller Example Source: https://github.com/xvrh/lottie-flutter/blob/master/README.template.md Import the example file for controlling Lottie animations with a custom AnimationController. ```dart import 'example/lib/examples/animation_controller.dart'; ``` -------------------------------- ### Import DotLottie Example Source: https://github.com/xvrh/lottie-flutter/blob/master/README.template.md Import the example file for selecting a .json file from a dotlottie (.lottie) archive using a custom decoder. ```dart import 'example/lib/examples/dotlottie.dart#example'; ``` -------------------------------- ### Import Custom Load Example Source: https://github.com/xvrh/lottie-flutter/blob/master/README.template.md Import the example file for custom loading of Lottie compositions from JSON. ```dart import 'example/lib/examples/custom_load.dart#example'; ``` -------------------------------- ### Import Telegram Stickers Example Source: https://github.com/xvrh/lottie-flutter/blob/master/README.template.md Import the example file for loading Telegram Stickers (.tgs) with a special decoder. ```dart import 'example/lib/examples/telegram_stickers.dart#example'; ``` -------------------------------- ### ValueDelegate KeyPath Example Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/value-delegate.md Demonstrates how to create a ValueDelegate for a specific property path and access its keyPath. ```dart final delegate = ValueDelegate.color(['Shape', 'Fill']); print(delegate.keyPath); // ['Shape', 'Fill'] ``` -------------------------------- ### Basic Asset Animation Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-widget.md Example of how to load and display a Lottie animation from local assets in a Flutter application. ```APIDOC ## Usage Example ### Basic asset animation with auto-play ```dart import 'package:flutter/material.dart'; import 'package:lottie/lottie.dart'; class SimpleAnimation extends StatelessWidget { @override Widget build(BuildContext context) { return Lottie.asset( 'assets/animation.json', width: 200, height: 200, fit: BoxFit.fill, ); } } ``` ``` -------------------------------- ### FrameRate Constructor Example Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/delegates-and-options.md Creates a FrameRate instance with a specific frames per second value. The value must be greater than 0. ```dart FrameRate(30) // 30 FPS ``` ```dart FrameRate(10) // 10 FPS ``` -------------------------------- ### Navigate Lottie Animation with Markers Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/README.md Explains how to navigate to specific points in a Lottie animation using markers. Retrieves a marker by its name and controls the animation playback to start from the marker's start time. ```dart final marker = composition.getMarker('intro'); if (marker != null) { controller.forward(from: marker.start); } ``` -------------------------------- ### Lottie Cache Management Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-providers.md Shows how to configure the Lottie cache size, clear the cache, and check the current number of cached items. Configure cache size before the app starts. ```dart import 'package:lottie/lottie.dart'; void main() { // Configure cache size before app starts Lottie.cache.maximumSize = 100; runApp(const MyApp()); } class CacheManagement extends StatelessWidget { @override Widget build(BuildContext context) { return Column( children: [ Lottie.asset('assets/animation1.json'), Lottie.asset('assets/animation2.json'), ElevatedButton( onPressed: () { // Clear cache when memory is tight Lottie.cache.clear(); }, child: const Text('Clear Cache'), ), Text('Cached: ${Lottie.cache.count} items'), ], ); } } ``` -------------------------------- ### Configure Lottie Animation with Delegates Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/START_HERE.md Modify animation properties like color at runtime using `LottieDelegates` and `ValueDelegate`. This example changes the color of a specific layer's fill. ```dart Lottie.asset( 'assets/animation.json', delegates: LottieDelegates( values: [ ValueDelegate.color(['Layer', 'Fill'], value: Colors.blue), ], ), ) ``` -------------------------------- ### Combine Multiple Delegates for Advanced Customization Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/delegates-and-options.md Combine text translation, text styling, color, opacity, and image delegates within `LottieDelegates` for complex animation modifications. This example demonstrates dynamic changes based on a state variable. ```dart class AdvancedAnimation extends StatefulWidget { @override State createState() => _AdvancedAnimationState(); } class _AdvancedAnimationState extends State { bool _showAlternative = false; @override Widget build(BuildContext context) { return Column( children: [ Lottie.asset( 'assets/complex.json', delegates: LottieDelegates( text: (text) => _showAlternative ? 'Alternative $text' : text, textStyle: (fontStyle) => TextStyle( fontFamily: 'OpenSans', fontWeight: FontWeight.w600, ), values: [ ValueDelegate.color( ['Background', 'Fill'], value: _showAlternative ? Colors.blue : Colors.red, ), ValueDelegate.opacity( ['Label'], callback: (frameInfo) => (_showAlternative ? 50 : 100) + ((frameInfo.overallProgress - 0.5).abs() * 50).toInt(), ), ], image: (composition, imageAsset) { if (imageAsset.id == 'logo' && _showAlternative) { return alternativeLogo; } return null; }, ), ), ElevatedButton( onPressed: () => setState(() => _showAlternative = !_showAlternative), child: const Text('Toggle'), ), ], ); } } ``` -------------------------------- ### Control Lottie Animation with Custom AnimationController Source: https://github.com/xvrh/lottie-flutter/blob/master/README.md Provide a custom AnimationController to gain full control over the animation playback. This allows for starting, stopping, playing forward/backward, and looping between specific points. Ensure to dispose of the controller when it's no longer needed. ```dart import 'package:flutter/material.dart'; import 'package:lottie/lottie.dart'; void main() => runApp(const MyApp()); class MyApp extends StatefulWidget { const MyApp({super.key}); @override State createState() => _MyAppState(); } class _MyAppState extends State with TickerProviderStateMixin { late final AnimationController _controller; @override void initState() { super.initState(); _controller = AnimationController(vsync: this); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: ListView( children: [ Lottie.asset( 'assets/LottieLogo1.json', controller: _controller, onLoaded: (composition) { // Configure the AnimationController with the duration of the // Lottie file and start the animation. _controller ..duration = composition.duration ..forward(); }, ), ], ), ), ); } } ``` -------------------------------- ### Access Composition Frame Information Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/composition.md Get details about the animation's frames, including start frame, end frame, total frames, and frame rate. These are represented as double values. ```dart final startFrame = composition.startFrame; final endFrame = composition.endFrame; final durationFrames = composition.durationFrames; final frameRate = composition.frameRate; ``` -------------------------------- ### Initialize LottieCache Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-providers.md Instantiate the LottieCache. The default maximum size is 1000 compositions. ```dart LottieCache() ``` -------------------------------- ### Network Animation with Controller Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-widget.md Demonstrates loading a Lottie animation from a network URL and controlling its playback using an AnimationController. ```APIDOC ### Network animation with custom controller ```dart class ControlledAnimation extends StatefulWidget { @override State createState() => _ControlledAnimationState(); } class _ControlledAnimationState extends State with TickerProviderStateMixin { late AnimationController _controller; @override void initState() { super.initState(); _controller = AnimationController(vsync: this); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Lottie.network( 'https://example.com/animation.json', controller: _controller, onLoaded: (composition) { _controller ..duration = composition.duration ..forward(); }, ); } } ``` ``` -------------------------------- ### Get Animation Duration Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/composition.md Access the total duration of the animation. This property returns a Duration object. ```dart print('Animation plays for ${composition.duration}'); ``` -------------------------------- ### AssetLottie Constructor and Load Method Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-providers.md Demonstrates how to instantiate and use the AssetLottie provider to load animations from the Flutter asset bundle. It includes details on constructor parameters and the load method for fetching the Lottie composition. ```APIDOC ## AssetLottie Loads Lottie animations from the Flutter asset bundle. ### Constructor ```dart AssetLottie( String assetName, { AssetBundle? bundle, String? package, LottieImageProviderFactory? imageProviderFactory, LottieDecoder? decoder, bool? backgroundLoading, } ) ``` | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | assetName | `String` | yes | — | Path to the JSON file in assets | | bundle | `AssetBundle?` | no | null | Custom asset bundle; defaults to `DefaultAssetBundle` | | package | `String?` | no | null | Package name for `packages/` prefix in path | | imageProviderFactory | `LottieImageProviderFactory?` | no | null | Factory for custom image providers | | decoder | `LottieDecoder?` | no | null | Custom decoder for special formats | | backgroundLoading | `bool?` | no | false | Parse JSON on background isolate | ### Properties | Property | Type | Description | |----------|------|-------------| | assetName | `String` | The asset path | | keyName | `String` (read-only) | Full key with package prefix if applicable | | bundle | `AssetBundle?` | The asset bundle | | package | `String?` | Package name | ### Methods #### load ```dart Future load({BuildContext? context}) ``` Loads the composition from assets, caching the result. **Example:** ```dart final provider = AssetLottie('assets/animation.json'); final composition = await provider.load(); ``` ``` -------------------------------- ### Load and Inspect Lottie Composition Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/composition.md Demonstrates loading a Lottie animation from assets using `LottieComposition.fromBytes` and accessing its properties like duration, frame rate, bounds, and image information. It also shows how to retrieve specific markers and log any warnings generated during parsing. ```dart import 'package:flutter/services.dart'; import 'package:lottie/lottie.dart'; void main() async { // Load from asset final bytes = (await rootBundle.load('assets/animation.json')).buffer.asUint8List(); final composition = await LottieComposition.fromBytes(bytes); // Access metadata print('Duration: ${composition.duration}'); print('Frame rate: ${composition.frameRate}'); print('Bounds: ${composition.bounds}'); print('Has images: ${composition.hasImages}'); // Get markers final startMarker = composition.getMarker('start'); if (startMarker != null) { print('Start marker at: ${startMarker.start}'); } // Check for warnings if (composition.warnings.isNotEmpty) { for (var warning in composition.warnings) { print('Warning: $warning'); } } } ``` -------------------------------- ### Get Precomposition Layers Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/composition.md Retrieves a list of layers for a given precomposition ID. Returns null if the precomposition is not found. ```dart List? getPrecomps(String? id) ``` ```dart final precompLayers = composition.getPrecomps('precomp_id'); ``` -------------------------------- ### Delegate Configuration: Values Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/configuration.md Configure delegates to modify animation properties at runtime. This example sets a specific color for a shape fill. ```dart List? values; ``` -------------------------------- ### Lottie.file Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-widget.md Creates a widget that loads a Lottie animation from a file system path. This method allows for customization of animation playback, loading, and rendering. ```APIDOC ## Lottie.file ### Description Creates a widget that loads a Lottie animation from a file system path. ### Method Signature ```dart static LottieBuilder file( Object file, { Animation? controller, FrameRate? frameRate, bool? animate, bool? repeat, bool? reverse, LottieDelegates? delegates, LottieOptions? options, LottieImageProviderFactory? imageProviderFactory, void Function(LottieComposition)? onLoaded, Key? key, LottieFrameBuilder? frameBuilder, ImageErrorWidgetBuilder? errorBuilder, double? width, double? height, BoxFit? fit, AlignmentGeometry? alignment, bool? addRepaintBoundary, FilterQuality? filterQuality, WarningCallback? onWarning, LottieDecoder? decoder, RenderCache? renderCache, bool? backgroundLoading, } ) ``` ### Parameters #### Path Parameters - **file** (Object) - Required - `File` object pointing to JSON animation file; not supported on web #### Optional Parameters - **controller** (Animation?) - Optional - Custom animation controller - **frameRate** (FrameRate?) - Optional - Frame rate override - **animate** (bool?) - Optional - Auto-play setting (default: true) - **repeat** (bool?) - Optional - Loop animation (default: true) - **reverse** (bool?) - Optional - Alternate direction on repeat (default: false) - **delegates** (LottieDelegates?) - Optional - Runtime property modification callbacks - **options** (LottieOptions?) - Optional - Feature flags - **imageProviderFactory** (LottieImageProviderFactory?) - Optional - Factory for custom image loading - **onLoaded** (void Function(LottieComposition)?) - Optional - Callback when composition finishes loading - **key** (Key?) - Optional - Widget key - **frameBuilder** (LottieFrameBuilder?) - Optional - Builder for custom frame rendering - **errorBuilder** (ImageErrorWidgetBuilder?) - Optional - Builder when loading fails - **width** (double?) - Optional - Widget width - **height** (double?) - Optional - Widget height - **fit** (BoxFit?) - Optional - Size fitting mode - **alignment** (AlignmentGeometry?) - Optional - Alignment within bounds (default: Alignment.center) - **addRepaintBoundary** (bool?) - Optional - Optimize with repaint boundary (default: true) - **filterQuality** (FilterQuality?) - Optional - Image filter quality (default: FilterQuality.low) - **onWarning** (WarningCallback?) - Optional - Callback for parser warnings - **decoder** (LottieDecoder?) - Optional - Custom decoder for special formats - **renderCache** (RenderCache?) - Optional - Frame caching strategy - **backgroundLoading** (bool?) - Optional - Parse JSON on background isolate (default: false) ### Returns `LottieBuilder` ### Throws `AssertionError` on web platform ``` -------------------------------- ### LottieProvider Implementations Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/README.md Abstract base class and concrete implementations for loading Lottie animations from different sources. ```APIDOC ## LottieProvider ### Description Abstract base class for all animation source providers. Handles loading and caching. ## AssetLottie ### Description Loads animations from Flutter asset bundle. ### Usage ```dart AssetLottie('assets/animation.json') ``` ### Parameters - `assetName` (String) - Required - Asset path - `bundle` (AssetBundle) - Optional - Custom asset bundle - `package` (String) - Optional - Package name for `packages/` prefix - `imageProviderFactory` (Function) - Optional - Custom image loader - `decoder` (Function) - Optional - Custom format decoder - `backgroundLoading` (bool) - Optional - Parse on isolate ## NetworkLottie ### Description Loads animations from HTTP URLs. ### Usage ```dart NetworkLottie('https://example.com/animation.json') ``` ### Parameters - `url` (String) - Required - Full animation URL - `client` (http.Client) - Optional - Custom HTTP client - `headers` (Map) - Optional - HTTP headers - `imageProviderFactory` (Function) - Optional - Custom image loader - `decoder` (Function) - Optional - Custom format decoder - `backgroundLoading` (bool) - Optional - Parse on isolate ## MemoryLottie ### Description Loads animations from bytes in memory. ### Usage ```dart MemoryLottie(animationBytes) ``` ### Parameters - `animationBytes` (Uint8List) - Required - Animation data in bytes ## FileLottie ### Description Loads animations from file system (mobile only). ### Usage ```dart FileLottie(File('path/to/animation.json')) ``` ### Parameters - `file` (File) - Required - File object pointing to the animation file ## LottieCache ### Description LRU composition cache for loaded animations. Access via `Lottie.cache`. ### Properties - `maximumSize` (int) - Max cached items (default: 1000) - `count` (int) - Current cache size ### Methods - `clear()` - Remove all cached items - `evict(Object key)` - Remove specific item - `putIfAbsent(Object key, Future Function() loader)` - Get or load with caching ``` -------------------------------- ### Loading Lottie Animation from Network Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/API_OVERVIEW.md Illustrates how to load and display a Lottie animation directly from a network URL. This method is convenient for animations that are hosted remotely. ```dart Lottie.network( 'https://raw.githubusercontent.com/xvrh/lottie-flutter/master/example/assets/Mobilo/A.json', ) ``` -------------------------------- ### Marker Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/types.md Represents a named segment within an animation timeline. It provides information about the start frame, duration, and allows matching by name. ```APIDOC ## Marker Named timeline segment in an animation. ```dart class Marker { final String name; final double startFrame; final double durationFrames; double get start; // Normalized progress (0-1) double get end; // Normalized progress (0-1) bool matchesName(String name); } ``` **Fields:** - `name`: Segment name from animation - `startFrame`: Absolute frame number - `durationFrames`: Duration in frames - `start`: Normalized start (computed) - `end`: Normalized end (computed) **Used by:** `LottieComposition.markers` ``` -------------------------------- ### Create Lottie Animation from File Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-widget.md Use Lottie.file to load an animation from a local file path. This method is not supported on the web platform and will throw an AssertionError. ```dart static LottieBuilder file( Object file, { Animation? controller, FrameRate? frameRate, bool? animate, bool? repeat, bool? reverse, LottieDelegates? delegates, LottieOptions? options, LottieImageProviderFactory? imageProviderFactory, void Function(LottieComposition)? onLoaded, Key? key, LottieFrameBuilder? frameBuilder, ImageErrorWidgetBuilder? errorBuilder, double? width, double? height, BoxFit? fit, AlignmentGeometry? alignment, bool? addRepaintBoundary, FilterQuality? filterQuality, WarningCallback? onWarning, LottieDecoder? decoder, RenderCache? renderCache, bool? backgroundLoading, }) ``` -------------------------------- ### Get Composition Bounds Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/composition.md Retrieve the bounding rectangle of the composition in pixels, which defines the viewBox size. Useful for determining the display area. ```dart final width = composition.bounds.width; final height = composition.bounds.height; ``` -------------------------------- ### Memory Animation with Delegates Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-widget.md Shows how to load a Lottie animation from memory (byte data) and apply custom delegates for text and value modifications. ```APIDOC ### Memory animation with delegates ```dart class AnimationWithDelegates extends StatelessWidget { @override Widget build(BuildContext context) { return Lottie.memory( animationBytes, delegates: LottieDelegates( text: (initialText) => 'Updated: $initialText', values: [ ValueDelegate.color( ['Layer 1', 'Shape 1', 'Fill'], value: Colors.blue, ), ], ), ); } } ``` ``` -------------------------------- ### Get Shared Lottie Cache Instance Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-widget.md Retrieves the shared cache instance for Lottie compositions. This is useful for performance optimization when reusing animations. ```dart static LottieCache get cache ``` -------------------------------- ### Load Lottie Animation from File Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-providers.md Use FileLottie to load Lottie animations from a file on the file system. This provider is not supported on the web platform and will throw an AssertionError if used there. Ensure you import 'dart:io'. ```dart import 'dart:io'; final file = File('/path/to/animation.json'); final provider = FileLottie(file); final composition = await provider.load(); ``` -------------------------------- ### Get Mask and Matte Count Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/composition.md Obtain the count of masks and mattes present in the composition. This count is used to assess compatibility with hardware acceleration. ```dart int maskAndMatteCount = composition.maskAndMatteCount; ``` -------------------------------- ### Access Composition Images Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/composition.md Get a map of image IDs to their corresponding LottieImageAsset objects. Image data is loaded on demand when the composition is loaded. ```dart Map images = composition.images; ``` -------------------------------- ### Basic Asset Animation Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-widget.md Displays a Lottie animation loaded from the application's assets folder. Ensure the animation file is correctly added to the `pubspec.yaml`. ```dart import 'package:flutter/material.dart'; import 'package:lottie/lottie.dart'; class SimpleAnimation extends StatelessWidget { @override Widget build(BuildContext context) { return Lottie.asset( 'assets/animation.json', width: 200, height: 200, fit: BoxFit.fill, ); } } ``` -------------------------------- ### NetworkLottie Constructor Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-providers.md Initializes a NetworkLottie provider to load animations from a given URL. You can customize the HTTP client, headers, image provider factory, decoder, and background loading behavior. ```APIDOC ## NetworkLottie Constructor Loads Lottie animations from a network URL. **Import Path:** `package:lottie/lottie.dart` ### Signature ```dart NetworkLottie( String url, { http.Client? client, Map? headers, LottieImageProviderFactory? imageProviderFactory, LottieDecoder? decoder, bool? backgroundLoading, } ) ``` ### Parameters #### Parameters - **url** (`String`) - Required - Full URL to the JSON file - **client** (`http.Client?`) - Optional - Custom HTTP client; reused for image requests - **headers** (`Map?`) - Optional - HTTP headers for composition and image requests - **imageProviderFactory** (`LottieImageProviderFactory?`) - Optional - Factory for custom image providers - **decoder** (`LottieDecoder?`) - Optional - Custom decoder for special formats - **backgroundLoading** (`bool?`) - Optional - Parse JSON on background isolate ### Returns `NetworkLottie` instance ``` -------------------------------- ### Get or Load Composition with Cache Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-providers.md Retrieve a Lottie composition from the cache. If it's not found, it will be loaded using the provided loader function and then added to the cache. ```dart final composition = await Lottie.cache.putIfAbsent( 'unique-key', () async => LottieComposition.fromBytes(bytes), ); ``` -------------------------------- ### LottieFrameInfo Class Definition Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/types.md Provides frame-specific data to ValueDelegate callbacks. It includes progress information and values at the start and end of keyframes. Used by ValueDelegate callbacks. ```dart class LottieFrameInfo { final double startFrame; final double? endFrame; final T? startValue; final T? endValue; final double linearKeyframeProgress; final double interpolatedKeyframeProgress; final double overallProgress; } ``` -------------------------------- ### ValueDelegate Properties Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/value-delegate.md Explains the properties available on the ValueDelegate class, including keyPath, property, value, and callback. ```APIDOC ## ValueDelegate Properties ### keyPath ```dart final List keyPath ``` The path to the target property as layer and component names. Supports wildcard patterns (`*` for single level, `**` for multiple levels). **Type:** `List` ### property ```dart final T property ``` The property identifier (internal use). **Type:** `T` ### value ```dart final T? value ``` The static value to apply, or null if using a callback. **Type:** `T?` ### callback ```dart final T Function(LottieFrameInfo)? callback ``` The callback function to compute the value per frame, or null if using a static value. **Type:** `T Function(LottieFrameInfo)?` ``` -------------------------------- ### Get Layer Model by ID Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/composition.md Finds a specific layer model using its unique integer ID. Returns null if no layer with the specified ID exists. ```dart Layer? layerModelForId(int id) ``` ```dart final layer = composition.layerModelForId(42); ``` -------------------------------- ### Get Marker by Name Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/composition.md Finds a marker by its name (case-insensitive). Returns null if the marker is not found. Useful for controlling animation playback based on named markers. ```dart Marker? getMarker(String markerName) ``` ```dart final intro = composition.getMarker('intro'); if (intro != null) { controller.forward(from: intro.start); } ``` -------------------------------- ### Load Lottie Animation Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/README.md Demonstrates the simplest way to load a Lottie animation from assets. Use custom size and fit options for display. Supports loading from network, local files (mobile only), and memory. ```dart Lottie.asset('assets/animation.json') ``` ```dart Lottie.asset( 'assets/animation.json', width: 200, height: 200, fit: BoxFit.contain, ) ``` ```dart Lottie.network('https://example.com/animation.json') ``` ```dart Lottie.file(File('/path/to/animation.json')) ``` ```dart Lottie.memory(animationBytes) ``` -------------------------------- ### FileLottie Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-providers.md Loads Lottie animations from the file system (not supported on web). Offers a constructor that accepts a file object and optional parameters for image provider factory, decoder, and background loading. ```APIDOC ## FileLottie Loads Lottie animations from the file system (not supported on web). **Import Path:** `package:lottie/lottie.dart` ### Constructor ```dart FileLottie( Object file, { LottieImageProviderFactory? imageProviderFactory, LottieDecoder? decoder, bool? backgroundLoading, } ) ``` | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | file | `Object` | yes | — | `dart:io.File` instance pointing to JSON file | | imageProviderFactory | `LottieImageProviderFactory?` | no | null | Factory for custom image providers | | decoder | `LottieDecoder?` | no | null | Custom decoder for special formats | | backgroundLoading | `bool?` | no | false | Parse JSON on background isolate | **Returns:** `FileLottie` instance **Throws:** `AssertionError` on web platform ### Properties | Property | Type | Description | |----------|------|-------------| | file | `io.File` | The file object | ### Methods #### load ```dart Future load({BuildContext? context}) ``` Reads and parses the composition from file, caching the result. **Example:** ```dart import 'dart:io'; final file = File('/path/to/animation.json'); final provider = FileLottie(file); final composition = await provider.load(); ``` ``` -------------------------------- ### Access Font Definitions Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/composition.md Get a map of font family names to their corresponding Font descriptors. This allows access to font information used within the animation. ```dart Map fonts = composition.fonts; ``` -------------------------------- ### Delegate Configuration: TextStyle Callback Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/configuration.md Provide custom text styling for Lottie text layers using this callback. ```dart TextStyle Function(LottieFontStyle)? textStyle; ``` -------------------------------- ### Loop Animation Between Markers Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/markers.md Implement a looping animation that repeats a specific segment defined by start and end markers. Ensure the marker exists in the composition before attempting to loop. ```dart class MarkerLooping extends StatefulWidget { final LottieComposition composition; final String loopMarkerName; const MarkerLooping({ required this.composition, required this.loopMarkerName, }); @override State createState() => _MarkerLoopingState(); } class _MarkerLoopingState extends State with TickerProviderStateMixin { late AnimationController _controller; @override void initState() { super.initState(); _controller = AnimationController( vsync: this, duration: widget.composition.duration, ); final loopMarker = widget.composition.getMarker(widget.loopMarkerName); if (loopMarker != null) { // Create a looping animation that repeats just the marked segment _startMarkerLoop(loopMarker); } } void _startMarkerLoop(Marker marker) { _controller.addListener(() { if (_controller.value >= marker.end) { // Reset to marker start and continue _controller.forward(from: marker.start); } }); _controller.forward(from: marker.start); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Lottie( composition: widget.composition, controller: _controller, ); } } ``` -------------------------------- ### Custom Decoder for .tgs Files Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/configuration.md Use a custom decoder to load specific animation formats like .tgs (Telegram stickers). This example shows how to set `LottieComposition.decodeGZip` as the decoder. ```dart Lottie.asset( 'assets/sticker.tgs', decoder: LottieComposition.decodeGZip, ) ``` -------------------------------- ### Load Lottie Animations in Flutter Source: https://github.com/xvrh/lottie-flutter/blob/master/example/README.md Demonstrates loading Lottie animations from both local assets and remote URLs within a Flutter application. Ensure Lottie files are correctly placed in the assets folder. ```dart import 'package:flutter/material.dart'; import 'package:lottie/lottie.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: ListView( children: [ // Load a Lottie file from your assets Lottie.asset('assets/LottieLogo1.json'), // Load a Lottie file from a remote url Lottie.network( 'https://raw.githubusercontent.com/xvrh/lottie-flutter/master/sample_app/assets/Mobilo/A.json', ), ], ), ), ); } } ``` -------------------------------- ### Load Lottie Composition from Network Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-providers.md Call the load method on a NetworkLottie instance to download and cache the Lottie composition from the specified URL. This is useful for pre-loading animations before they are displayed. ```dart final provider = NetworkLottie( 'https://example.com/animation.json', headers: {'Authorization': 'Bearer token'}, ); final composition = await provider.load(); ``` -------------------------------- ### Custom Image Provider Factory for Lottie Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-providers.md Illustrates how to use a custom image provider factory to return a specific image provider based on the asset ID, allowing for custom image loading logic. ```dart import 'package:lottie/lottie.dart'; class CustomImageAnimation extends StatelessWidget { @override Widget build(BuildContext context) { return Lottie.asset( 'assets/animation.json', imageProviderFactory: (imageAsset) { // Return custom image provider based on asset ID if (imageAsset.id == 'custom_image') { return NetworkImage('https://example.com/image.png'); } return null; // Use default loading }, ); } } ``` -------------------------------- ### NetworkLottie.load() Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-providers.md Downloads the Lottie composition from the specified URL and caches the result. This method is asynchronous and returns a Future that resolves to a LottieComposition. ```APIDOC ## NetworkLottie.load() Downloads the composition from the URL, caching the result. ### Signature ```dart Future load({BuildContext? context}) ``` ### Description Downloads the composition from the URL, caching the result. ### Parameters #### Parameters - **context** (`BuildContext?`) - Optional - The build context. ### Returns `Future` - A future that resolves to the loaded Lottie composition. ### Example ```dart final provider = NetworkLottie( 'https://example.com/animation.json', headers: {'Authorization': 'Bearer token'}, ); final composition = await provider.load(); ``` ``` -------------------------------- ### Get Delegates Hash for Cache Invalidation Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-drawable.md Returns an integer hash representing the current delegates associated with the drawable. This hash can be used in conjunction with the configuration hash to manage cache invalidation. ```dart int delegatesHash() ``` -------------------------------- ### fromBytes Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/composition.md Asynchronously loads a LottieComposition from a list of bytes. It supports JSON, zip, and gzip formats and can use a custom decoder. ```APIDOC ## fromBytes ### Description Asynchronously loads a composition from a byte list. Supports JSON, zip archives, and gzip-compressed formats. ### Method `static Future fromBytes(List bytes, {LottieDecoder? decoder})` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **bytes** (`List`) - Required - Raw animation data - **decoder** (`LottieDecoder?`) - Optional - Custom decoder; defaults to zip format detection ### Request Example ```dart final bytes = await File('animation.json').readAsBytes(); final composition = await LottieComposition.fromBytes(bytes); ``` ### Response #### Success Response (Future) - `Future` - A future that resolves to the parsed animation composition. #### Response Example ```dart // Example of a LottieComposition object (structure not detailed here) ``` ### Error Handling - **Throws:** None ``` -------------------------------- ### Segment Playback Between Markers Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/markers.md Facilitates playing specific segments of a Lottie animation defined by start and end markers. This is useful for playing distinct parts of an animation, like intros, loops, or outros. ```dart class SegmentPlayback extends StatefulWidget { final LottieComposition composition; const SegmentPlayback(this.composition); @override State createState() => _SegmentPlaybackState(); } class _SegmentPlaybackState extends State with TickerProviderStateMixin { late AnimationController _controller; @override void initState() { super.initState(); _controller = AnimationController( vsync: this, duration: widget.composition.duration, ); } @override void dispose() { _controller.dispose(); super.dispose(); } void _playSegment(String fromMarker, String? toMarker) { final start = widget.composition.getMarker(fromMarker); final end = toMarker != null ? widget.composition.getMarker(toMarker) : null; if (start != null) { // Create a new animation that only plays the segment final startProgress = start.start; final endProgress = end?.start ?? start.end; _controller.animateTo( endProgress, duration: Duration( milliseconds: (widget.composition.duration.inMilliseconds * (endProgress - startProgress)) .toInt(), ), ); } } @override Widget build(BuildContext context) { return Column( children: [ Lottie( composition: widget.composition, controller: _controller, ), ElevatedButton( onPressed: () => _playSegment('intro', 'loop'), child: const Text('Intro to Loop'), ), ElevatedButton( onPressed: () => _playSegment('loop', 'outro'), child: const Text('Loop to Outro'), ), ElevatedButton( onPressed: () => _playSegment('intro', null), child: const Text('Play From Intro'), ), ], ); } } ``` -------------------------------- ### LottieCache.maximumSize Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-providers.md Gets or sets the maximum number of Lottie compositions that can be stored in the cache. When the cache reaches its maximum size and a new composition is added, the least recently used composition is automatically removed. ```APIDOC ## LottieCache.maximumSize ### Description Gets or sets the maximum number of Lottie compositions that can be stored in the cache. When the cache reaches its maximum size and a new composition is added, the least recently used composition is automatically removed. ### Property ```dart int get maximumSize set maximumSize(int value) ``` ### Type `int` ### Default `1000` ### Example ```dart Lottie.cache.maximumSize = 50; // Limit to 50 compositions ``` ``` -------------------------------- ### Direct Asset and Network Lottie Provider Usage Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-providers.md Demonstrates direct usage of AssetLottie for local files and NetworkLottie for remote animations, including custom headers for network requests. ```dart import 'package:lottie/lottie.dart'; // Direct provider usage final assetProvider = AssetLottie('assets/animation.json'); final composition = await assetProvider.load(); // Network provider with custom headers final networkProvider = NetworkLottie( 'https://api.example.com/animation.json', headers: {'Authorization': 'Bearer token'}, ); final composition = await networkProvider.load(); ``` -------------------------------- ### Combining Multiple Delegates for Complex Animations Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/value-delegate.md Combine various static and dynamic delegates to create intricate animations with user-controlled elements and animated properties. This example shows a color-changing shape and animated position/opacity. ```dart import 'package:flutter/material.dart'; import 'package:lottie/lottie.dart'; class ComplexAnimation extends StatefulWidget { @override State createState() => _ComplexAnimationState(); } class _ComplexAnimationState extends State { Color _selectedColor = Colors.blue; @override Widget build(BuildContext context) { return Column( children: [ Lottie.asset( 'assets/complex.json', width: 200, height: 200, delegates: LottieDelegates( values: [ // User-controlled color ValueDelegate.color( ['Primary Shape', 'Fill'], value: _selectedColor, ), // Animated opacity ValueDelegate.opacity( ['Secondary Shape'], callback: (frameInfo) => (50 + frameInfo.overallProgress * 50).toInt(), ), // Animated position ValueDelegate.transformPosition( ['Floating Text'], callback: (frameInfo) { final wave = sin(frameInfo.overallProgress * pi * 2) * 10; return Offset(0, wave); }, ), ], ), ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( onPressed: () => setState(() => _selectedColor = Colors.red), child: const Text('Red'), ), ElevatedButton( onPressed: () => setState(() => _selectedColor = Colors.blue), child: const Text('Blue'), ), ], ), ], ); } } ``` -------------------------------- ### Define LottieImageProviderFactory for Custom Images Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/types.md Implement this factory to provide custom ImageProviders for Lottie assets. Return null to use the default image loading mechanism. ```dart typedef LottieImageProviderFactory = ImageProvider? Function(LottieImageAsset); ``` -------------------------------- ### Display Animation Marker Information Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/markers.md Display details of all markers found in a Lottie composition. This widget shows marker names, start frames, durations, and end percentages. It handles cases where no markers are defined. ```dart class MarkerInfo extends StatelessWidget { final LottieComposition composition; const MarkerInfo(this.composition); @override Widget build(BuildContext context) { return ListView( children: [ const Padding( padding: EdgeInsets.all(8.0), child: Text( 'Animation Markers', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), ), ), if (composition.markers.isEmpty) const Padding( padding: EdgeInsets.all(8.0), child: Text('No markers defined'), ), for (final marker in composition.markers) Card( child: Padding( padding: const EdgeInsets.all(12.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( marker.name, style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 16, ), ), const SizedBox(height: 4), Text( 'Start: ${marker.startFrame} frames (${(marker.start * 100).toStringAsFixed(1)}%)', style: const TextStyle(fontSize: 12), ), Text( 'Duration: ${marker.durationFrames} frames', style: const TextStyle(fontSize: 12), ), Text( 'End: ${(marker.end * 100).toStringAsFixed(1)}%', style: const TextStyle(fontSize: 12), ), const SizedBox(height: 8), LinearProgressIndicator( value: marker.start, minHeight: 4, backgroundColor: Colors.grey[300], valueColor: AlwaysStoppedAnimation(Colors.blue), ), ], ), ), ), ], ); } } ``` -------------------------------- ### Custom Value Delegates Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/delegates-and-options.md Modify animation properties like color, opacity, or position at runtime using `ValueDelegate`. This example shows how to set a specific color for a layer and control opacity based on animation progress. ```dart values: [ ValueDelegate.color(['Layer', 'Fill'], value: Colors.blue), ValueDelegate.opacity(['Shape'], callback: (f) => (f.overallProgress * 100).toInt()), ], ``` -------------------------------- ### Utilize Render Cache for Lottie Animations Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/delegates-and-options.md Improve performance by configuring the render cache for Lottie animations. `RenderCache.raster` is recommended for small, frequently played animations, while `RenderCache.drawingCommands` offers a balance for larger animations. ```dart class CachedAnimation extends StatelessWidget { @override Widget build(BuildContext context) { return Lottie.asset( 'assets/small_animation.json', renderCache: RenderCache.raster, // Best for small, frequently-played animations ); } } class LargeCachedAnimation extends StatelessWidget { @override Widget build(BuildContext context) { return Lottie.asset( 'assets/medium_animation.json', renderCache: RenderCache.drawingCommands, // Better balance for larger animations ); } } ``` -------------------------------- ### Get Configuration Hash for Cache Invalidation Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-drawable.md Retrieves a hash representing the current configuration of the drawable, including merge paths, filter quality, and frame rate. This is useful for determining if cached data needs to be invalidated. ```dart if (configHash() != previousHash) { cacheInvalidated = true; } ``` -------------------------------- ### Delegate Configuration: Image Callback Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/configuration.md Provide custom images for Lottie animations using this callback, which receives the composition and image asset information. ```dart ui.Image? Function(LottieComposition, LottieImageAsset)? image; ``` -------------------------------- ### Network Animation with Custom Controller Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-widget.md Loads and controls a Lottie animation from a network URL. Requires a `TickerProviderStateMixin` and an `AnimationController` for playback management. ```dart class ControlledAnimation extends StatefulWidget { @override State createState() => _ControlledAnimationState(); } class _ControlledAnimationState extends State with TickerProviderStateMixin { late AnimationController _controller; @override void initState() { super.initState(); _controller = AnimationController(vsync: this); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Lottie.network( 'https://example.com/animation.json', controller: _controller, onLoaded: (composition) { _controller ..duration = composition.duration ..forward(); }, ); } } ``` -------------------------------- ### configHash Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/lottie-drawable.md Returns a hash of the configuration (merge paths, filter quality, frame rate, etc.) for cache invalidation. ```APIDOC ## configHash ### Description Returns a hash of the configuration (merge paths, filter quality, frame rate, etc.) for cache invalidation. ### Method Signature ```dart List configHash() ``` ### Returns `List` — Configuration values ### Example ```dart if (configHash() != previousHash) { cacheInvalidated = true; } ``` ``` -------------------------------- ### Using Wildcards in Lottie Key Paths Source: https://github.com/xvrh/lottie-flutter/blob/master/_autodocs/api-reference/value-delegate.md Utilize wildcards in key paths for flexible targeting of animation elements. A single wildcard '*' matches one level, while a double wildcard '**' matches multiple nested levels. ```dart // Single wildcard: matches one level ValueDelegate.color( ['*', 'Fill 1'], // Matches ['Layer 1', 'Fill 1'], ['Layer 2', 'Fill 1'], etc. value: Colors.green, ) // Double wildcard: matches multiple levels ValueDelegate.opacity( ['Group', '**', 'Fill'], // Matches nested fills at any depth callback: (frameInfo) => (frameInfo.overallProgress * 100).toInt(), ) ```