flutter_image_perspective_crop 0.0.2
flutter_image_perspective_crop: ^0.0.2 copied to clipboard
Flutter perspective crop editor with draggable handles, magnifier, controller, and pure Dart processing.
import 'dart:convert';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_image_perspective_crop/flutter_image_perspective_crop.dart';
void main() {
runApp(const PerspectiveCropExampleApp());
}
class PerspectiveCropExampleApp extends StatefulWidget {
const PerspectiveCropExampleApp({super.key});
@override
State<PerspectiveCropExampleApp> createState() =>
_PerspectiveCropExampleAppState();
}
class _PerspectiveCropExampleAppState extends State<PerspectiveCropExampleApp> {
Uint8List? _imageBytes;
@override
void initState() {
super.initState();
_loadSample();
}
Future<void> _loadSample() async {
// A tiny 1x1 white PNG, base64 encoded, to avoid extra assets.
const String base64Image =
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9YtX1rkAAAAASUVORK5CYII=';
final Uint8List bytes = base64.decode(base64Image);
setState(() => _imageBytes = bytes);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Perspective Crop Example')),
body: _imageBytes == null
? const Center(child: CircularProgressIndicator())
: ImagePerspectiveCrop(
onCloseRequested: () {
Navigator.of(context).pop();
},
image: _imageBytes!,
onCompleted: (PerspectiveCropResult result) {
debugPrint(
'Cropped bytes length: ${result.bytes.length}, source: ${result.imageWidth}x${result.imageHeight}');
},
),
),
);
}
}