yekeskin / flutter_avif

A flutter plugin to view and encode avif images.
https://pub.dev/packages/flutter_avif
MIT License
61 stars 17 forks source link

Can't decode images #29

Closed turbobuilt closed 1 year ago

turbobuilt commented 1 year ago

The latest version 1.4.0 doesn't work on my avifs any more. It can't decode. Not sure what's up, but thought I would report.

yekeskin commented 1 year ago

Can you share the error you are getting and the platform you are testing on? I would really appreciate if you can also share a reproduction.

turbobuilt commented 1 year ago

I had a weird error, but reinstalling the package seemed to work. For anybody else having problems, I also had an issue with loadingBuilder. If you don't check for null in loadingProgress, it doesn't ever show the image. This is kind of a ridiculous property because it's null on first render and when it's loaded so you get flicker. I had to fix it a different way below. (Note, this is not an issue with the package, but I would say with flutter in general. Thanks for the hard work!

AvifImage.network(
  // "https://images.dreamgenerator.ai/${data.share["imagePath"]}",
  "https://images.dreamgenerator.ai/images/alVg3NAPKEelsIszGC.avif",
  fit: BoxFit.cover,
  loadingBuilder: (context, widget, loadingProgress) {
    if (loadingProgress == null) {. // <-- I didn't know this was required!
      return widget;
    }
    return Container(
      // background red
      color: Colors.red,
      height: constraints.maxWidth,
      width: constraints.maxWidth,
    );
  },
),

I ended up not using loadingBuilder similar to this

frameBuilder: (BuildContext context, Widget child, int? frame, bool wasSynchronouslyLoaded) {
  if (wasSynchronouslyLoaded) {
    return child;
  }
  return Container(
    height: frame == null ? constraints.maxWidth : null,
    width: constraints.maxWidth,
    child: child
  );
},

Thanks for your hard work on this. Right now, it seems to render