image_crop_widget
A Flutter widget to crop images. The widget is completely written in Dart and has minimal dependencies.
The widget displays the image within the given layout space. On top of the image a transparent rectangular overlay, with handles on each corner, is drawn. The overlay handles can be dragged by touch to adjust the cropping area.
By calling the cropImage()
method on the widget's state object, the image area that is marked by the overlay is returned as a new image object.
To acquire the widget's state you can use a GlobalKey
object.
Example:
How to create an image object
The Image
class from dart:ui
is typically not instantiated directly. Instead, you could convert your image data into a Uint8List
and instantiate the image like this:
How to display an image object
The Image
object can be displayed with the Flutter Image
widget. One way to do this, is by converting the image into a Uint8List
and pass it into the widget's memory constructor. Please note, that the widget is not the same Image
class as the image object itself.
How to persist an image object
The Image
object can be persisted into a file or a database. To do this, you can convert the image object into a Uint8List
and write it into a File
or your database object.