Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Flutter Web? #2

Open
ghost opened this issue Jan 6, 2020 · 1 comment
Open

Support for Flutter Web? #2

ghost opened this issue Jan 6, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 6, 2020

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! :)

@pulstar
Copy link

pulstar commented Nov 10, 2020

@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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant