webp_animation_flutter library

High-performance WebP animation library for Flutter using game dev principles.

This library provides efficient WebP animation rendering with isolate-based decoding and sprite sheet batching for smooth performance.

Features

  • Isolate-based decoding: WebP decoding happens in background isolates
  • Sprite sheet rendering: All frames packed into single GPU texture
  • Batch rendering: Multiple animations in single draw call
  • Flexible timing: Respect WebP delays or use custom FPS
  • Simple API: Two main widgets with intuitive parameters

Usage

Single Animation from Asset

WebpAnimation(
  uri: Uri(path: 'assets/animations/character.webp'),
  width: 100,
  height: 100,
  autoPlay: true,
  loop: true,
)

Single Animation from Network

WebpAnimation(
  uri: Uri.parse('https://example.com/animation.webp'),
  width: 100,
  height: 100,
)

Static WebP Image

WebpStaticImage(
  uri: Uri(path: 'assets/images/logo.webp'),
  width: 200,
  height: 200,
)

Multiple Animations (Batch)

WebpAnimationLayer(
  animations: [
    WebpAnimationItem(
      uri: Uri(path: 'assets/char1.webp'),
      position: Offset(10, 20),
      size: Size(100, 100),
    ),
  ],
)

Classes

AnimationPainter
Unified painter for rendering WebP animations with optimal GPU performance.
AnimationState
Manages animation timing and state without Flutter's AnimationController.
DecodedSpriteSheetData
Internal data structure passed between isolates.
DecodedStaticImageData
Internal data structure for static images passed between isolates.
GameLoopController
Provides a pure game loop timing system without animation curves.
SpriteSheet
Represents a decoded WebP animation as a sprite sheet ready for GPU rendering.
StaticImageSheet
Represents a single-frame WebP image as a static image sheet. Optimized for static image rendering without animation overhead.
WebpAnimation
A widget that displays a WebP animation with efficient sprite sheet rendering.
WebpAnimationController
Convenience wrapper for WebP animation control using game loop timing.
WebpAnimationItem
Represents a single WebP animation to be rendered in a WebpAnimationLayer.
WebpAnimationLayer
A widget that efficiently renders multiple WebP animations in a single draw call.
WebpAnimationLayerController
Controller for managing multiple animations in a layer using game loop timing.
WebpCache
Unified cache for WebP content with source-agnostic keys. Handles both animations and static images with intelligent cache management.
WebpDecoder
Handles WebP animation decoding using isolate-based processing.
WebpStaticImage
A widget that displays a static WebP image with efficient GPU rendering. Optimized for single-frame images without animation overhead.

Exceptions / Errors

AssetError
Error that occurs when loading assets.
DecodeError
Error that occurs during WebP decoding operations.
NetworkError
Error that occurs during network operations.
ValidationError
Error that occurs when validating WebP data.
WebpError
Base class for WebP-related errors. Provides consistent error handling across all WebP operations.