fluttercommunity / flutter_blurhash

Compact representation of a placeholder for an image. Encode a blurry image under 30 caracters for instant display like used by Medium. Maintainer: @Solido
https://pub.dev/packages/flutter_blurhash
MIT License
528 stars 66 forks source link

How to use with flutter_blurhash CachedNetworkImage? #49

Closed RoyalCoder88 closed 2 years ago

RoyalCoder88 commented 2 years ago

It's possible to use CachedNetworkImage with flutter_blurhash ?

CachedNetworkImage( imageUrl: widget.imageUrls[0], height: MediaQuery.of(context).size.height * 0.5, width: MediaQuery.of(context).size.width, fit: BoxFit.cover, placeholder: (context, url) => const Padding( child: CupertinoActivityIndicator(), padding: EdgeInsets.all(20.0)), errorWidget: (context, url, error) => const Icon(Icons.error), );

thanks in advance!

RoyalCoder88 commented 2 years ago

I found a solution:

Widget _blurHashImage() { return SizedBox( width: double.infinity, child: CachedNetworkImage( placeholder: (context, url) => const AspectRatio( aspectRatio: 1.6, child: BlurHash(hash: 'LEHV6nWB2yk8pyo0adR*.7kCMdnj'), ), imageUrl: 'https://blurha.sh/assets/images/img1.jpg', fit: BoxFit.cover, ), ); }