onEntitySaving property
The callback type define for saving entity in the viewer. 在查看器中保存图片时的回调
Future<void> _onEntitySaving() async {
File? _fileToBeHandle;
await CameraPicker.pickFromCamera(
context,
pickerConfig: CameraPickerConfig(
onEntitySaving: (
BuildContext context,
CameraPickerViewType viewType,
File file,
) {
// Pass the file out of the saving method's scope.
_fileToBeHandle = file;
// Pop twice without any result to exit the picker.
Navigator.of(context)..pop()..pop();
},
),
);
// Continue your custom flow here.
print(_fileToBeHandle?.path);
}
Notice about the implementation
- After the callback is implemented, the default saving method won't called anymore.
- Don't call
Navigator.of(context).pop/maybePop
without poppingnull
orAssetEntity
, otherwise there will be a type cast error occurred.
在实现时需要注意
- 实现该方法后,原本的保存方法不会再被调用;
- 不要使用
Navigator.of(context).pop/maybePop
返回null
或AssetEntity
以外类型的内容,否则会抛出类型转换异常。
Implementation
final EntitySaveCallback? onEntitySaving;