Giter VIP home page Giter VIP logo

Comments (8)

wizawuza avatar wizawuza commented on July 29, 2024 1

I just made a wrapper with a FutureBuilder like this, so no more problems!

class FBImage extends StatelessWidget {
  final String imagePath;
  final double width;
  final double height;
  const FBImage({
    @required this.imagePath,
    this.width,
    this.height
  });

  Future<CachedNetworkImage> _futureGetter() async {
    final StorageReference storageReference = FirebaseStorage().ref();
    try {
      final String url = await storageReference.child(imagePath).getDownloadURL();
      return CachedNetworkImage(
        imageUrl: url,
      );
    } catch(e) {
      return null;
    }
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: _futureGetter(),
      builder: (BuildContext context, AsyncSnapshot<CachedNetworkImage> metaData) {
        if(metaData.hasData) {
          return SizedBox(
            width: width,
            height: height,
            child: metaData.data,
          );
        } else {
          return SizedBox(
            width: width,
            height: height,
            child: Container(
              color: Colors.grey.withOpacity(0.5),
            ),
          );
        }
      },
    );
  }
}

from firebase_image.

wizawuza avatar wizawuza commented on July 29, 2024

@feinstein
It's not obvious to me, but does cached_network_image check metadata and then re-download the image automatically if the metadata has changed?

from firebase_image.

feinstein avatar feinstein commented on July 29, 2024

I don't think it will check any firebase specific Metadata.

from firebase_image.

wizawuza avatar wizawuza commented on July 29, 2024

That's what I thought when I looked their their docs. For me, this is worthwhile to use firebase_image as I have periodic changes to the images.

from firebase_image.

wizawuza avatar wizawuza commented on July 29, 2024

Nevermind, I just realized that firebase storage changes the download url (via the token) with each new upload, even if you overwrite. So with a new upload, you get a URL, and effectively invalidate the cache! Thanks for the suggestion.

from firebase_image.

feinstein avatar feinstein commented on July 29, 2024

Yes, but you will have to keep track of the URL, this library on the other hand allows to fetch directly from image objects references, if I remember correctly.

from firebase_image.

feinstein avatar feinstein commented on July 29, 2024

I don't this this is the place for this, it will deviate from my original question.

That being said, don't return CachedNetworkImage, as its a Widget, return the URL String and then pass it inside the FutureBuilder to the CachedNetworkImage.

from firebase_image.

wizawuza avatar wizawuza commented on July 29, 2024

Agreed re: not the place. Thank you for the feedback.

from firebase_image.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.