Search packages, repositories and app categories

Package detailsv3.1.0

flutter_avif

A flutter plugin to view and encode avif images using libavif.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
9.6K
Likes
52
Pub points
140

Install package

flutter pub add flutter_avif

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

flutter_avif is a Flutter plugin that enables viewing and encoding AVIF images using the libavif library. It supports multiple platforms including Android, iOS, Web, macOS, Windows, and Linux. The plugin allows developers to integrate high-efficiency AVIF image handling into their apps, offering superior compression and image quality compared to traditional formats like JPEG or PNG. It provides a straightforward API for decoding and encoding AVIF files within Flutter applications.

Use cases

  • Displaying AVIF images in Flutter apps
  • Converting images to AVIF format
  • Optimizing app image assets
  • Supporting modern image formats on all platforms
  • Integrating AVIF in media-heavy applications

Key features

  • Supports AVIF decoding and encoding
  • Cross-platform compatibility
  • Uses libavif for efficient processing
  • Simple integration with Flutter
  • High compression with excellent image quality

Suitable for

  • Apps requiring efficient image storage
  • Developers targeting modern image formats
  • Projects focused on performance and bandwidth savings
  • Image-heavy applications like galleries or social media
  • Teams building cross-platform apps with advanced image support

Considerations

  • AVIF support may vary slightly across platforms
  • Requires native dependencies via libavif
  • Not suitable for legacy systems without AVIF support
  • Limited browser support on older Web environments
  • Potential build complexity on some platforms

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

flutter_avif

A flutter plugin to view and encode avif images.

Installation

To add the flutter_avif to your Flutter application follow the installation instructions on pub.dev.

Usage

AvifImage widget has a similar api as Flutter Image widget.

import 'package:flutter_avif/flutter_avif.dart';

AvifImage.file(
    file,
    height: 200,
    fit: BoxFit.contain,
),

AvifImage.asset(
    "test.avif",
    height: 200,
    fit: BoxFit.contain,
),

AvifImage.network(
    "https://test.com/test.avif",
    height: 200,
    fit: BoxFit.contain,
),

For documentation on widget properties, please refer to https://api.flutter.dev/flutter/widgets/Image-class.html.

The package also provides CachedNetworkAvifImage for caching network images.

import 'package:flutter_avif/flutter_avif.dart';

CachedNetworkAvifImage(
    "https://test.com/test.avif",
    height: 200,
    fit: BoxFit.contain,
)

Encoding

To convert an image to avif:

import 'package:flutter_avif/flutter_avif.dart';

final asset = await rootBundle.load("asset.gif");
final avifBytes = await encodeAvif(asset.buffer.asUint8List());
final outputFile = File('output.avif');
outputFile.writeAsBytes(avifBytes);
import 'package:flutter_avif/flutter_avif.dart';

final inputFile = File('input.png');
final inputBytes = await inputFile.readAsBytes();
final avifBytes = await encodeAvif(inputBytes);
final outputFile = File('output.avif');
outputFile.writeAsBytes(avifBytes);

Decoding

decodeAvif function can be used to decode an avif file to a list of dart:ui Image:

import 'package:flutter_avif/flutter_avif.dart';

final bytes = await rootBundle.load('asset.avif');
final frames = await decodeAvif(bytes.buffer.asUint8List());

decodeAvif functions return a list of AvifFrameInfo which has the duration and the image of a frame.

Custom Animation Controller

AvifAnimation can be used together with an AnimationController to manipulate the playback of multiframe images.

import 'package:flutter_avif/flutter_avif.dart';

AnimationController controller = AnimationController(vsync: this);

AvifAnimation(
    controller: controller,
    image: const AssetAvifImage('multiframe.avif'),
    onLoaded: (duration, fps) {
        controller.forward(); // play the animation
    },
),

Categories

Dependencies

Dependency list 10 items

  • exif^3.3.0
  • flutter_avif_android^3.1.0
  • flutter_avif_ios^3.1.0
  • flutter_avif_linux^3.1.0
  • flutter_avif_macos^3.1.0
  • flutter_avif_platform_interface^3.1.0
  • flutter_avif_web^3.1.0
  • flutter_avif_windows^3.1.0
  • flutter_cache_manager^3.4.1
  • http^1.2.2

Source repository

Projects using this package