Open ghost opened 4 years ago
@senordonfelipe
It worked for me. Below is my test code, but you must create a widget and place the ImageCrop() inside it with a close button to the user go foward, then you call it in the MaterialPageRouter line below. The MemoryFileSystem() is from this package: https://pub.dev/packages/file
import 'dart:ui' as ui;
import 'package:file/memory.dart';
import 'package:image_crop_widget/image_crop_widget.dart';
Future<File> crop(File imageFile) async {
File croppedFile = MemoryFileSystem().file('');
final key = GlobalKey<ImageCropState>();
final codec = await ui.instantiateImageCodec(imageFile.readAsBytesSync());
final frame = await codec.getNextFrame();
await Navigator.of(context).push(
MaterialPageRoute(builder: (context) => ImageCrop(key: key, image: frame.image))
);
ui.Image croppedImage = await key.currentState.cropImage();
final bytes = await croppedImage.toByteData(format: ui.ImageByteFormat.png);
final byteList = bytes.buffer.asUint8List();
return await croppedFile.writeAsBytes(byteList);
}
Hey,
is there an implementation for flutter web planned as well? On pub.dev it said that web is supported, however, I tried it and it did not work.
Thanks! :)