mozartcropper 0.0.4 copy "mozartcropper: ^0.0.4" to clipboard
mozartcropper: ^0.0.4 copied to clipboard

PlatformAndroid

A Flutter plugin for high-performance localized image cropping on Android (Native) with customizable UI in Flutter.

example/lib/main.dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:mozartcropper/ui/normal_crop_page.dart';
import 'package:mozartcropper/ui/profile_crop_page.dart';

void main() {
  runApp(const MaterialApp(home: MyApp()));
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final ImagePicker _picker = ImagePicker();
  String? _croppedPath;
  File? _imageFile;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Mozart Image Cropper Example')),
      body: Center(
        child: SingleChildScrollView(
          padding: const EdgeInsets.all(24),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              if (_croppedPath != null) ...[
                const Text(
                  "Last Cropped Image:",
                  style: TextStyle(fontWeight: FontWeight.bold),
                ),
                const SizedBox(height: 8),
                Container(
                  height: 300,
                  decoration: BoxDecoration(
                    border: Border.all(color: Colors.grey),
                  ),
                  child: Image.file(File(_croppedPath!)),
                ),
                const SizedBox(height: 32),
              ],
              SizedBox(
                width: double.infinity,
                child: ElevatedButton.icon(
                  onPressed: () => _pickImage(isProfile: false),
                  icon: const Icon(Icons.crop),
                  label: const Text("Crop Image (Rectangle)"),
                  style: ElevatedButton.styleFrom(
                    padding: const EdgeInsets.all(16),
                  ),
                ),
              ),
              const SizedBox(height: 16),
              SizedBox(
                width: double.infinity,
                child: ElevatedButton.icon(
                  onPressed: () => _pickImage(isProfile: true),
                  icon: const Icon(Icons.person),
                  label: const Text("Crop Image (Circle)"),
                  style: ElevatedButton.styleFrom(
                    padding: const EdgeInsets.all(16),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Future<void> _pickImage({required bool isProfile}) async {
    final XFile? pickedFile = await _picker.pickImage(
      source: ImageSource.gallery,
    );

    if (pickedFile != null) {
      if (!mounted) return;
      _imageFile = File(pickedFile.path);

      final String? resultPath = await Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => isProfile
              ? ProfileCropPage(imageFile: _imageFile!)
              : NormalCropPage(imageFile: _imageFile!),
        ),
      );

      if (resultPath != null) {
        setState(() {
          _croppedPath = resultPath;
        });
      }
    }
  }
}
0
likes
130
points
--
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for high-performance localized image cropping on Android (Native) with customizable UI in Flutter.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

croppy, cupertino_icons, flutter, plugin_platform_interface, vector_math

More

Packages that depend on mozartcropper

Packages that implement mozartcropper