Flutter tips - How to crop image

Flutter tips Published on

Cropping Images Made Simple in Flutter

Need to show just a part of an image in your Flutter app? Cropping helps you focus on what matters.

The Easy Way with ClipRect

Flutter gives us a neat widget called ClipRect. It's perfect for cutting out a rectangular piece of another widget, like an image.

How ClipRect Works

You place the widget you want to crop, like your Image, inside the ClipRect. The ClipRect itself is often placed inside another widget that defines the size of the area you want to clip to, like a Container.

Setting it Up (Code Snippet Explained)
Container(
  alignment: Alignment.topCenter,
  child: ClipRect(
    child: Image.asset(
      'assets/04.jpg',
      width: 400,
      height: 400,
      fit: BoxFit.none,
      alignment: Alignment.topCenter,
    ),
  ),
)

Looking at the code:

By adjusting the size of the Container and the width/height/alignment of the Image, you can control exactly which part of your image is visible.

Save 3 months of work

Create your app using our 6 years of making Flutter apps and more than 50+ apps

kickstarter for flutter apps

Frequently Asked Questions

What widget is used for rectangular cropping in Flutter?

You use the `ClipRect` widget to crop to a rectangular shape.

How do I define the size of the cropped area?

You can place the `ClipRect` inside another widget like a `Container` and set the size of that parent widget.

How do I choose which part of the image is shown?

You can control the position of the image inside the clipping area using the `alignment` property of the `Image` widget.

Is BoxFit.none required when cropping?

Not always, but `BoxFit.none` is commonly used when cropping to prevent the image from scaling and to allow precise positioning with `alignment`.

Read more
You may also be interested in
Flutter tips: some useful date extension methods  blog card image
Flutter tips: some useful date extension methods
Published on 2025-05-04
6 ways to copy a list or map in dart  blog card image
6 ways to copy a list or map in dart
Published on 2025-05-12T11:41:57.081Z
ApparenceKit is a flutter template generator tool by Apparence.io © 2025.
All rights reserved