flutter_avif 3.0.0 copy "flutter_avif: ^3.0.0" to clipboard
flutter_avif: ^3.0.0 copied to clipboard

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

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,
),
copied to clipboard

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,
)
copied to clipboard

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);
copied to clipboard
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);
copied to clipboard

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());
copied to clipboard

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
    },
),
copied to clipboard
47
likes
160
points
1.94k
downloads

Publisher

unverified uploader

Weekly Downloads

2024.09.19 - 2025.04.03

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

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

exif, flutter, flutter_avif_android, flutter_avif_ios, flutter_avif_linux, flutter_avif_macos, flutter_avif_platform_interface, flutter_avif_web, flutter_avif_windows, flutter_cache_manager, http

More

Packages that depend on flutter_avif