Search code examples
imageflutterdartnetworkimageview

How to fix pixelated image in Flutter


I want to create a rounded image widget, but it ends up pixelated.

With Image.network(url), I get the following:

Pixelated image

while the original looks like this:

enter image description here

Here is the relevant code:

class RoundedImage extends StatelessWidget {
  final String URL;
  final double size;
  final bool dynamicallySized;
  final double borderRadius;
  final bool onlyTopBorderRadius;

  const RoundedImage({
    @required this.size,
    @required this.url,
    this.dynamicallySized = false,
    this.borderRadius = 8.0,
    this.onlyTopBorderRadius = false,
  });

  @override
  Widget build(BuildContext context) {
    final newSize = dynamicallySized ? PaddingUtils.getPadding(context, padding: size) : size;
    return ClipRRect(
      borderRadius:
          onlyTopBorderRadius ? BorderRadius.vertical(top: Radius.circular(borderRadius)) : BorderRadius.circular(borderRadius),
      child: CachedNetworkImage(
        imageUrl: url,
        height: newSize,
        width: newSize,
        fit: BoxFit.cover,
      ),
    );
  }
}

Solution

  • Try to add this property to CachedNetworkImage

    filterQuality: FilterQuality.high