Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yekeskin/flutter_avif
A flutter plugin to view and encode avif images.
https://github.com/yekeskin/flutter_avif
avif dart flutter
Last synced: 13 days ago
JSON representation
A flutter plugin to view and encode avif images.
- Host: GitHub
- URL: https://github.com/yekeskin/flutter_avif
- Owner: yekeskin
- License: mit
- Created: 2022-03-29T17:47:06.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-23T14:18:19.000Z (7 months ago)
- Last Synced: 2024-04-24T07:57:15.806Z (7 months ago)
- Topics: avif, dart, flutter
- Language: Dart
- Homepage: https://pub.dev/packages/flutter_avif
- Size: 455 MB
- Stars: 41
- Watchers: 3
- Forks: 12
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://pub.dev/packages/flutter_avif/install) on pub.dev.
## Usage
AvifImage widget has a similar api as Flutter Image widget.
```dart
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 .## Encoding
To convert an image to avif:
```dart
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);
```
```dart
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](https://api.flutter.dev/flutter/dart-ui/Image-class.html):
```dart
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](https://pub.dev/documentation/flutter_avif/latest/flutter_avif/AvifFrameInfo-class.html) 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.
```dart
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
},
),
```