Skip to main content

cropigo 1.0.2 copy "cropigo: ^1.0.2" to clipboard
cropigo: ^1.0.2 copied to clipboard

A unified image picker and cropper for Flutter. Easily pick and crop images with customizable output size, aspect ratio, shape, and native UI theming via a simple, null-safe API.

example/lib/main.dart

import 'dart:io';

import 'package:cropigo/cropigo.dart';
import 'package:flutter/material.dart';

void main() => runApp(const CropigoExampleApp());

class CropigoExampleApp extends StatelessWidget {
  const CropigoExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Cropigo Example',
      theme: ThemeData(colorSchemeSeed: Colors.indigo, useMaterial3: true),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  CropigoResult? _result;
  String? _error;

  Future<void> _pick(CropigoSource source) async {
    setState(() => _error = null);
    try {
      final result = await Cropigo.pickAndCrop(
        source: source,
        options: const CropigoOptions(
          aspectRatio: CropigoAspectRatio.square,
          shape: CropigoCropShape.oval,
          maxWidth: 800,
          maxHeight: 800,
          compressQuality: 85,
          theme: CropigoTheme(
            toolbarTitle: 'Crop your photo',
            showCropGrid: true,
          ),
        ),
      );
      setState(() => _result = result);
    } on CropigoException catch (e) {
      setState(() => _error = e.message);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Cropigo Example')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            if (_result != null)
              ClipOval(
                child: Image.file(
                  File(_result!.path),
                  width: 180,
                  height: 180,
                  fit: BoxFit.cover,
                ),
              )
            else
              const CircleAvatar(radius: 90, child: Icon(Icons.person, size: 64)),
            const SizedBox(height: 12),
            if (_result != null)
              Text('${_result!.width}x${_result!.height} • ${_result!.readableSize}'),
            if (_error != null)
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text(_error!, style: const TextStyle(color: Colors.red)),
              ),
            const SizedBox(height: 24),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                ElevatedButton.icon(
                  onPressed: () => _pick(CropigoSource.gallery),
                  icon: const Icon(Icons.photo_library),
                  label: const Text('Gallery'),
                ),
                const SizedBox(width: 12),
                ElevatedButton.icon(
                  onPressed: () => _pick(CropigoSource.camera),
                  icon: const Icon(Icons.camera_alt),
                  label: const Text('Camera'),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
2
likes
160
points
207
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

A unified image picker and cropper for Flutter. Easily pick and crop images with customizable output size, aspect ratio, shape, and native UI theming via a simple, null-safe API.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

cross_file, flutter, image_cropper, image_picker

More

Packages that depend on cropigo