Skip to content

Commit

Permalink
Merge pull request #3 from fernan542/main
Browse files Browse the repository at this point in the history
refactor: add frame info duration loop that checks the number of image info to add
  • Loading branch information
saytoonz authored Feb 9, 2023
2 parents 4a9ba13 + 80f7d3b commit f6ad76c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/flutter_gif.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
library flutter_gif;

import 'dart:io';
import 'dart:typed_data';
import 'dart:ui' as ui show Codec;
import 'dart:ui';

Expand Down Expand Up @@ -257,13 +256,15 @@ Future<List<ImageInfo>> fetchGif(ImageProvider provider) async {
throw Exception("Unsupported image provider");
}

ui.Codec codec = await PaintingBinding.instance.instantiateImageCodec(bytes);
infos = [];
final buffer = await ImmutableBuffer.fromUint8List(bytes);
ui.Codec codec =
await PaintingBinding.instance.instantiateImageCodecFromBuffer(buffer);
for (int i = 0; i < codec.frameCount; i++) {
FrameInfo frameInfo = await codec.getNextFrame();
//scale ??
infos.add(ImageInfo(image: frameInfo.image));
final frameInfo = await codec.getNextFrame();
final duration = frameInfo.duration.inSeconds;
for (int sec = 1; sec <= duration; sec++) {
infos.add(ImageInfo(image: frameInfo.image));
}
}
GifImage.cache.caches.putIfAbsent(key, () => infos);
return infos;
}

0 comments on commit f6ad76c

Please sign in to comment.