Helper for picking and cropping an image (Desktop, Mobile and Web support)
Pick and crop image on Flutter
In pubspec.yaml
dependencies:
tekartik_app_pick_crop_image_flutter:
git:
url: https://github.com/tekartik/app_image.dart
path: packages/app_pick_crop_image_flutter
ref: dart3a
version: '>=0.1.0'
See Demo app
Needed import
import 'package:tekartik_app_pick_crop_image_flutter/pick_crop_image.dart';
Simplest exemple that will pick an image from the gallery, allow free cropping and export as jpg
The result is available in the imageData returned
- bytes
- width
- height
- encoding
var imageData = pickCropImage(context);
Example to pick from the camera and crop it manually as a square
var imageData = await pickCropImage(context,
options: PickCropImageOptions(
source: const PickCropImageSourceCamera(
preferredCameraDevice: SourceCameraDevice.rear),
width: 1024,
height: 1024,
encoding: ImageEncodingJpg(quality: 75)));
Example to pick from the gallery with a round mask The resulting image is still a square though.
var imageData = await pickCropImage(context,
options: PickCropImageOptions(
source: const PickCropImageSourceGallery(),
width: 1024,
height: 1024,
ovalCropMask: true,
encoding: ImageEncodingJpg(quality: 75)));