How to fix pixelated image in Flutter
Asked Answered
K

3

8

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,
      ),
    );
  }
}
Knitter answered 14/1, 2021 at 15:1 Comment(0)
H
5

Try to add this property to CachedNetworkImage

filterQuality: FilterQuality.high
Halloo answered 14/1, 2021 at 15:33 Comment(2)
Actually, it seems that when scaling down the image, FilterQuality.medium should produce better results. See this comment github.com/flutter/flutter/issues/79645#issuecomment-819920763Ouch
for me neither are workingConan
G
0

After trying the standard web option that uses Canvas Kit I found the images were pixelated, type this from the command line to use html renderer instead:

flutter run -d chrome --web-renderer html.

See here Flutter Web Renderers

Gules answered 23/4 at 9:3 Comment(0)
M
0

Here is a thread about how the image issue can be solved. link -> https://github.com/flutter/flutter/issues/65120

However, this link tells you why you face the pixelation issue, and how it can be solved i.e., for those who do not want to go through the full thread. link-> https://github.com/flutter/flutter/issues/65120#issuecomment-686835554

Marismarisa answered 13/6 at 5:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.