EntitySaveCallback typedef

EntitySaveCallback = FutureOr Function(BuildContext context, CameraPickerViewType viewType, File file)

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 popping null or AssetEntity, otherwise there will be a type cast error occurred.

在实现时需要注意

  • 实现该方法后,原本的保存方法不会再被调用;
  • 不要使用 Navigator.of(context).pop/maybePop 返回 nullAssetEntity 以外类型的内容,否则会抛出类型转换异常。

Implementation

typedef EntitySaveCallback = FutureOr<dynamic> Function(
  BuildContext context,
  CameraPickerViewType viewType,
  File file,
);