Is there a way to create a GIF from network images in flutter?

23 Views Asked by At

I want to display a GIF in my app that will be created from a list of network images. Can it be implemented using the image package just like creating GIF from local asset images?

1

There are 1 best solutions below

1
Abel On
import "dart:typed_data";
import 'package:image/image.dart' as img;
import "package:dio/dio.dart";



Future<void> convertJpgToPdf(String imagePaths) async {
try {
  List<int> _gifBytes = [];
  img.Animation animation = img.Animation();
  Dio dio = Dio();
  for (String imagePath in imagePaths) {
    Response<List<int>> res = await dio.get(imagePath,
        options: Options(
          responseType: ResponseType.bytes,
        ));
    List<int> bytes = res.data!;
    img.Image image = img.decodeImage(Uint8List.fromList(bytes))!;
    image.duration = 500;
    animation.addFrame(image);
  }
  _gifBytes = img.encodeGifAnimation(animation)!;
} catch (err) {
  print(err.toString());
  }
}