If you use customDialogBuilder or customRouteBuilder in WebUiSettings, you must manually handle the initialization and the cropping trigger to ensure the plugin receives the result.
- Initialization: You must call the provided
initCropper() function inside your widget's initState. - Cropping: You must call the provided
crop() function and return the result to the plugin using Navigator.of(context).pop(result).
class CropperDialog extends StatefulWidget {
final dynamic cropper;
final VoidCallback initCropper;
final Future<dynamic> Function() crop;
// ... other params
@override
_CropperDialogState createState() => _CropperDialogState();
}
class _CropperDialogState extends State<CropperDialog> {
@override
void initState() {
super.initState();
// IMPORTANT: must call this function to initialize the Cropper object
widget.initCropper();
}
@override
Widget build(BuildContext context) {
return Dialog(
child: Column(
children: [
widget.cropper, // The cropper widget
TextButton(
onPressed: () async {
// IMPORTANT: call crop() and pop the result to the plugin
final result = await widget.crop();
Navigator.of(context).pop(result);
},
child: Text('Crop'),
),
],
),
);
}
}
// Usage in WebUiSettings
WebUiSettings(
customDialogBuilder: (cropper, initCropper, crop, rotate, scale) {
return CropperDialog(
cropper: cropper,
initCropper: initCropper,
crop: crop,
rotate: rotate,
scale: scale,
);
},
)
class CropperDialog extends StatefulWidget {
...
}
class _CropperDialogState extends State<CropperDialog> {
@override
void initState() {
super.initState();
/// IMPORTANT: must to call this function
widget.initCropper();
}
@override
Widget build(BuildContext context) {
Dialog(
child: Column(
children: [
...
cropper,
...
TextButton(
onPressed: () async {
/// IMPORTANT: to call crop() function and return
/// result data to plugin, for example:
final result = await crop();
Navigator.of(context).pop(result);
},
child: Text('Crop'),
)
]
),
);
}
}
WebUiSettings(
...
customDialogBuilder: (cropper, initCropper, crop, rotate, scale) {
return CropperDialog(
cropper: cropper,
initCropper: initCropper,
crop: crop,
rotate: rotate,
scale: scale,
);
},
...
)